debian-mirror-gitlab/app/assets/javascripts/alert_management/details.js

62 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql';
import { defaultDataIdFromObject } from 'apollo-cache-inmemory';
import AlertDetails from './components/alert_details.vue';
2020-07-28 23:09:34 +05:30
import sidebarStatusQuery from './graphql/queries/sidebar_status.query.graphql';
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;
const resolvers = {
Mutation: {
toggleSidebarStatus: (_, __, { cache }) => {
const data = cache.readQuery({ query: sidebarStatusQuery });
data.sidebarStatus = !data.sidebarStatus;
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-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,
},
render(createElement) {
2020-07-28 23:09:34 +05:30
return createElement('alert-details', {});
2020-05-24 23:13:21 +05:30
},
});
};