2022-04-04 11:22:00 +05:30
|
|
|
import { defaultDataIdFromObject } from '@apollo/client/core';
|
2021-01-03 14:25:43 +05:30
|
|
|
import produce from 'immer';
|
2020-05-24 23:13:21 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
2020-10-24 23:57:45 +05:30
|
|
|
import createDefaultClient from '~/lib/graphql';
|
2022-06-21 17:19:12 +05:30
|
|
|
import { parseBoolean } from '~/lib/utils/common_utils';
|
|
|
|
import createStore from '~/vue_shared/components/metric_images/store';
|
|
|
|
import service from './service';
|
2020-05-24 23:13:21 +05:30
|
|
|
import AlertDetails from './components/alert_details.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { PAGE_CONFIG } from './constants';
|
|
|
|
import sidebarStatusQuery from './graphql/queries/alert_sidebar_status.query.graphql';
|
2021-01-03 14:25:43 +05:30
|
|
|
import createRouter from './router';
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
export default (selector) => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const domEl = document.querySelector(selector);
|
2023-01-13 00:05:48 +05:30
|
|
|
const {
|
|
|
|
alertId,
|
|
|
|
projectPath,
|
|
|
|
projectIssuesPath,
|
|
|
|
projectAlertManagementDetailsPath,
|
|
|
|
projectId,
|
|
|
|
page,
|
|
|
|
canUpdate,
|
|
|
|
} = domEl.dataset;
|
2022-06-21 17:19:12 +05:30
|
|
|
const iid = alertId;
|
2023-01-13 00:05:48 +05:30
|
|
|
const router = createRouter(projectAlertManagementDetailsPath);
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
const resolvers = {
|
|
|
|
Mutation: {
|
|
|
|
toggleSidebarStatus: (_, __, { cache }) => {
|
2020-11-24 15:15:51 +05:30
|
|
|
const sourceData = cache.readQuery({ query: sidebarStatusQuery });
|
2021-03-08 18:12:59 +05:30
|
|
|
const data = produce(sourceData, (draftData) => {
|
2020-11-24 15:15:51 +05:30
|
|
|
draftData.sidebarStatus = !draftData.sidebarStatus;
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
cache.writeQuery({ query: sidebarStatusQuery, data });
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
const apolloProvider = new VueApollo({
|
2020-07-28 23:09:34 +05:30
|
|
|
defaultClient: createDefaultClient(resolvers, {
|
|
|
|
cacheConfig: {
|
2021-03-08 18:12:59 +05:30
|
|
|
dataIdFromObject: (object) => {
|
2020-07-28 23:09:34 +05:30
|
|
|
// eslint-disable-next-line no-underscore-dangle
|
|
|
|
if (object.__typename === 'AlertManagementAlert') {
|
|
|
|
return object.iid;
|
|
|
|
}
|
|
|
|
return defaultDataIdFromObject(object);
|
2020-05-24 23:13:21 +05:30
|
|
|
},
|
|
|
|
},
|
2020-07-28 23:09:34 +05:30
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
apolloProvider.clients.defaultClient.cache.writeQuery({
|
|
|
|
query: sidebarStatusQuery,
|
2020-07-28 23:09:34 +05:30
|
|
|
data: {
|
|
|
|
sidebarStatus: false,
|
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
const provide = {
|
|
|
|
projectPath,
|
|
|
|
alertId,
|
|
|
|
page,
|
|
|
|
projectIssuesPath,
|
|
|
|
projectId,
|
2022-06-21 17:19:12 +05:30
|
|
|
iid,
|
2021-04-29 21:17:54 +05:30
|
|
|
statuses: PAGE_CONFIG[page].STATUSES,
|
2022-06-21 17:19:12 +05:30
|
|
|
canUpdate: parseBoolean(canUpdate),
|
2021-03-11 19:13:27 +05:30
|
|
|
};
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
const opsProperties = {};
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
const { TRACK_ALERTS_DETAILS_VIEWS_OPTIONS, TRACK_ALERT_STATUS_UPDATE_OPTIONS } = PAGE_CONFIG[
|
|
|
|
page
|
|
|
|
];
|
|
|
|
provide.trackAlertsDetailsViewsOptions = TRACK_ALERTS_DETAILS_VIEWS_OPTIONS;
|
|
|
|
provide.trackAlertStatusUpdateOptions = TRACK_ALERT_STATUS_UPDATE_OPTIONS;
|
|
|
|
opsProperties.store = createStore({}, service);
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
|
|
|
el: selector,
|
2022-04-04 11:22:00 +05:30
|
|
|
name: 'AlertDetailsRoot',
|
2021-03-08 18:12:59 +05:30
|
|
|
components: {
|
|
|
|
AlertDetails,
|
|
|
|
},
|
2022-06-21 17:19:12 +05:30
|
|
|
...opsProperties,
|
2021-03-11 19:13:27 +05:30
|
|
|
provide,
|
2020-05-24 23:13:21 +05:30
|
|
|
apolloProvider,
|
2020-10-24 23:57:45 +05:30
|
|
|
router,
|
2020-05-24 23:13:21 +05:30
|
|
|
render(createElement) {
|
2020-07-28 23:09:34 +05:30
|
|
|
return createElement('alert-details', {});
|
2020-05-24 23:13:21 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|