debian-mirror-gitlab/app/assets/javascripts/integrations/edit/index.js

99 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-04-22 19:07:51 +05:30
import Vue from 'vue';
2020-07-28 23:09:34 +05:30
import { createStore } from './store';
2020-04-22 19:07:51 +05:30
import { parseBoolean } from '~/lib/utils/common_utils';
2020-05-24 23:13:21 +05:30
import IntegrationForm from './components/integration_form.vue';
2020-04-22 19:07:51 +05:30
2020-07-28 23:09:34 +05:30
function parseBooleanInData(data) {
const result = {};
Object.entries(data).forEach(([key, value]) => {
result[key] = parseBoolean(value);
});
return result;
}
2020-04-22 19:07:51 +05:30
2020-07-28 23:09:34 +05:30
function parseDatasetToProps(data) {
const {
id,
type,
commentDetail,
projectKey,
upgradePlanPath,
editProjectPath,
2020-11-24 15:15:51 +05:30
learnMorePath,
2020-07-28 23:09:34 +05:30
triggerEvents,
fields,
inheritFromId,
2020-11-24 15:15:51 +05:30
integrationLevel,
cancelPath,
testPath,
2020-07-28 23:09:34 +05:30
...booleanAttributes
} = data;
2020-05-24 23:13:21 +05:30
const {
showActive,
activated,
2020-11-24 15:15:51 +05:30
editable,
canTest,
2020-05-24 23:13:21 +05:30
commitEvents,
mergeRequestEvents,
enableComments,
2020-07-28 23:09:34 +05:30
showJiraIssuesIntegration,
enableJiraIssues,
2020-11-24 15:15:51 +05:30
gitlabIssuesEnabled,
2020-05-24 23:13:21 +05:30
} = parseBooleanInData(booleanAttributes);
2020-07-28 23:09:34 +05:30
return {
2020-11-24 15:15:51 +05:30
initialActivated: activated,
2020-07-28 23:09:34 +05:30
showActive,
type,
2020-11-24 15:15:51 +05:30
cancelPath,
editable,
canTest,
testPath,
2020-07-28 23:09:34 +05:30
triggerFieldsProps: {
initialTriggerCommit: commitEvents,
initialTriggerMergeRequest: mergeRequestEvents,
initialEnableComments: enableComments,
initialCommentDetail: commentDetail,
},
jiraIssuesProps: {
showJiraIssuesIntegration,
initialEnableJiraIssues: enableJiraIssues,
initialProjectKey: projectKey,
2020-11-24 15:15:51 +05:30
gitlabIssuesEnabled,
2020-07-28 23:09:34 +05:30
upgradePlanPath,
editProjectPath,
},
2020-11-24 15:15:51 +05:30
learnMorePath,
2020-07-28 23:09:34 +05:30
triggerEvents: JSON.parse(triggerEvents),
fields: JSON.parse(fields),
inheritFromId: parseInt(inheritFromId, 10),
2020-11-24 15:15:51 +05:30
integrationLevel,
2020-07-28 23:09:34 +05:30
id: parseInt(id, 10),
};
}
2020-11-24 15:15:51 +05:30
export default (el, defaultEl) => {
2020-07-28 23:09:34 +05:30
if (!el) {
return null;
}
const props = parseDatasetToProps(el.dataset);
const initialState = {
2020-11-24 15:15:51 +05:30
defaultState: null,
2020-07-28 23:09:34 +05:30
customState: props,
};
2020-11-24 15:15:51 +05:30
if (defaultEl) {
initialState.defaultState = Object.freeze(parseDatasetToProps(defaultEl.dataset));
2020-07-28 23:09:34 +05:30
}
2020-04-22 19:07:51 +05:30
return new Vue({
el,
2020-07-28 23:09:34 +05:30
store: createStore(initialState),
2020-04-22 19:07:51 +05:30
render(createElement) {
2020-07-28 23:09:34 +05:30
return createElement(IntegrationForm);
2020-04-22 19:07:51 +05:30
},
});
};