Commit f77ff0c7 authored by Jose Vargas's avatar Jose Vargas

Add support for time windows for the performance dashbooards

The performance dashboards will now display the data
from a set amount of time windows that are defined
on a constants file
parent 1ddd9eff
...@@ -9,6 +9,7 @@ import MonitorAreaChart from './charts/area.vue'; ...@@ -9,6 +9,7 @@ import MonitorAreaChart from './charts/area.vue';
import GraphGroup from './graph_group.vue'; import GraphGroup from './graph_group.vue';
import EmptyState from './empty_state.vue'; import EmptyState from './empty_state.vue';
import MonitoringStore from '../stores/monitoring_store'; import MonitoringStore from '../stores/monitoring_store';
import { timeWindows } from '../constants';
const sidebarAnimationDuration = 150; const sidebarAnimationDuration = 150;
let sidebarMutationObserver; let sidebarMutationObserver;
...@@ -94,6 +95,7 @@ export default { ...@@ -94,6 +95,7 @@ export default {
state: 'gettingStarted', state: 'gettingStarted',
showEmptyState: true, showEmptyState: true,
elWidth: 0, elWidth: 0,
selectedTimeWindow: '',
}; };
}, },
created() { created() {
...@@ -102,6 +104,9 @@ export default { ...@@ -102,6 +104,9 @@ export default {
deploymentEndpoint: this.deploymentEndpoint, deploymentEndpoint: this.deploymentEndpoint,
environmentsEndpoint: this.environmentsEndpoint, environmentsEndpoint: this.environmentsEndpoint,
}); });
this.timeWindows = timeWindows;
this.selectedTimeWindow = this.timeWindows.eightHours;
}, },
beforeDestroy() { beforeDestroy() {
if (sidebarMutationObserver) { if (sidebarMutationObserver) {
...@@ -160,11 +165,17 @@ export default { ...@@ -160,11 +165,17 @@ export default {
this.state = 'unableToConnect'; this.state = 'unableToConnect';
}); });
}, },
getGraphsDataWithTime(timeFrame) {
this.selectedTimeWindow = this.timeWindows[timeFrame];
},
onSidebarMutation() { onSidebarMutation() {
setTimeout(() => { setTimeout(() => {
this.elWidth = this.$el.clientWidth; this.elWidth = this.$el.clientWidth;
}, sidebarAnimationDuration); }, sidebarAnimationDuration);
}, },
activeTimeWindow(key) {
return this.timeWindows[key] === this.selectedTimeWindow;
},
}, },
}; };
</script> </script>
...@@ -172,21 +183,40 @@ export default { ...@@ -172,21 +183,40 @@ export default {
<template> <template>
<div v-if="!showEmptyState" class="prometheus-graphs prepend-top-default"> <div v-if="!showEmptyState" class="prometheus-graphs prepend-top-default">
<div v-if="environmentsEndpoint" class="environments d-flex align-items-center"> <div v-if="environmentsEndpoint" class="environments d-flex align-items-center">
<strong>{{ s__('Metrics|Environment') }}</strong> <div class="d-flex align-items-center">
<gl-dropdown <strong>{{ s__('Metrics|Environment') }}</strong>
class="prepend-left-10 js-environments-dropdown" <gl-dropdown
toggle-class="dropdown-menu-toggle" class="prepend-left-10 js-environments-dropdown"
:text="currentEnvironmentName" toggle-class="dropdown-menu-toggle"
:disabled="store.environmentsData.length === 0" :text="currentEnvironmentName"
> :disabled="store.environmentsData.length === 0"
<gl-dropdown-item >
v-for="environment in store.environmentsData" <gl-dropdown-item
:key="environment.id" v-for="environment in store.environmentsData"
:active="environment.name === currentEnvironmentName" :key="environment.id"
active-class="is-active" :active="environment.name === currentEnvironmentName"
>{{ environment.name }}</gl-dropdown-item active-class="is-active"
>{{ environment.name }}</gl-dropdown-item
>
</gl-dropdown>
</div>
<div class="d-flex align-items-center">
<span class="font-weight-bold">{{ s__('Metrics|Show Last') }}</span>
<gl-dropdown
id="time-window-dropdown"
class="prepend-left-10"
toggle-class="dropdown-menu-toggle"
:text="selectedTimeWindow"
> >
</gl-dropdown> <gl-dropdown-item
v-for="(value, key) in timeWindows"
:key="key"
:active="activeTimeWindow(key)"
@click="getGraphsDataWithTime(key)"
>{{ value }}</gl-dropdown-item
>
</gl-dropdown>
</div>
</div> </div>
<graph-group <graph-group
v-for="(groupData, index) in store.groups" v-for="(groupData, index) in store.groups"
......
...@@ -7,3 +7,12 @@ export const graphTypes = { ...@@ -7,3 +7,12 @@ export const graphTypes = {
export const lineTypes = { export const lineTypes = {
default: 'solid', default: 'solid',
}; };
export const timeWindows = {
thirtyMinutes: '30 minutes',
threeHours: '3 hours',
eightHours: '8 hours',
oneDay: '1 day',
threeDays: '3 days',
oneWeek: '1 week',
};
...@@ -204,7 +204,7 @@ ...@@ -204,7 +204,7 @@
} }
.prometheus-graphs { .prometheus-graphs {
.environments { .dropdowns {
.dropdown-menu-toggle { .dropdown-menu-toggle {
svg { svg {
position: absolute; position: absolute;
......
import Vue from 'vue'; import Vue from 'vue';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import Dashboard from '~/monitoring/components/dashboard.vue'; import Dashboard from '~/monitoring/components/dashboard.vue';
import { timeWindows } from '~/monitoring/constants';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { metricsGroupsAPIResponse, mockApiEndpoint, environmentData } from './mock_data'; import { metricsGroupsAPIResponse, mockApiEndpoint, environmentData } from './mock_data';
...@@ -131,7 +132,7 @@ describe('Dashboard', () => { ...@@ -131,7 +132,7 @@ describe('Dashboard', () => {
setTimeout(() => { setTimeout(() => {
const dropdownMenuEnvironments = component.$el.querySelectorAll( const dropdownMenuEnvironments = component.$el.querySelectorAll(
'.js-environments-dropdown .dropdown-item', '.js-environments-dropdown ul',
); );
expect(dropdownMenuEnvironments.length).toEqual(0); expect(dropdownMenuEnvironments.length).toEqual(0);
...@@ -176,6 +177,26 @@ describe('Dashboard', () => { ...@@ -176,6 +177,26 @@ describe('Dashboard', () => {
done(); done();
}); });
}); });
it('renders the time window dropdown with a set of options ', done => {
const component = new DashboardComponent({
el: document.querySelector('.prometheus-graphs'),
propsData: { ...propsData, hasMetrics: true, showPanels: false },
});
const numberOfTimeWindows = Object.keys(timeWindows).length;
setTimeout(() => {
const timeWindowDropdown = component.$el.querySelector('#time-window-dropdown');
const timeWindowDropdownEls = component.$el.querySelectorAll(
'#time-window-dropdown .dropdown-item',
);
expect(timeWindowDropdown).not.toBeNull();
expect(timeWindowDropdownEls.length).toEqual(numberOfTimeWindows);
done();
});
});
}); });
describe('when the window resizes', () => { describe('when the window resizes', () => {
......
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