Commit a3487dc8 authored by Phil Hughes's avatar Phil Hughes

Fetch initial merge request widget data async

This changes the way the merge request widget is init'd
instead of requiring data to be available on creation
it now fetches the initial data on created and then renders the widget

`mrWidgetData` still exists, and now mainly just holds the different
paths and routes that are needed in the widget

Closes https://gitlab.com/gitlab-org/gitlab/issues/31406
parent 17de0b74
...@@ -80,12 +80,10 @@ export default { ...@@ -80,12 +80,10 @@ export default {
}, },
}, },
data() { data() {
const store = new MRWidgetStore(this.mrData || window.gl.mrWidgetData);
const service = this.createService(store);
return { return {
mr: store, mr: null,
state: store.state, state: null,
service, service: null,
}; };
}, },
computed: { computed: {
...@@ -133,18 +131,24 @@ export default { ...@@ -133,18 +131,24 @@ export default {
} }
}, },
}, },
created() { created() {},
this.initPolling();
this.bindEventHubListeners();
eventHub.$on('mr.discussion.updated', this.checkStatus);
},
mounted() { mounted() {
this.setFaviconHelper(); return MRWidgetService.fetchInitialData().then(({ data }) => {
this.initDeploymentsPolling(); this.mr = new MRWidgetStore({ ...window.gl.mrWidgetData, ...data });
this.state = this.mr.state;
this.service = this.createService(this.mr);
if (this.shouldRenderMergedPipeline) { this.setFaviconHelper();
this.initPostMergeDeploymentsPolling(); this.initDeploymentsPolling();
}
if (this.shouldRenderMergedPipeline) {
this.initPostMergeDeploymentsPolling();
}
this.initPolling();
this.bindEventHubListeners();
eventHub.$on('mr.discussion.updated', this.checkStatus);
});
}, },
beforeDestroy() { beforeDestroy() {
eventHub.$off('mr.discussion.updated', this.checkStatus); eventHub.$off('mr.discussion.updated', this.checkStatus);
...@@ -319,7 +323,7 @@ export default { ...@@ -319,7 +323,7 @@ export default {
}; };
</script> </script>
<template> <template>
<div class="mr-state-widget prepend-top-default"> <div v-if="mr" class="mr-state-widget prepend-top-default">
<mr-widget-header :mr="mr" /> <mr-widget-header :mr="mr" />
<mr-widget-pipeline-container <mr-widget-pipeline-container
v-if="shouldRenderPipelines" v-if="shouldRenderPipelines"
......
...@@ -61,4 +61,11 @@ export default class MRWidgetService { ...@@ -61,4 +61,11 @@ export default class MRWidgetService {
static fetchMetrics(metricsUrl) { static fetchMetrics(metricsUrl) {
return axios.get(`${metricsUrl}.json`); return axios.get(`${metricsUrl}.json`);
} }
static fetchInitialData() {
return Promise.all([
axios.get(window.gl.mrWidgetData.merge_request_cached_widget_path),
axios.get(window.gl.mrWidgetData.merge_request_widget_path),
]).then(axios.spread((res, cachedRes) => ({ data: Object.assign(res.data, cachedRes.data) })));
}
} }
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
class MergeRequestWidgetEntity < Grape::Entity class MergeRequestWidgetEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
expose :iid
expose :source_project_full_path do |merge_request| expose :source_project_full_path do |merge_request|
merge_request.source_project&.full_path merge_request.source_project&.full_path
end end
...@@ -66,8 +68,6 @@ class MergeRequestWidgetEntity < Grape::Entity ...@@ -66,8 +68,6 @@ class MergeRequestWidgetEntity < Grape::Entity
def as_json(options = {}) def as_json(options = {})
super(options) super(options)
.merge(MergeRequestPollCachedWidgetEntity.new(object, **@options.opts_hash).as_json(options))
.merge(MergeRequestPollWidgetEntity.new(object, **@options.opts_hash).as_json(options))
end end
private private
......
...@@ -43,7 +43,7 @@ export default { ...@@ -43,7 +43,7 @@ export default {
return this.mr.hasApprovalsAvailable && this.mr.state !== 'nothingToMerge'; return this.mr.hasApprovalsAvailable && this.mr.state !== 'nothingToMerge';
}, },
shouldRenderCodeQuality() { shouldRenderCodeQuality() {
const { codeclimate } = this.mr; const { codeclimate } = this.mr || {};
return codeclimate && codeclimate.head_path && codeclimate.base_path; return codeclimate && codeclimate.head_path && codeclimate.base_path;
}, },
shouldRenderLicenseReport() { shouldRenderLicenseReport() {
...@@ -67,7 +67,7 @@ export default { ...@@ -67,7 +67,7 @@ export default {
); );
}, },
shouldRenderPerformance() { shouldRenderPerformance() {
const { performance } = this.mr; const { performance } = this.mr || {};
return performance && performance.head_path && performance.base_path; return performance && performance.head_path && performance.base_path;
}, },
shouldRenderSecurityReport() { shouldRenderSecurityReport() {
...@@ -149,14 +149,17 @@ export default { ...@@ -149,14 +149,17 @@ export default {
return (gl && gl.mrWidgetData && gl.mrWidgetData.license_management_comparison_path) || null; return (gl && gl.mrWidgetData && gl.mrWidgetData.license_management_comparison_path) || null;
}, },
}, },
created() { watch: {
if (this.shouldRenderCodeQuality) { shouldRenderCodeQuality(newVal) {
this.fetchCodeQuality(); if (newVal) {
} this.fetchCodeQuality();
}
if (this.shouldRenderPerformance) { },
this.fetchPerformance(); shouldRenderPerformance(newVal) {
} if (newVal) {
this.fetchPerformance();
}
},
}, },
methods: { methods: {
getServiceEndpoints(store) { getServiceEndpoints(store) {
...@@ -223,7 +226,7 @@ export default { ...@@ -223,7 +226,7 @@ export default {
}; };
</script> </script>
<template> <template>
<div class="mr-state-widget prepend-top-default"> <div v-if="mr" class="mr-state-widget prepend-top-default">
<mr-widget-header :mr="mr" /> <mr-widget-header :mr="mr" />
<mr-widget-pipeline-container <mr-widget-pipeline-container
v-if="shouldRenderPipelines" v-if="shouldRenderPipelines"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment