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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

135 lines
3.6 KiB
JavaScript
Raw Normal View History

2020-04-22 19:07:51 +05:30
import Vue from 'vue';
2022-06-21 17:19:12 +05:30
import { GlToast } from '@gitlab/ui';
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
2022-06-21 17:19:12 +05:30
Vue.use(GlToast);
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,
2020-11-24 15:15:51 +05:30
learnMorePath,
2022-07-16 23:28:13 +05:30
aboutPricingUrl,
2020-07-28 23:09:34 +05:30
triggerEvents,
2022-05-07 20:08:51 +05:30
sections,
2020-07-28 23:09:34 +05:30
fields,
inheritFromId,
2020-11-24 15:15:51 +05:30
integrationLevel,
cancelPath,
testPath,
2021-01-29 00:20:46 +05:30
resetPath,
2022-03-02 08:16:31 +05:30
formPath,
2021-03-11 19:13:27 +05:30
vulnerabilitiesIssuetype,
2021-04-29 21:17:54 +05:30
jiraIssueTransitionAutomatic,
jiraIssueTransitionId,
2022-03-02 08:16:31 +05:30
redirectTo,
2023-01-13 00:05:48 +05:30
upgradeSlackUrl,
2020-07-28 23:09:34 +05:30
...booleanAttributes
} = data;
2020-05-24 23:13:21 +05:30
const {
showActive,
activated,
2022-05-07 20:08:51 +05:30
activateDisabled,
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,
2023-01-13 00:05:48 +05:30
shouldUpgradeSlack,
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,
2022-05-07 20:08:51 +05:30
activateDisabled,
2020-07-28 23:09:34 +05:30
type,
2020-11-24 15:15:51 +05:30
cancelPath,
editable,
canTest,
testPath,
2021-01-29 00:20:46 +05:30
resetPath,
2022-03-02 08:16:31 +05:30
formPath,
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
learnMorePath,
2022-07-16 23:28:13 +05:30
aboutPricingUrl,
2020-07-28 23:09:34 +05:30
triggerEvents: JSON.parse(triggerEvents),
2022-07-23 23:45:48 +05:30
sections: JSON.parse(sections),
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),
2022-03-02 08:16:31 +05:30
redirectTo,
2023-01-13 00:05:48 +05:30
shouldUpgradeSlack,
upgradeSlackUrl,
2020-07-28 23:09:34 +05:30
};
}
2022-03-02 08:16:31 +05:30
export default function initIntegrationSettingsForm() {
2022-01-26 12:08:38 +05:30
const customSettingsEl = document.querySelector('.js-vue-integration-settings');
const defaultSettingsEl = document.querySelector('.js-vue-default-integration-settings');
if (!customSettingsEl) {
2020-07-28 23:09:34 +05:30
return null;
}
2022-01-26 12:08:38 +05:30
const customSettingsProps = parseDatasetToProps(customSettingsEl.dataset);
2020-07-28 23:09:34 +05:30
const initialState = {
2020-11-24 15:15:51 +05:30
defaultState: null,
2022-01-26 12:08:38 +05:30
customState: customSettingsProps,
2023-03-04 22:38:38 +05:30
editable: customSettingsProps.editable && !customSettingsProps.shouldUpgradeSlack,
2020-07-28 23:09:34 +05:30
};
2022-01-26 12:08:38 +05:30
if (defaultSettingsEl) {
initialState.defaultState = Object.freeze(parseDatasetToProps(defaultSettingsEl.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.
2022-01-26 12:08:38 +05:30
const helpHtml = customSettingsEl.querySelector('.js-integration-help-html')?.innerHTML;
2021-03-11 19:13:27 +05:30
2020-04-22 19:07:51 +05:30
return new Vue({
2022-01-26 12:08:38 +05:30
el: customSettingsEl,
2022-05-07 20:08:51 +05:30
name: 'IntegrationEditRoot',
2020-07-28 23:09:34 +05:30
store: createStore(initialState),
2022-05-07 20:08:51 +05:30
provide: {
helpHtml,
},
2020-04-22 19:07:51 +05:30
render(createElement) {
2022-05-07 20:08:51 +05:30
return createElement(IntegrationForm);
2020-04-22 19:07:51 +05:30
},
});
2022-01-26 12:08:38 +05:30
}