debian-mirror-gitlab/spec/frontend/monitoring/store_utils.js

81 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-04-22 19:07:51 +05:30
import * as types from '~/monitoring/stores/mutation_types';
import { metricsDashboardPayload } from './fixture_data';
2021-03-11 19:13:27 +05:30
import { metricsResult, environmentData, dashboardGitResponse } from './mock_data';
2020-04-22 19:07:51 +05:30
2020-05-24 23:13:21 +05:30
export const setMetricResult = ({ store, result, group = 0, panel = 0, metric = 0 }) => {
const { dashboard } = store.state.monitoringDashboard;
2020-04-22 19:07:51 +05:30
const { metricId } = dashboard.panelGroups[group].panels[panel].metrics[metric];
2020-05-24 23:13:21 +05:30
store.commit(`monitoringDashboard/${types.RECEIVE_METRIC_RESULT_SUCCESS}`, {
2020-04-22 19:07:51 +05:30
metricId,
2020-07-28 23:09:34 +05:30
data: {
resultType: 'matrix',
result,
},
2020-04-22 19:07:51 +05:30
});
};
2021-03-08 18:12:59 +05:30
const setEnvironmentData = (store) => {
2020-05-24 23:13:21 +05:30
store.commit(`monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`, environmentData);
2020-04-22 19:07:51 +05:30
};
2020-06-23 00:09:42 +05:30
export const setupAllDashboards = (store, path) => {
2020-05-24 23:13:21 +05:30
store.commit(`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, dashboardGitResponse);
2020-06-23 00:09:42 +05:30
if (path) {
store.commit(`monitoringDashboard/${types.SET_INITIAL_STATE}`, {
currentDashboard: path,
});
}
2020-05-24 23:13:21 +05:30
};
2021-03-08 18:12:59 +05:30
export const setupStoreWithDashboard = (store) => {
2020-05-24 23:13:21 +05:30
store.commit(
`monitoringDashboard/${types.RECEIVE_METRICS_DASHBOARD_SUCCESS}`,
metricsDashboardPayload,
);
2020-04-22 19:07:51 +05:30
};
2021-03-08 18:12:59 +05:30
export const setupStoreWithLinks = (store) => {
2020-06-23 00:09:42 +05:30
store.commit(`monitoringDashboard/${types.RECEIVE_METRICS_DASHBOARD_SUCCESS}`, {
...metricsDashboardPayload,
links: [
{
title: 'GitLab Website',
url: `https://gitlab.com/website`,
},
],
});
};
2021-03-08 18:12:59 +05:30
export const setupStoreWithData = (store) => {
2020-05-24 23:13:21 +05:30
setupAllDashboards(store);
setupStoreWithDashboard(store);
2020-04-22 19:07:51 +05:30
2020-05-24 23:13:21 +05:30
setMetricResult({ store, result: [], panel: 0 });
setMetricResult({ store, result: metricsResult, panel: 1 });
setMetricResult({ store, result: metricsResult, panel: 2 });
2020-04-22 19:07:51 +05:30
2020-05-24 23:13:21 +05:30
setEnvironmentData(store);
2020-04-22 19:07:51 +05:30
};
2020-07-28 23:09:34 +05:30
export const setupStoreWithDataForPanelCount = (store, panelCount) => {
const payloadPanelGroup = metricsDashboardPayload.panel_groups[0];
const panelGroupCustom = {
...payloadPanelGroup,
panels: payloadPanelGroup.panels.slice(0, panelCount),
};
const metricsDashboardPayloadCustom = {
...metricsDashboardPayload,
panel_groups: [panelGroupCustom],
};
store.commit(
`monitoringDashboard/${types.RECEIVE_METRICS_DASHBOARD_SUCCESS}`,
metricsDashboardPayloadCustom,
);
setMetricResult({ store, result: metricsResult, panel: 0 });
};