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';
|
|
|
|
|
|
|
|
import { MESSAGE_EVENT_TYPE, OBSERVABILITY_ROUTES, SKELETON_VARIANT } from '../constants';
|
|
|
|
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() {
|
|
|
|
switch (this.$route.path) {
|
|
|
|
case OBSERVABILITY_ROUTES.DASHBOARDS:
|
|
|
|
return SKELETON_VARIANT.DASHBOARDS;
|
|
|
|
case OBSERVABILITY_ROUTES.EXPLORE:
|
|
|
|
return SKELETON_VARIANT.EXPLORE;
|
|
|
|
case OBSERVABILITY_ROUTES.MANAGE:
|
|
|
|
return SKELETON_VARIANT.MANAGE;
|
|
|
|
default:
|
|
|
|
return SKELETON_VARIANT.DASHBOARDS;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
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:
|
|
|
|
this.$refs.iframeSkeleton.handleSkeleton();
|
|
|
|
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-04 22:38:38 +05:30
|
|
|
<observability-skeleton ref="iframeSkeleton" :variant="getSkeletonVariant">
|
|
|
|
<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>
|