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.

94 lines
2.5 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-03-17 16:20:25 +05:30
import { MESSAGE_EVENT_TYPE, SKELETON_VARIANTS_BY_ROUTE } 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-03-04 22:38:38 +05:30
computed: {
iframeSrcWithParams() {
return setUrlParams(
{ theme: darkModeEnabled() ? 'dark' : 'light', username: gon?.current_username },
this.observabilityIframeSrc,
);
},
getSkeletonVariant() {
2023-03-17 16:20:25 +05:30
const [, variant] =
Object.entries(SKELETON_VARIANTS_BY_ROUTE).find(([path]) =>
this.$route.path.endsWith(path),
) || [];
const DEFAULT_SKELETON = 'dashboards';
if (!variant) return DEFAULT_SKELETON;
return variant;
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:
this.routeUpdateHandler(payload);
break;
default:
break;
}
},
routeUpdateHandler(payload) {
const isNewObservabilityPath = this.$route?.query?.observability_path !== payload?.url;
2023-01-13 00:05:48 +05:30
2023-03-04 22:38:38 +05:30
const shouldNotHandleMessage = !payload.url || !isNewObservabilityPath;
2023-01-13 00:05:48 +05:30
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,
2023-03-04 22:38:38 +05:30
query: { ...this.$route.query, observability_path: payload.url },
2023-01-13 00:05:48 +05:30
});
},
},
};
</script>
<template>
2023-03-17 16:20:25 +05:30
<observability-skeleton ref="observabilitySkeleton" :variant="getSkeletonVariant">
2023-03-04 22:38:38 +05:30
<iframe
id="observability-ui-iframe"
data-testid="observability-ui-iframe"
frameborder="0"
height="100%"
:src="iframeSrcWithParams"
sandbox="allow-same-origin allow-forms allow-scripts"
></iframe>
</observability-skeleton>
2023-01-13 00:05:48 +05:30
</template>