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

120 lines
3 KiB
JavaScript
Raw Normal View History

2020-04-22 19:07:51 +05:30
import Vue from 'vue';
2021-04-29 21:17:54 +05:30
import { convertObjectPropsToCamelCase, parseBoolean } from '~/lib/utils/common_utils';
2020-05-24 23:13:21 +05:30
import IntegrationForm from './components/integration_form.vue';
2021-03-11 19:13:27 +05:30
import { createStore } from './store';
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,
2021-01-29 00:20:46 +05:30
resetPath,
2021-03-11 19:13:27 +05:30
vulnerabilitiesIssuetype,
2021-04-29 21:17:54 +05:30
jiraIssueTransitionAutomatic,
jiraIssueTransitionId,
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,
2021-03-11 19:13:27 +05:30
showJiraVulnerabilitiesIntegration,
2020-07-28 23:09:34 +05:30
enableJiraIssues,
2021-03-11 19:13:27 +05:30
enableJiraVulnerabilities,
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,
2021-01-29 00:20:46 +05:30
resetPath,
2020-07-28 23:09:34 +05:30
triggerFieldsProps: {
initialTriggerCommit: commitEvents,
initialTriggerMergeRequest: mergeRequestEvents,
initialEnableComments: enableComments,
initialCommentDetail: commentDetail,
2021-04-29 21:17:54 +05:30
initialJiraIssueTransitionAutomatic: jiraIssueTransitionAutomatic,
initialJiraIssueTransitionId: jiraIssueTransitionId,
2020-07-28 23:09:34 +05:30
},
jiraIssuesProps: {
showJiraIssuesIntegration,
2021-03-11 19:13:27 +05:30
showJiraVulnerabilitiesIntegration,
2020-07-28 23:09:34 +05:30
initialEnableJiraIssues: enableJiraIssues,
2021-03-11 19:13:27 +05:30
initialEnableJiraVulnerabilities: enableJiraVulnerabilities,
initialVulnerabilitiesIssuetype: vulnerabilitiesIssuetype,
2020-07-28 23:09:34 +05:30
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),
2021-04-29 21:17:54 +05:30
fields: convertObjectPropsToCamelCase(JSON.parse(fields), { deep: true }),
2020-07-28 23:09:34 +05:30
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
}
2021-03-11 19:13:27 +05:30
// Here, we capture the "helpHtml", so we can pass it to the Vue component
// to position it where ever it wants.
// Because this node is a _child_ of `el`, it will be removed when the Vue component is mounted,
// so we don't need to manually remove it.
const helpHtml = el.querySelector('.js-integration-help-html')?.innerHTML;
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) {
2021-03-11 19:13:27 +05:30
return createElement(IntegrationForm, {
props: {
helpHtml,
},
});
2020-04-22 19:07:51 +05:30
},
});
};