debian-mirror-gitlab/app/assets/javascripts/monitoring/monitoring_app.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-06-23 00:09:42 +05:30
import { GlToast } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import Vue from 'vue';
2020-06-23 00:09:42 +05:30
import createRouter from './router';
2021-03-11 19:13:27 +05:30
import { createStore } from './stores';
2020-07-28 23:09:34 +05:30
import { stateAndPropsFromDataset } from './utils';
2020-06-23 00:09:42 +05:30
Vue.use(GlToast);
export default (props = {}) => {
const el = document.getElementById('prometheus-graphs');
if (el && el.dataset) {
2020-07-28 23:09:34 +05:30
const { metricsDashboardBasePath, ...dataset } = el.dataset;
2020-06-23 00:09:42 +05:30
2021-12-11 22:18:48 +05:30
const { initState, dataProps } = stateAndPropsFromDataset(dataset);
2020-07-28 23:09:34 +05:30
const store = createStore(initState);
2020-06-23 00:09:42 +05:30
const router = createRouter(metricsDashboardBasePath);
// eslint-disable-next-line no-new
new Vue({
el,
store,
router,
data() {
return {
dashboardProps: { ...dataProps, ...props },
};
},
2021-03-11 19:13:27 +05:30
render(h) {
return h('RouterView', {
// This is attrs rather than props because:
// 1. RouterView only actually defines one prop: `name`.
// 2. The RouterView [throws away other props][1] given to it, in
// favour of those configured in the route config/params.
// 3. The Vue template compiler itself in general compiles anything
// like <some-component :foo="bar" /> into roughly
// h('some-component', { attrs: { foo: bar } }). Then later, Vue
// [extract props from attrs and merges them with props][2],
// matching them up according to the component's definition.
// [1]: https://github.com/vuejs/vue-router/blob/v3.4.9/src/components/view.js#L124
// [2]: https://github.com/vuejs/vue/blob/v2.6.12/src/core/vdom/helpers/extract-props.js#L12-L50
attrs: {
dashboardProps: this.dashboardProps,
},
});
},
2020-06-23 00:09:42 +05:30
});
}
};