Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index.js « observability « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 72ff1357551d4aab0f8cf8c712a67b0574ad005d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import Vue from 'vue';
import VueRouter from 'vue-router';

import ObservabilityApp from './components/observability_app.vue';
import { SKELETON_VARIANTS_BY_ROUTE } from './constants';

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,
    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 },
        });
      },
    },
    render(h) {
      return h(ObservabilityApp, {
        props: {
          observabilityIframeSrc: el.dataset.observabilityIframeSrc,
          skeletonVariant: this.skeletonVariant,
        },
        on: {
          'route-update': (payload) => this.routeUpdateHandler(payload),
        },
      });
    },
  });
};