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

observability_app.vue « components « observability « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 36cbe715149b6ae9c01795cff494d0b37b738e00 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<script>
import { darkModeEnabled } from '~/lib/utils/color_utils';
import { setUrlParams } from '~/lib/utils/url_utility';

import { MESSAGE_EVENT_TYPE, FULL_APP_DIMENSIONS } from '../constants';
import ObservabilitySkeleton from './skeleton/index.vue';

export default {
  components: {
    ObservabilitySkeleton,
  },
  props: {
    observabilityIframeSrc: {
      type: String,
      required: true,
    },
    inlineEmbed: {
      type: Boolean,
      required: false,
      default: false,
    },
    skeletonVariant: {
      type: String,
      required: false,
      default: 'dashboards',
    },
    height: {
      type: String,
      required: false,
      default: FULL_APP_DIMENSIONS.HEIGHT,
    },
    width: {
      type: String,
      required: false,
      default: FULL_APP_DIMENSIONS.WIDTH,
    },
  },
  computed: {
    iframeSrcWithParams() {
      return `${setUrlParams(
        { theme: darkModeEnabled() ? 'dark' : 'light', username: gon?.current_username },
        this.observabilityIframeSrc,
      )}${this.inlineEmbed ? '&kiosk=inline-embed' : ''}`;
    },
  },
  mounted() {
    window.addEventListener('message', this.messageHandler);
  },
  destroyed() {
    window.removeEventListener('message', this.messageHandler);
  },
  methods: {
    messageHandler(e) {
      const isExpectedOrigin = e.origin === new URL(this.observabilityIframeSrc)?.origin;
      if (!isExpectedOrigin) return;

      const {
        data: { type, payload },
      } = e;
      switch (type) {
        case MESSAGE_EVENT_TYPE.GOUI_LOADED:
          this.$refs.observabilitySkeleton.onContentLoaded();
          break;
        case MESSAGE_EVENT_TYPE.GOUI_ROUTE_UPDATE:
          this.$emit('route-update', payload);
          break;
        default:
          break;
      }
    },
  },
};
</script>

<template>
  <observability-skeleton ref="observabilitySkeleton" :variant="skeletonVariant">
    <iframe
      id="observability-ui-iframe"
      data-testid="observability-ui-iframe"
      frameborder="0"
      :width="width"
      :height="height"
      :src="iframeSrcWithParams"
      sandbox="allow-same-origin allow-forms allow-scripts"
    ></iframe>
  </observability-skeleton>
</template>