debian-mirror-gitlab/app/assets/javascripts/issues/show/index.js

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

173 lines
4.6 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import Vue from 'vue';
2022-03-02 08:16:31 +05:30
import { mapGetters } from 'vuex';
import errorTrackingStore from '~/error_tracking/store';
2021-03-11 19:13:27 +05:30
import { parseBoolean } from '~/lib/utils/common_utils';
2022-03-02 08:16:31 +05:30
import { scrollToTargetOnResize } from '~/lib/utils/resize_observer';
import IssueApp from './components/app.vue';
import HeaderActions from './components/header_actions.vue';
import IncidentTabs from './components/incidents/incident_tabs.vue';
import SentryErrorStackTrace from './components/sentry_error_stack_trace.vue';
import { INCIDENT_TYPE, issueState } from './constants';
2021-09-04 01:27:46 +05:30
import apolloProvider from './graphql';
import getIssueStateQuery from './queries/get_issue_state.query.graphql';
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,
},
});
};
2022-03-02 08:16:31 +05:30
export function initIncidentApp(issueData = {}) {
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,
2022-07-23 23:45:48 +05:30
issuableId,
2021-03-08 18:12:59 +05:30
projectNamespace,
projectPath,
projectId,
slaFeatureAvailable,
uploadMetricsFeatureAvailable,
2022-07-16 23:28:13 +05:30
state,
2022-03-02 08:16:31 +05:30
} = issueData;
2021-03-08 18:12:59 +05:30
const fullPath = `${projectNamespace}/${projectPath}`;
2020-11-24 15:15:51 +05:30
return new Vue({
2021-09-04 01:27:46 +05:30
el,
2022-04-04 11:22:00 +05:30
name: 'DescriptionRoot',
2020-11-24 15:15:51 +05:30
apolloProvider,
provide: {
2022-03-02 08:16:31 +05:30
issueType: INCIDENT_TYPE,
2021-12-11 22:18:48 +05:30
canCreateIncident,
2021-03-08 18:12:59 +05:30
canUpdate,
fullPath,
2020-11-24 15:15:51 +05:30
iid,
2022-07-23 23:45:48 +05:30
issuableId,
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) {
2022-03-02 08:16:31 +05:30
return createElement(IssueApp, {
2020-11-24 15:15:51 +05:30
props: {
2022-03-02 08:16:31 +05:30
...issueData,
2022-08-13 15:12:31 +05:30
issueId: Number(issuableId),
2022-07-16 23:28:13 +05:30
issuableStatus: state,
2022-03-02 08:16:31 +05:30
descriptionComponent: IncidentTabs,
2020-11-24 15:15:51 +05:30
showTitleBorder: false,
},
});
},
});
}
2021-12-11 22:18:48 +05:30
2022-03-02 08:16:31 +05:30
export function initIssueApp(issueData, store) {
const el = document.getElementById('js-issuable-app');
if (!el) {
return undefined;
}
2022-04-04 11:22:00 +05:30
const { fullPath } = el.dataset;
2022-05-07 20:08:51 +05:30
scrollToTargetOnResize();
2022-03-02 08:16:31 +05:30
bootstrapApollo({ ...issueState, issueType: el.dataset.issueType });
2022-07-23 23:45:48 +05:30
const { canCreateIncident, hasIssueWeightsFeature, ...issueProps } = issueData;
2022-03-02 08:16:31 +05:30
return new Vue({
el,
2022-04-04 11:22:00 +05:30
name: 'DescriptionRoot',
2022-03-02 08:16:31 +05:30
apolloProvider,
store,
provide: {
canCreateIncident,
2022-04-04 11:22:00 +05:30
fullPath,
2022-07-23 23:45:48 +05:30
hasIssueWeightsFeature,
2022-03-02 08:16:31 +05:30
},
computed: {
...mapGetters(['getNoteableData']),
},
render(createElement) {
return createElement(IssueApp, {
props: {
...issueProps,
isConfidential: this.getNoteableData?.confidential,
isLocked: this.getNoteableData?.discussion_locked,
issuableStatus: this.getNoteableData?.state,
2022-06-21 17:19:12 +05:30
issueId: this.getNoteableData?.id,
2022-03-02 08:16:31 +05:30
},
});
},
});
}
export function initHeaderActions(store, type = '') {
2021-12-11 22:18:48 +05:30
const el = document.querySelector('.js-issue-header-actions');
if (!el) {
return undefined;
}
bootstrapApollo({ ...issueState, issueType: el.dataset.issueType });
2022-03-02 08:16:31 +05:30
const canCreate =
type === INCIDENT_TYPE ? el.dataset.canCreateIncident : el.dataset.canCreateIssue;
2021-12-11 22:18:48 +05:30
return new Vue({
el,
2022-04-04 11:22:00 +05:30
name: 'HeaderActionsRoot',
2021-12-11 22:18:48 +05:30
apolloProvider,
store,
provide: {
2022-03-02 08:16:31 +05:30
canCreateIssue: parseBoolean(canCreate),
2022-01-26 12:08:38 +05:30
canDestroyIssue: parseBoolean(el.dataset.canDestroyIssue),
2021-12-11 22:18:48 +05:30
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),
2022-01-26 12:08:38 +05:30
issuePath: el.dataset.issuePath,
2021-12-11 22:18:48 +05:30
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),
});
}
2022-03-02 08:16:31 +05:30
export function initSentryErrorStackTrace() {
const el = document.querySelector('#js-sentry-error-stack-trace');
if (!el) {
return undefined;
}
const { issueStackTracePath } = el.dataset;
return new Vue({
el,
2022-04-04 11:22:00 +05:30
name: 'SentryErrorStackTraceRoot',
2022-03-02 08:16:31 +05:30
store: errorTrackingStore,
render: (createElement) =>
createElement(SentryErrorStackTrace, { props: { issueStackTracePath } }),
});
}