2019-10-12 21:52:04 +05:30
|
|
|
import Vue from 'vue';
|
2020-04-22 19:07:51 +05:30
|
|
|
import EmbedGroup from '~/monitoring/components/embeds/embed_group.vue';
|
|
|
|
import { createStore } from '~/monitoring/stores/embed_group/';
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
// TODO: Handle copy-pasting - https://gitlab.com/gitlab-org/gitlab-foss/issues/64369.
|
2019-10-12 21:52:04 +05:30
|
|
|
export default function renderMetrics(elements) {
|
|
|
|
if (!elements.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
const EmbedGroupComponent = Vue.extend(EmbedGroup);
|
|
|
|
|
|
|
|
const wrapperList = [];
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
elements.forEach(element => {
|
2020-04-22 19:07:51 +05:30
|
|
|
let wrapper;
|
|
|
|
const { previousElementSibling } = element;
|
|
|
|
const isFirstElementInGroup = !previousElementSibling?.urls;
|
|
|
|
|
|
|
|
if (isFirstElementInGroup) {
|
|
|
|
wrapper = document.createElement('div');
|
|
|
|
wrapper.urls = [element.dataset.dashboardUrl];
|
|
|
|
element.parentNode.insertBefore(wrapper, element);
|
|
|
|
wrapperList.push(wrapper);
|
|
|
|
} else {
|
|
|
|
wrapper = previousElementSibling;
|
|
|
|
wrapper.urls.push(element.dataset.dashboardUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up processed element
|
|
|
|
element.parentNode.removeChild(element);
|
|
|
|
});
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
wrapperList.forEach(wrapper => {
|
2019-10-12 21:52:04 +05:30
|
|
|
// eslint-disable-next-line no-new
|
2020-04-22 19:07:51 +05:30
|
|
|
new EmbedGroupComponent({
|
|
|
|
el: wrapper,
|
2019-10-12 21:52:04 +05:30
|
|
|
store: createStore(),
|
|
|
|
propsData: {
|
2020-04-22 19:07:51 +05:30
|
|
|
urls: wrapper.urls,
|
2019-10-12 21:52:04 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|