From 3e3bead22bddc65963319e38926bae4c2c3a0eab Mon Sep 17 00:00:00 2001 From: Jose Vargas Date: Wed, 10 Apr 2019 12:33:30 -0500 Subject: Make time window parameters available in the query string This commit adds the frontend functionality to add the parameters via the `pushState` api, preventing the need for a page reload. --- .../monitoring/components/dashboard.vue | 43 ++++++++++------------ app/assets/javascripts/monitoring/constants.js | 9 +++++ locale/gitlab.pot | 3 -- spec/javascripts/monitoring/dashboard_spec.js | 37 ++++++++++++++++++- 4 files changed, 65 insertions(+), 27 deletions(-) diff --git a/app/assets/javascripts/monitoring/components/dashboard.vue b/app/assets/javascripts/monitoring/components/dashboard.vue index 00547abd7bc..33f6afc9c2d 100644 --- a/app/assets/javascripts/monitoring/components/dashboard.vue +++ b/app/assets/javascripts/monitoring/components/dashboard.vue @@ -1,16 +1,17 @@ @@ -239,8 +237,7 @@ export default { v-for="(value, key) in timeWindows" :key="key" :active="activeTimeWindow(key)" - @click="getGraphsDataWithTime(key)" - >{{ value }}{{ value }} diff --git a/app/assets/javascripts/monitoring/constants.js b/app/assets/javascripts/monitoring/constants.js index e97320fd682..26f1bf3f68d 100644 --- a/app/assets/javascripts/monitoring/constants.js +++ b/app/assets/javascripts/monitoring/constants.js @@ -18,3 +18,12 @@ export const timeWindows = { threeDays: __('3 days'), oneWeek: __('1 week'), }; + +export const timeWindowsKeyNames = { + thirtyMinutes: 'thirtyMinutes', + threeHours: 'threeHours', + eightHours: 'eightHours', + oneDay: 'oneDay', + threeDays: 'threeDays', + oneWeek: 'oneWeek', +}; diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 78d50c74eac..00324c85cda 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -5661,9 +5661,6 @@ msgstr "" msgid "Metrics|No deployed environments" msgstr "" -msgid "Metrics|Not enough data to display" -msgstr "" - msgid "Metrics|Show last" msgstr "" diff --git a/spec/javascripts/monitoring/dashboard_spec.js b/spec/javascripts/monitoring/dashboard_spec.js index 16dc0084a10..5c28840d3a4 100644 --- a/spec/javascripts/monitoring/dashboard_spec.js +++ b/spec/javascripts/monitoring/dashboard_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import MockAdapter from 'axios-mock-adapter'; import Dashboard from '~/monitoring/components/dashboard.vue'; -import { timeWindows } from '~/monitoring/constants'; +import { timeWindows, timeWindowsKeyNames } from '~/monitoring/constants'; import axios from '~/lib/utils/axios_utils'; import { metricsGroupsAPIResponse, mockApiEndpoint, environmentData } from './mock_data'; @@ -248,6 +248,41 @@ describe('Dashboard', () => { done(); }); }); + + it('shows a specific time window selected from the url params', done => { + spyOnDependency(Dashboard, 'getParameterValues').and.returnValue(['thirtyMinutes']); + + const component = new DashboardComponent({ + el: document.querySelector('.prometheus-graphs'), + propsData: { ...propsData, hasMetrics: true, showTimeWindowDropdown: true }, + }); + + setTimeout(() => { + const selectedTimeWindow = component.$el.querySelector( + '.js-time-window-dropdown [active="true"]', + ); + + expect(selectedTimeWindow.textContent.trim()).toEqual('30 minutes'); + done(); + }); + }); + + it('defaults to the eight hours time window for non valid url parameters', done => { + spyOnDependency(Dashboard, 'getParameterValues').and.returnValue([ + '', + ]); + + const component = new DashboardComponent({ + el: document.querySelector('.prometheus-graphs'), + propsData: { ...propsData, hasMetrics: true, showTimeWindowDropdown: true }, + }); + + Vue.nextTick(() => { + expect(component.selectedTimeWindowKey).toEqual(timeWindowsKeyNames.eightHours); + + done(); + }); + }); }); describe('when the window resizes', () => { -- cgit v1.2.1