debian-mirror-gitlab/app/assets/javascripts/issue_show/incident.js

100 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import Vue from 'vue';
2021-03-11 19:13:27 +05:30
import { parseBoolean } from '~/lib/utils/common_utils';
2020-11-24 15:15:51 +05:30
import issuableApp from './components/app.vue';
import incidentTabs from './components/incidents/incident_tabs.vue';
2021-12-11 22:18:48 +05:30
import { issueState, IncidentType } from './constants';
2021-09-04 01:27:46 +05:30
import apolloProvider from './graphql';
import getIssueStateQuery from './queries/get_issue_state.query.graphql';
2021-12-11 22:18:48 +05:30
import HeaderActions from './components/header_actions.vue';
2020-11-24 15:15:51 +05:30
2021-12-11 22:18:48 +05:30
const bootstrapApollo = (state = {}) => {
return apolloProvider.clients.defaultClient.cache.writeQuery({
query: getIssueStateQuery,
data: {
issueState: state,
},
});
};
export function initIncidentApp(issuableData = {}) {
2021-09-04 01:27:46 +05:30
const el = document.getElementById('js-issuable-app');
if (!el) {
return undefined;
}
2021-12-11 22:18:48 +05:30
bootstrapApollo({ ...issueState, issueType: el.dataset.issueType });
2020-11-24 15:15:51 +05:30
2021-03-08 18:12:59 +05:30
const {
2021-12-11 22:18:48 +05:30
canCreateIncident,
2021-03-08 18:12:59 +05:30
canUpdate,
iid,
projectNamespace,
projectPath,
projectId,
slaFeatureAvailable,
uploadMetricsFeatureAvailable,
} = issuableData;
const fullPath = `${projectNamespace}/${projectPath}`;
2020-11-24 15:15:51 +05:30
return new Vue({
2021-09-04 01:27:46 +05:30
el,
2020-11-24 15:15:51 +05:30
apolloProvider,
components: {
issuableApp,
},
provide: {
2021-12-11 22:18:48 +05:30
issueType: IncidentType,
canCreateIncident,
2021-03-08 18:12:59 +05:30
canUpdate,
fullPath,
2020-11-24 15:15:51 +05:30
iid,
2021-03-08 18:12:59 +05:30
projectId,
2021-01-03 14:25:43 +05:30
slaFeatureAvailable: parseBoolean(slaFeatureAvailable),
2021-03-08 18:12:59 +05:30
uploadMetricsFeatureAvailable: parseBoolean(uploadMetricsFeatureAvailable),
2020-11-24 15:15:51 +05:30
},
render(createElement) {
return createElement('issuable-app', {
props: {
...issuableData,
descriptionComponent: incidentTabs,
showTitleBorder: false,
},
});
},
});
}
2021-12-11 22:18:48 +05:30
export function initIncidentHeaderActions(store) {
const el = document.querySelector('.js-issue-header-actions');
if (!el) {
return undefined;
}
bootstrapApollo({ ...issueState, issueType: el.dataset.issueType });
return new Vue({
el,
apolloProvider,
store,
provide: {
canCreateIssue: parseBoolean(el.dataset.canCreateIncident),
canPromoteToEpic: parseBoolean(el.dataset.canPromoteToEpic),
canReopenIssue: parseBoolean(el.dataset.canReopenIssue),
canReportSpam: parseBoolean(el.dataset.canReportSpam),
canUpdateIssue: parseBoolean(el.dataset.canUpdateIssue),
iid: el.dataset.iid,
isIssueAuthor: parseBoolean(el.dataset.isIssueAuthor),
issueType: el.dataset.issueType,
newIssuePath: el.dataset.newIssuePath,
projectPath: el.dataset.projectPath,
projectId: el.dataset.projectId,
reportAbusePath: el.dataset.reportAbusePath,
submitAsSpamPath: el.dataset.submitAsSpamPath,
},
render: (createElement) => createElement(HeaderActions),
});
}