debian-mirror-gitlab/app/assets/javascripts/observability/components/observability_app.vue

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

88 lines
2.2 KiB
Vue
Raw Normal View History

2023-01-13 00:05:48 +05:30
<script>
2023-03-04 22:38:38 +05:30
import { darkModeEnabled } from '~/lib/utils/color_utils';
import { setUrlParams } from '~/lib/utils/url_utility';
2023-05-27 22:25:52 +05:30
import { MESSAGE_EVENT_TYPE, FULL_APP_DIMENSIONS } from '../constants';
2023-03-04 22:38:38 +05:30
import ObservabilitySkeleton from './skeleton/index.vue';
2023-01-13 00:05:48 +05:30
export default {
2023-03-04 22:38:38 +05:30
components: {
ObservabilitySkeleton,
},
2023-01-13 00:05:48 +05:30
props: {
observabilityIframeSrc: {
type: String,
required: true,
},
2023-05-27 22:25:52 +05:30
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,
},
2023-01-13 00:05:48 +05:30
},
2023-03-04 22:38:38 +05:30
computed: {
iframeSrcWithParams() {
2023-05-27 22:25:52 +05:30
return `${setUrlParams(
2023-03-04 22:38:38 +05:30
{ theme: darkModeEnabled() ? 'dark' : 'light', username: gon?.current_username },
this.observabilityIframeSrc,
2023-05-27 22:25:52 +05:30
)}${this.inlineEmbed ? '&kiosk=inline-embed' : ''}`;
2023-03-04 22:38:38 +05:30
},
},
2023-01-13 00:05:48 +05:30
mounted() {
window.addEventListener('message', this.messageHandler);
},
2023-03-04 22:38:38 +05:30
destroyed() {
window.removeEventListener('message', this.messageHandler);
},
2023-01-13 00:05:48 +05:30
methods: {
messageHandler(e) {
const isExpectedOrigin = e.origin === new URL(this.observabilityIframeSrc)?.origin;
2023-03-04 22:38:38 +05:30
if (!isExpectedOrigin) return;
2023-01-13 00:05:48 +05:30
2023-03-04 22:38:38 +05:30
const {
data: { type, payload },
} = e;
switch (type) {
case MESSAGE_EVENT_TYPE.GOUI_LOADED:
2023-03-17 16:20:25 +05:30
this.$refs.observabilitySkeleton.onContentLoaded();
2023-03-04 22:38:38 +05:30
break;
case MESSAGE_EVENT_TYPE.GOUI_ROUTE_UPDATE:
2023-05-27 22:25:52 +05:30
this.$emit('route-update', payload);
2023-03-04 22:38:38 +05:30
break;
default:
break;
}
},
2023-01-13 00:05:48 +05:30
},
};
</script>
<template>
2023-05-27 22:25:52 +05:30
<observability-skeleton ref="observabilitySkeleton" :variant="skeletonVariant">
2023-03-04 22:38:38 +05:30
<iframe
id="observability-ui-iframe"
data-testid="observability-ui-iframe"
frameborder="0"
2023-05-27 22:25:52 +05:30
:width="width"
:height="height"
2023-03-04 22:38:38 +05:30
:src="iframeSrcWithParams"
sandbox="allow-same-origin allow-forms allow-scripts"
></iframe>
</observability-skeleton>
2023-01-13 00:05:48 +05:30
</template>