2020-10-13 02:09:09 -04:00
|
|
|
import { defaultDataIdFromObject } from 'apollo-cache-inmemory';
|
|
|
|
import produce from 'immer';
|
2020-04-30 17:09:47 -04:00
|
|
|
import Vue from 'vue';
|
2020-05-06 11:09:42 -04:00
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import createDefaultClient from '~/lib/graphql';
|
2020-04-30 17:09:47 -04:00
|
|
|
import AlertDetails from './components/alert_details.vue';
|
2021-02-04 13:09:22 -05:00
|
|
|
import sidebarStatusQuery from './graphql/queries/alert_sidebar_status.query.graphql';
|
2020-10-13 02:09:09 -04:00
|
|
|
import createRouter from './router';
|
2021-02-12 07:09:02 -05:00
|
|
|
import { PAGE_CONFIG } from './constants';
|
2020-04-30 17:09:47 -04:00
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
export default (selector) => {
|
2020-05-06 11:09:42 -04:00
|
|
|
const domEl = document.querySelector(selector);
|
2021-02-12 07:09:02 -05:00
|
|
|
const { alertId, projectPath, projectIssuesPath, projectId, page } = domEl.dataset;
|
2020-08-13 08:09:50 -04:00
|
|
|
const router = createRouter();
|
2020-05-06 11:09:42 -04:00
|
|
|
|
2020-06-30 11:08:48 -04:00
|
|
|
const resolvers = {
|
|
|
|
Mutation: {
|
|
|
|
toggleSidebarStatus: (_, __, { cache }) => {
|
2020-09-11 08:08:50 -04:00
|
|
|
const sourceData = cache.readQuery({ query: sidebarStatusQuery });
|
2020-12-23 16:10:24 -05:00
|
|
|
const data = produce(sourceData, (draftData) => {
|
2020-09-11 08:08:50 -04:00
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
draftData.sidebarStatus = !draftData.sidebarStatus;
|
|
|
|
});
|
2020-06-30 11:08:48 -04:00
|
|
|
cache.writeQuery({ query: sidebarStatusQuery, data });
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
const apolloProvider = new VueApollo({
|
2020-06-30 11:08:48 -04:00
|
|
|
defaultClient: createDefaultClient(resolvers, {
|
|
|
|
cacheConfig: {
|
2020-12-23 16:10:24 -05:00
|
|
|
dataIdFromObject: (object) => {
|
2020-06-30 11:08:48 -04:00
|
|
|
// eslint-disable-next-line no-underscore-dangle
|
|
|
|
if (object.__typename === 'AlertManagementAlert') {
|
|
|
|
return object.iid;
|
|
|
|
}
|
|
|
|
return defaultDataIdFromObject(object);
|
2020-05-15 05:07:59 -04:00
|
|
|
},
|
|
|
|
},
|
2020-09-11 08:08:50 -04:00
|
|
|
assumeImmutableResults: true,
|
2020-06-30 11:08:48 -04:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
apolloProvider.clients.defaultClient.cache.writeData({
|
|
|
|
data: {
|
|
|
|
sidebarStatus: false,
|
|
|
|
},
|
2020-05-06 11:09:42 -04:00
|
|
|
});
|
|
|
|
|
2021-02-04 13:09:22 -05:00
|
|
|
const provide = {
|
|
|
|
projectPath,
|
|
|
|
alertId,
|
2021-02-12 07:09:02 -05:00
|
|
|
page,
|
2021-02-04 13:09:22 -05:00
|
|
|
projectIssuesPath,
|
|
|
|
projectId,
|
|
|
|
};
|
|
|
|
|
2021-02-12 07:09:02 -05:00
|
|
|
if (page === PAGE_CONFIG.OPERATIONS.TITLE) {
|
2021-02-04 13:09:22 -05:00
|
|
|
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;
|
2021-02-12 07:09:02 -05:00
|
|
|
} else if (page === PAGE_CONFIG.THREAT_MONITORING.TITLE) {
|
|
|
|
provide.isThreatMonitoringPage = true;
|
2021-02-04 13:09:22 -05:00
|
|
|
}
|
|
|
|
|
2020-04-30 17:09:47 -04:00
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
|
|
|
el: selector,
|
2021-01-12 04:10:49 -05:00
|
|
|
components: {
|
|
|
|
AlertDetails,
|
|
|
|
},
|
2021-02-04 13:09:22 -05:00
|
|
|
provide,
|
2020-05-06 11:09:42 -04:00
|
|
|
apolloProvider,
|
2020-08-13 08:09:50 -04:00
|
|
|
router,
|
2020-04-30 17:09:47 -04:00
|
|
|
render(createElement) {
|
2020-06-30 11:08:48 -04:00
|
|
|
return createElement('alert-details', {});
|
2020-04-30 17:09:47 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|