From d0f81b60e45a0eed8eb863aa9fc9070d1f416f14 Mon Sep 17 00:00:00 2001 From: Jose Vargas Date: Thu, 13 Sep 2018 14:33:31 -0500 Subject: Fix monitoring dashboard not working properly This fixes a bug when the monitoring dashboard wouldn't redraw for when the sidebar was collapsed/expanded on medium to small screens. This is done by enforcing vue to update based on the change of a key --- .../monitoring/components/dashboard.vue | 35 ++++++++++++---------- .../javascripts/monitoring/components/graph.vue | 13 -------- 2 files changed, 20 insertions(+), 28 deletions(-) (limited to 'app/assets/javascripts/monitoring') diff --git a/app/assets/javascripts/monitoring/components/dashboard.vue b/app/assets/javascripts/monitoring/components/dashboard.vue index ae96ac3b80c..524f4d1f568 100644 --- a/app/assets/javascripts/monitoring/components/dashboard.vue +++ b/app/assets/javascripts/monitoring/components/dashboard.vue @@ -97,33 +97,45 @@ export default { store: new MonitoringStore(), state: 'gettingStarted', showEmptyState: true, - updateAspectRatio: false, - updatedAspectRatios: 0, hoverData: {}, - resizeThrottled: {}, + updateDashboardKeyNumber: 0, }; }, + computed: { + forceRedraw() { + return `dashboard-key-${this.updateDashboardKeyNumber}`; + }, + }, created() { this.service = new MonitoringService({ metricsEndpoint: this.metricsEndpoint, deploymentEndpoint: this.deploymentEndpoint, environmentsEndpoint: this.environmentsEndpoint, }); - eventHub.$on('toggleAspectRatio', this.toggleAspectRatio); + this.mutationObserverConfig = { + attributes: true, + childList: false, + subtree: false, + }; eventHub.$on('hoverChanged', this.hoverChanged); }, beforeDestroy() { - eventHub.$off('toggleAspectRatio', this.toggleAspectRatio); eventHub.$off('hoverChanged', this.hoverChanged); window.removeEventListener('resize', this.resizeThrottled, false); + this.sidebarMutationObserver.disconnect(); }, mounted() { - this.resizeThrottled = _.throttle(this.resize, 600); + this.resizeThrottled = _.debounce(this.resize, 100); if (!this.hasMetrics) { this.state = 'gettingStarted'; } else { this.getGraphsData(); window.addEventListener('resize', this.resizeThrottled, false); + + const sidebarEl = document.querySelector('.nav-sidebar'); + // The sidebar listener + this.sidebarMutationObserver = new MutationObserver(this.resizeThrottled); + this.sidebarMutationObserver.observe(sidebarEl, this.mutationObserverConfig); } }, methods: { @@ -153,14 +165,7 @@ export default { }); }, resize() { - this.updateAspectRatio = true; - }, - toggleAspectRatio() { - this.updatedAspectRatios += 1; - if (this.store.getMetricsCount() === this.updatedAspectRatios) { - this.updateAspectRatio = !this.updateAspectRatio; - this.updatedAspectRatios = 0; - } + this.updateDashboardKeyNumber += 1; }, hoverChanged(data) { this.hoverData = data; @@ -172,6 +177,7 @@ export default {