Commit d6562639 authored by Dhiraj Bodicherla's avatar Dhiraj Bodicherla

Add retry to metrics panel preview page

This page adds a refresh icon in the panel preview
page in the metrics dashboard
parent cc82a103
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
GlButton, GlButton,
GlSprintf, GlSprintf,
GlAlert, GlAlert,
GlTooltipDirective,
} from '@gitlab/ui'; } from '@gitlab/ui';
import DateTimePicker from '~/vue_shared/components/date_time_picker/date_time_picker.vue'; import DateTimePicker from '~/vue_shared/components/date_time_picker/date_time_picker.vue';
import { timeRanges } from '~/vue_shared/constants'; import { timeRanges } from '~/vue_shared/constants';
...@@ -34,6 +35,9 @@ export default { ...@@ -34,6 +35,9 @@ export default {
DashboardPanel, DashboardPanel,
DateTimePicker, DateTimePicker,
}, },
directives: {
GlTooltip: GlTooltipDirective,
},
data() { data() {
return { return {
yml: initialYml, yml: initialYml,
...@@ -67,6 +71,13 @@ export default { ...@@ -67,6 +71,13 @@ export default {
this.fetchPanelPreviewMetrics(); this.fetchPanelPreviewMetrics();
} }
}, },
onRefresh() {
// refetch data only if preview has been clicked
// and there are no errors
if (this.panelPreviewIsShown && !this.panelPreviewError) {
this.fetchPanelPreviewMetrics();
}
},
}, },
timeRanges, timeRanges,
}; };
...@@ -171,11 +182,18 @@ export default { ...@@ -171,11 +182,18 @@ export default {
</gl-alert> </gl-alert>
<date-time-picker <date-time-picker
ref="dateTimePicker" ref="dateTimePicker"
class="gl-flex-grow-1 preview-date-time-picker" class="gl-flex-grow-1 preview-date-time-picker gl-xs-mb-3"
:value="panelPreviewTimeRange" :value="panelPreviewTimeRange"
:options="$options.timeRanges" :options="$options.timeRanges"
@input="onDateTimePickerInput" @input="onDateTimePickerInput"
/> />
<gl-button
v-gl-tooltip
data-testid="previewRefreshButton"
icon="retry"
:title="s__('Metrics|Refresh Prometheus data')"
@click="onRefresh"
/>
<dashboard-panel :graph-data="panelPreviewGraphData" /> <dashboard-panel :graph-data="panelPreviewGraphData" />
</div> </div>
</template> </template>
...@@ -15346,6 +15346,9 @@ msgstr "" ...@@ -15346,6 +15346,9 @@ msgstr ""
msgid "Metrics|Prometheus Query Documentation" msgid "Metrics|Prometheus Query Documentation"
msgstr "" msgstr ""
msgid "Metrics|Refresh Prometheus data"
msgstr ""
msgid "Metrics|Refresh dashboard" msgid "Metrics|Refresh dashboard"
msgstr "" msgstr ""
......
...@@ -40,6 +40,7 @@ describe('dashboard invalid url parameters', () => { ...@@ -40,6 +40,7 @@ describe('dashboard invalid url parameters', () => {
const findOpenRepositoryBtn = () => wrapper.find({ ref: 'openRepositoryBtn' }); const findOpenRepositoryBtn = () => wrapper.find({ ref: 'openRepositoryBtn' });
const findPanel = () => wrapper.find(DashboardPanel); const findPanel = () => wrapper.find(DashboardPanel);
const findTimeRangePicker = () => wrapper.find(DateTimePicker); const findTimeRangePicker = () => wrapper.find(DateTimePicker);
const findRefreshButton = () => wrapper.find('[data-testid="previewRefreshButton"]');
beforeEach(() => { beforeEach(() => {
mockShowToast = jest.fn(); mockShowToast = jest.fn();
...@@ -138,6 +139,35 @@ describe('dashboard invalid url parameters', () => { ...@@ -138,6 +139,35 @@ describe('dashboard invalid url parameters', () => {
}); });
}); });
describe('refresh', () => {
it('is visible by default', () => {
expect(findRefreshButton().exists()).toBe(true);
});
it('when clicked does not trigger data fetch unless preview panel button is clicked', () => {
// mimic initial state where SET_PANEL_PREVIEW_IS_SHOWN is set to false
store.commit(`monitoringDashboard/${types.SET_PANEL_PREVIEW_IS_SHOWN}`, false);
return wrapper.vm.$nextTick(() => {
expect(store.dispatch).not.toHaveBeenCalled();
});
});
it('when clicked triggers data fetch if preview panel button is clicked', () => {
// mimic state where preview is visible. SET_PANEL_PREVIEW_IS_SHOWN is set to true
store.commit(`monitoringDashboard/${types.SET_PANEL_PREVIEW_IS_SHOWN}`, true);
findRefreshButton().vm.$emit('click');
return wrapper.vm.$nextTick(() => {
expect(store.dispatch).toHaveBeenCalledWith(
'monitoringDashboard/fetchPanelPreviewMetrics',
undefined,
);
});
});
});
describe('instructions card', () => { describe('instructions card', () => {
const mockDocsPath = '/docs-path'; const mockDocsPath = '/docs-path';
const mockProjectPath = '/project-path'; const mockProjectPath = '/project-path';
......
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