debian-mirror-gitlab/app/assets/javascripts/performance_bar/index.js

64 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import Vue from 'vue';
2018-11-18 11:00:15 +05:30
import PerformanceBarService from './services/performance_bar_service';
2018-05-09 12:01:36 +05:30
import PerformanceBarStore from './stores/performance_bar_store';
export default ({ container }) =>
new Vue({
el: container,
components: {
2019-12-21 20:55:43 +05:30
PerformanceBarApp: () => import('./components/performance_bar_app.vue'),
2018-05-09 12:01:36 +05:30
},
data() {
2018-12-13 13:39:08 +05:30
const performanceBarData = document.querySelector(this.$options.el).dataset;
2018-05-09 12:01:36 +05:30
const store = new PerformanceBarStore();
return {
store,
env: performanceBarData.env,
requestId: performanceBarData.requestId,
peekUrl: performanceBarData.peekUrl,
profileUrl: performanceBarData.profileUrl,
};
},
2018-11-18 11:00:15 +05:30
mounted() {
this.interceptor = PerformanceBarService.registerInterceptor(
this.peekUrl,
this.loadRequestDetails,
);
this.loadRequestDetails(this.requestId, window.location.href);
},
beforeDestroy() {
PerformanceBarService.removeInterceptor(this.interceptor);
},
methods: {
loadRequestDetails(requestId, requestUrl) {
if (!this.store.canTrackRequest(requestUrl)) {
return;
}
this.store.addRequest(requestId, requestUrl);
PerformanceBarService.fetchRequestDetails(this.peekUrl, requestId)
.then(res => {
2019-12-21 20:55:43 +05:30
this.store.addRequestDetails(requestId, res.data);
2018-11-18 11:00:15 +05:30
})
.catch(() =>
2018-11-20 20:47:30 +05:30
// eslint-disable-next-line no-console
console.warn(`Error getting performance bar results for ${requestId}`),
2018-11-18 11:00:15 +05:30
);
},
},
2018-05-09 12:01:36 +05:30
render(createElement) {
return createElement('performance-bar-app', {
props: {
store: this.store,
env: this.env,
requestId: this.requestId,
peekUrl: this.peekUrl,
profileUrl: this.profileUrl,
},
});
},
});