debian-mirror-gitlab/app/assets/javascripts/observability/index.js

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

61 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-01-13 00:05:48 +05:30
import Vue from 'vue';
import VueRouter from 'vue-router';
import ObservabilityApp from './components/observability_app.vue';
2023-05-27 22:25:52 +05:30
import { SKELETON_VARIANTS_BY_ROUTE } from './constants';
2023-01-13 00:05:48 +05:30
Vue.use(VueRouter);
export default () => {
const el = document.getElementById('js-observability-app');
if (!el) return false;
const router = new VueRouter({
mode: 'history',
});
return new Vue({
el,
router,
2023-05-27 22:25:52 +05:30
computed: {
skeletonVariant() {
const [, variant] =
Object.entries(SKELETON_VARIANTS_BY_ROUTE).find(([path]) =>
this.$route.path.endsWith(path),
) || [];
return variant;
},
},
methods: {
routeUpdateHandler(payload) {
const isNewObservabilityPath = this.$route?.query?.observability_path !== payload?.url;
const shouldNotHandleMessage = !payload.url || !isNewObservabilityPath;
if (shouldNotHandleMessage) {
return;
}
// this will update the `observability_path` query param on each route change inside Observability UI
this.$router.replace({
name: this.$route?.pathname,
query: { ...this.$route.query, observability_path: payload.url },
});
},
},
2023-01-13 00:05:48 +05:30
render(h) {
return h(ObservabilityApp, {
props: {
observabilityIframeSrc: el.dataset.observabilityIframeSrc,
2023-05-27 22:25:52 +05:30
skeletonVariant: this.skeletonVariant,
},
on: {
'route-update': (payload) => this.routeUpdateHandler(payload),
2023-01-13 00:05:48 +05:30
},
});
},
});
};