debian-mirror-gitlab/app/assets/javascripts/behaviors/markdown/render_metrics.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-10-12 21:52:04 +05:30
import Vue from 'vue';
2020-04-22 19:07:51 +05:30
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) {
2020-05-24 23:13:21 +05:30
return Promise.resolve();
2019-10-12 21:52:04 +05:30
}
2020-04-22 19:07:51 +05:30
const wrapperList = [];
2021-03-08 18:12:59 +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-05-24 23:13:21 +05:30
return import(
/* webpackChunkName: 'gfm_metrics' */ '~/monitoring/components/embeds/embed_group.vue'
).then(({ default: EmbedGroup }) => {
const EmbedGroupComponent = Vue.extend(EmbedGroup);
2021-03-08 18:12:59 +05:30
wrapperList.forEach((wrapper) => {
2020-05-24 23:13:21 +05:30
// eslint-disable-next-line no-new
new EmbedGroupComponent({
el: wrapper,
store: createStore(),
propsData: {
urls: wrapper.urls,
},
});
2019-10-12 21:52:04 +05:30
});
});
}