Commit 217e9e4d authored by Jose Vargas's avatar Jose Vargas

Created `getTimeDiff` utility function

Updated i18n strings and changed the
monitoring service graph data params
parent b75e03a6
...@@ -9,8 +9,8 @@ import MonitorAreaChart from './charts/area.vue'; ...@@ -9,8 +9,8 @@ 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, msPerMinute } from '../constants'; import { timeWindows } from '../constants';
import { getTimeDifferenceMinutes } from '../utils'; import { getTimeDiff } from '../utils';
const sidebarAnimationDuration = 150; const sidebarAnimationDuration = 150;
let sidebarMutationObserver; let sidebarMutationObserver;
...@@ -100,7 +100,7 @@ export default { ...@@ -100,7 +100,7 @@ export default {
}; };
}, },
computed: { computed: {
getTimeWindowFlagStatus() { showTimeWindowDropdown() {
return gon.features.metricsTimeWindow; return gon.features.metricsTimeWindow;
}, },
}, },
...@@ -113,7 +113,6 @@ export default { ...@@ -113,7 +113,6 @@ export default {
this.timeWindows = timeWindows; this.timeWindows = timeWindows;
this.selectedTimeWindow = this.timeWindows.eightHours; this.selectedTimeWindow = this.timeWindows.eightHours;
this.msPerMinute = msPerMinute;
}, },
beforeDestroy() { beforeDestroy() {
if (sidebarMutationObserver) { if (sidebarMutationObserver) {
...@@ -173,23 +172,18 @@ export default { ...@@ -173,23 +172,18 @@ export default {
}); });
}, },
getGraphsDataWithTime(timeFrame) { getGraphsDataWithTime(timeFrame) {
this.selectedTimeWindow = this.timeWindows[timeFrame];
this.state = 'loading'; this.state = 'loading';
this.showEmptyState = true; this.showEmptyState = true;
const end = Date.now();
const timeDifferenceMinutes = getTimeDifferenceMinutes(this.selectedTimeWindow);
const start = new Date(end - timeDifferenceMinutes * this.msPerMinute).getTime();
this.service this.service
.getGraphsData({ .getGraphsData(getTimeDiff(this.timeWindows[timeFrame]))
start,
end,
})
.then(data => { .then(data => {
this.store.storeMetrics(data); this.store.storeMetrics(data);
this.selectedTimeWindow = this.timeWindows[timeFrame];
this.showEmptyState = false; this.showEmptyState = false;
}) })
.catch(() => { .catch(() => {
this.state = 'unableToConnect'; this.showEmptyState = false;
Flash(s__('Metrics|Not enough data to display'));
}); });
}, },
onSidebarMutation() { onSidebarMutation() {
...@@ -227,8 +221,8 @@ export default { ...@@ -227,8 +221,8 @@ export default {
> >
</gl-dropdown> </gl-dropdown>
</div> </div>
<div v-if="getTimeWindowFlagStatus" class="d-flex align-items-center float-right"> <div v-if="showTimeWindowDropdown" class="d-flex align-items-center">
<span class="font-weight-bold">{{ s__('Metrics|Show Last') }}</span> <strong>{{ s__('Metrics|Show last') }}</strong>
<gl-dropdown <gl-dropdown
class="prepend-left-10 js-time-window-dropdown" class="prepend-left-10 js-time-window-dropdown"
toggle-class="dropdown-menu-toggle" toggle-class="dropdown-menu-toggle"
......
import { __ } from '~/locale';
export const chartHeight = 300; export const chartHeight = 300;
export const graphTypes = { export const graphTypes = {
...@@ -9,12 +11,12 @@ export const lineTypes = { ...@@ -9,12 +11,12 @@ export const lineTypes = {
}; };
export const timeWindows = { export const timeWindows = {
thirtyMinutes: '30 minutes', thirtyMinutes: __('30 minutes'),
threeHours: '3 hours', threeHours: __('3 hours'),
eightHours: '8 hours', eightHours: __('8 hours'),
oneDay: '1 day', oneDay: __('1 day'),
threeDays: '3 days', threeDays: __('3 days'),
oneWeek: '1 week', oneWeek: __('1 week'),
}; };
export const msPerMinute = 60000; export const msPerMinute = 60000;
...@@ -36,7 +36,7 @@ export default class MonitoringService { ...@@ -36,7 +36,7 @@ export default class MonitoringService {
return backOffRequest(() => return backOffRequest(() =>
axios.get(this.metricsEndpoint, { axios.get(this.metricsEndpoint, {
params: { params: {
...params, params,
}, },
}), }),
) )
......
import { timeWindows } from './constants'; import { timeWindows, msPerMinute } from './constants';
export const getTimeDifferenceMinutes = timeWindow => { export const getTimeDifferenceMinutes = timeWindow => {
let timeDifferenceMinutes;
switch (timeWindow) { switch (timeWindow) {
case timeWindows.thirtyMinutes: case timeWindows.thirtyMinutes:
timeDifferenceMinutes = 30; return 30;
break;
case timeWindows.threeHours: case timeWindows.threeHours:
timeDifferenceMinutes = 60 * 3; return 60 * 3;
break;
case timeWindows.eightHours: case timeWindows.eightHours:
timeDifferenceMinutes = 60 * 8; return 60 * 8;
break;
case timeWindows.oneDay: case timeWindows.oneDay:
timeDifferenceMinutes = 60 * 24 * 1; return 60 * 24 * 1;
break;
case timeWindows.threeDays: case timeWindows.threeDays:
timeDifferenceMinutes = 60 * 24 * 3; return 60 * 24 * 3;
break;
case timeWindows.oneWeek: case timeWindows.oneWeek:
timeDifferenceMinutes = 60 * 24 * 7 * 1; return 60 * 24 * 7 * 1;
break;
default: default:
timeDifferenceMinutes = 60 * 8; return 60 * 8;
break;
} }
};
export const getTimeDiff = selectedTimeWindow => {
const end = Date.now();
const timeDifferenceMinutes = getTimeDifferenceMinutes(selectedTimeWindow);
const start = new Date(end - timeDifferenceMinutes * msPerMinute).getTime();
return timeDifferenceMinutes; return { start, end };
}; };
export default {}; export default {};
...@@ -238,6 +238,9 @@ msgid_plural "%d closed merge requests" ...@@ -238,6 +238,9 @@ msgid_plural "%d closed merge requests"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
msgid "1 day"
msgstr ""
msgid "1 merged merge request" msgid "1 merged merge request"
msgid_plural "%d merged merge requests" msgid_plural "%d merged merge requests"
msgstr[0] "" msgstr[0] ""
...@@ -258,6 +261,9 @@ msgid_plural "%d pipelines" ...@@ -258,6 +261,9 @@ msgid_plural "%d pipelines"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
msgid "1 week"
msgstr ""
msgid "1st contribution!" msgid "1st contribution!"
msgstr "" msgstr ""
...@@ -267,6 +273,15 @@ msgstr "" ...@@ -267,6 +273,15 @@ msgstr ""
msgid "2FA enabled" msgid "2FA enabled"
msgstr "" msgstr ""
msgid "3 days"
msgstr ""
msgid "3 hours"
msgstr ""
msgid "30 minutes"
msgstr ""
msgid "403|Please contact your GitLab administrator to get permission." msgid "403|Please contact your GitLab administrator to get permission."
msgstr "" msgstr ""
...@@ -282,6 +297,9 @@ msgstr "" ...@@ -282,6 +297,9 @@ msgstr ""
msgid "404|Please contact your GitLab administrator if you think this is a mistake." msgid "404|Please contact your GitLab administrator if you think this is a mistake."
msgstr "" msgstr ""
msgid "8 hours"
msgstr ""
msgid "<code>\"johnsmith@example.com\": \"@johnsmith\"</code> will add \"By <a href=\"#\">@johnsmith</a>\" to all issues and comments originally created by johnsmith@example.com, and will set <a href=\"#\">@johnsmith</a> as the assignee on all issues originally assigned to johnsmith@example.com." msgid "<code>\"johnsmith@example.com\": \"@johnsmith\"</code> will add \"By <a href=\"#\">@johnsmith</a>\" to all issues and comments originally created by johnsmith@example.com, and will set <a href=\"#\">@johnsmith</a> as the assignee on all issues originally assigned to johnsmith@example.com."
msgstr "" msgstr ""
...@@ -5100,7 +5118,10 @@ msgstr "" ...@@ -5100,7 +5118,10 @@ msgstr ""
msgid "Metrics|No deployed environments" msgid "Metrics|No deployed environments"
msgstr "" msgstr ""
msgid "Metrics|Show Last" msgid "Metrics|Not enough data to display"
msgstr ""
msgid "Metrics|Show last"
msgstr "" msgstr ""
msgid "Metrics|There was an error fetching the environments data, please try again" msgid "Metrics|There was an error fetching the environments data, please try again"
......
...@@ -184,7 +184,23 @@ describe('Dashboard', () => { ...@@ -184,7 +184,23 @@ describe('Dashboard', () => {
}); });
}); });
it('renders the time window dropdown with a set of options ', done => { it('renders the time window dropdown with a set of options', done => {
gon.features.metricsTimeWindow = false;
const component = new DashboardComponent({
el: document.querySelector('.prometheus-graphs'),
propsData: { ...propsData, hasMetrics: true, showPanels: false },
});
setTimeout(() => {
const timeWindowDropdown = component.$el.querySelector('.js-time-window-dropdown');
expect(timeWindowDropdown).toBeNull();
done();
});
});
it('does not show the time window dropdown when the feature flag is not set', done => {
const component = new DashboardComponent({ const component = new DashboardComponent({
el: document.querySelector('.prometheus-graphs'), el: document.querySelector('.prometheus-graphs'),
propsData: { ...propsData, hasMetrics: true, showPanels: false }, propsData: { ...propsData, hasMetrics: true, showPanels: false },
......
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