Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index.js « show « issues « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b94f88f690e497313dccf9600a5c5280014f146c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import Vue from 'vue';
// eslint-disable-next-line no-restricted-imports
import { mapGetters } from 'vuex';
import errorTrackingStore from '~/error_tracking/store';
import { apolloProvider } from '~/graphql_shared/issuable_client';
import { TYPE_INCIDENT, TYPE_ISSUE } from '~/issues/constants';
import { convertObjectPropsToCamelCase, parseBoolean } from '~/lib/utils/common_utils';
import { scrollToTargetOnResize } from '~/lib/utils/resize_observer';
import initLinkedResources from '~/linked_resources';
import IssueApp from './components/app.vue';
import DescriptionComponent from './components/description.vue';
import IncidentTabs from './components/incidents/incident_tabs.vue';
import SentryErrorStackTrace from './components/sentry_error_stack_trace.vue';
import { issueState } from './constants';
import getIssueStateQuery from './queries/get_issue_state.query.graphql';
import createRouter from './components/incidents/router';
import { parseIssuableData } from './utils/parse_data';

const bootstrapApollo = (state = {}) => {
  return apolloProvider.clients.defaultClient.cache.writeQuery({
    query: getIssueStateQuery,
    data: {
      issueState: state,
    },
  });
};

export function initIssuableApp(store) {
  const el = document.getElementById('js-issuable-app');

  if (!el) {
    return undefined;
  }

  const issuableData = parseIssuableData(el);
  const headerActionsData = convertObjectPropsToCamelCase(JSON.parse(el.dataset.headerActionsData));

  const {
    authorId,
    authorName,
    authorUsername,
    authorWebUrl,
    canCreateIncident,
    fullPath,
    iid,
    issuableId,
    issueType,
    hasIterationsFeature,
    // for issue
    registerPath,
    signInPath,
    // for incident
    canUpdate,
    canUpdateTimelineEvent,
    currentPath,
    currentTab,
    hasLinkedAlerts,
    projectId,
    slaFeatureAvailable,
    uploadMetricsFeatureAvailable,
  } = issuableData;

  const issueProvideData = { registerPath, signInPath };
  const incidentProvideData = {
    canUpdate,
    canUpdateTimelineEvent,
    hasLinkedAlerts: parseBoolean(hasLinkedAlerts),
    projectId,
    slaFeatureAvailable: parseBoolean(slaFeatureAvailable),
    uploadMetricsFeatureAvailable: parseBoolean(uploadMetricsFeatureAvailable),
  };

  bootstrapApollo({ ...issueState, issueType });

  scrollToTargetOnResize();

  if (issueType === TYPE_INCIDENT) {
    initLinkedResources();
  }

  return new Vue({
    el,
    name: 'DescriptionRoot',
    apolloProvider,
    store,
    router: issueType === TYPE_INCIDENT ? createRouter(currentPath, currentTab) : undefined,
    provide: {
      canCreateIncident,
      fullPath,
      iid,
      issuableId,
      issueType,
      hasIterationsFeature,
      ...(issueType === TYPE_ISSUE && issueProvideData),
      ...(issueType === TYPE_INCIDENT && incidentProvideData),
      // for HeaderActions component
      canCreateIssue:
        issueType === TYPE_INCIDENT
          ? parseBoolean(headerActionsData.canCreateIncident)
          : parseBoolean(headerActionsData.canCreateIssue),
      canDestroyIssue: parseBoolean(headerActionsData.canDestroyIssue),
      canPromoteToEpic: parseBoolean(headerActionsData.canPromoteToEpic),
      canReopenIssue: parseBoolean(headerActionsData.canReopenIssue),
      canReportSpam: parseBoolean(headerActionsData.canReportSpam),
      canUpdateIssue: parseBoolean(headerActionsData.canUpdateIssue),
      isIssueAuthor: parseBoolean(headerActionsData.isIssueAuthor),
      issuePath: headerActionsData.issuePath,
      newIssuePath: headerActionsData.newIssuePath,
      projectPath: headerActionsData.projectPath,
      reportAbusePath: headerActionsData.reportAbusePath,
      reportedUserId: headerActionsData.reportedUserId,
      reportedFromUrl: headerActionsData.reportedFromUrl,
      submitAsSpamPath: headerActionsData.submitAsSpamPath,
      issuableEmailAddress: headerActionsData.issuableEmailAddress,
    },
    computed: {
      ...mapGetters(['getNoteableData']),
    },
    render(createElement) {
      return createElement(IssueApp, {
        props: {
          ...issuableData,
          author: {
            id: authorId,
            name: authorName,
            username: authorUsername,
            webUrl: authorWebUrl,
          },
          descriptionComponent: issueType === TYPE_INCIDENT ? IncidentTabs : DescriptionComponent,
          isConfidential: this.getNoteableData?.confidential,
          isLocked: this.getNoteableData?.discussion_locked,
          issuableStatus: this.getNoteableData?.state,
          issuableType: issueType,
          issueId: this.getNoteableData?.id,
          issueIid: this.getNoteableData?.iid,
          showTitleBorder: issueType !== TYPE_INCIDENT,
        },
      });
    },
  });
}

export function initSentryErrorStackTrace() {
  const el = document.querySelector('#js-sentry-error-stack-trace');

  if (!el) {
    return undefined;
  }

  const { issueStackTracePath } = el.dataset;

  return new Vue({
    el,
    name: 'SentryErrorStackTraceRoot',
    store: errorTrackingStore,
    render: (createElement) =>
      createElement(SentryErrorStackTrace, { props: { issueStackTracePath } }),
  });
}