2021-01-03 14:25:43 +05:30
|
|
|
import { defaultDataIdFromObject } from 'apollo-cache-inmemory';
|
|
|
|
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';
|
2020-05-24 23:13:21 +05:30
|
|
|
import AlertDetails from './components/alert_details.vue';
|
2020-07-28 23:09:34 +05:30
|
|
|
import sidebarStatusQuery from './graphql/queries/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);
|
|
|
|
|
|
|
|
export default selector => {
|
|
|
|
const domEl = document.querySelector(selector);
|
2020-07-28 23:09:34 +05:30
|
|
|
const { alertId, projectPath, projectIssuesPath, projectId } = domEl.dataset;
|
2020-10-24 23:57:45 +05:30
|
|
|
const router = createRouter();
|
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 });
|
|
|
|
const data = produce(sourceData, draftData => {
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
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: {
|
|
|
|
dataIdFromObject: object => {
|
|
|
|
// 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-11-24 15:15:51 +05:30
|
|
|
assumeImmutableResults: true,
|
2020-07-28 23:09:34 +05:30
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
apolloProvider.clients.defaultClient.cache.writeData({
|
|
|
|
data: {
|
|
|
|
sidebarStatus: false,
|
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
|
|
|
el: selector,
|
2020-07-28 23:09:34 +05:30
|
|
|
provide: {
|
|
|
|
projectPath,
|
|
|
|
alertId,
|
|
|
|
projectIssuesPath,
|
|
|
|
projectId,
|
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
apolloProvider,
|
|
|
|
components: {
|
|
|
|
AlertDetails,
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|