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

76 lines
2.1 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { defaultDataIdFromObject } from 'apollo-cache-inmemory';
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 { parseBoolean } from '~/lib/utils/common_utils';
2021-03-11 19:13:27 +05:30
import { PAGE_CONFIG } from '~/vue_shared/alert_details/constants';
2020-07-28 23:09:34 +05:30
import AlertManagementList from './components/alert_management_list_wrapper.vue';
2021-04-29 21:17:54 +05:30
import alertsHelpUrlQuery from './graphql/queries/alert_help_url.query.graphql';
2020-05-24 23:13:21 +05:30
Vue.use(VueApollo);
export default () => {
const selector = '#js-alert_management';
const domEl = document.querySelector(selector);
2020-07-28 23:09:34 +05:30
const {
projectPath,
enableAlertManagementPath,
emptyAlertSvgPath,
populatingAlertsHelpUrl,
2020-10-24 23:57:45 +05:30
alertsHelpUrl,
2021-01-03 14:25:43 +05:30
textQuery,
assigneeUsernameQuery,
alertManagementEnabled,
userCanEnableAlertManagement,
2021-06-08 01:23:25 +05:30
hasManagedPrometheus,
2020-07-28 23:09:34 +05:30
} = domEl.dataset;
2020-05-24 23:13:21 +05:30
const apolloProvider = new VueApollo({
defaultClient: createDefaultClient(
{},
{
cacheConfig: {
2021-03-08 18:12:59 +05:30
dataIdFromObject: (object) => {
2020-05-24 23:13:21 +05:30
// eslint-disable-next-line no-underscore-dangle
if (object.__typename === 'AlertManagementAlert') {
return object.iid;
}
return defaultDataIdFromObject(object);
},
},
},
),
});
2021-04-29 21:17:54 +05:30
apolloProvider.clients.defaultClient.cache.writeQuery({
query: alertsHelpUrlQuery,
2020-10-24 23:57:45 +05:30
data: {
alertsHelpUrl,
},
});
2020-05-24 23:13:21 +05:30
return new Vue({
el: selector,
2021-03-08 18:12:59 +05:30
components: {
AlertManagementList,
},
2021-01-03 14:25:43 +05:30
provide: {
projectPath,
textQuery,
assigneeUsernameQuery,
enableAlertManagementPath,
populatingAlertsHelpUrl,
emptyAlertSvgPath,
alertManagementEnabled: parseBoolean(alertManagementEnabled),
2021-03-11 19:13:27 +05:30
trackAlertStatusUpdateOptions: PAGE_CONFIG.OPERATIONS.TRACK_ALERT_STATUS_UPDATE_OPTIONS,
2021-01-03 14:25:43 +05:30
userCanEnableAlertManagement: parseBoolean(userCanEnableAlertManagement),
2021-06-08 01:23:25 +05:30
hasManagedPrometheus: parseBoolean(hasManagedPrometheus),
2021-01-03 14:25:43 +05:30
},
2020-05-24 23:13:21 +05:30
apolloProvider,
render(createElement) {
2021-01-03 14:25:43 +05:30
return createElement('alert-management-list');
2020-05-24 23:13:21 +05:30
},
});
};