Welcome to mirror list, hosted at ThFree Co, Russian Federation.

store_utils.js « monitoring « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 96219661b9b3547c71547b3036fbf8e5fe0bd433 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import * as types from '~/monitoring/stores/mutation_types';
import { metricsDashboardPayload } from './fixture_data';
import { metricsResult, environmentData, dashboardGitResponse } from './mock_data';

export const setMetricResult = ({ store, result, group = 0, panel = 0, metric = 0 }) => {
  const { dashboard } = store.state.monitoringDashboard;
  const { metricId } = dashboard.panelGroups[group].panels[panel].metrics[metric];

  store.commit(`monitoringDashboard/${types.RECEIVE_METRIC_RESULT_SUCCESS}`, {
    metricId,
    data: {
      resultType: 'matrix',
      result,
    },
  });
};

const setEnvironmentData = (store) => {
  store.commit(`monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`, environmentData);
};

export const setupAllDashboards = (store, path) => {
  store.commit(`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, dashboardGitResponse);
  if (path) {
    store.commit(`monitoringDashboard/${types.SET_INITIAL_STATE}`, {
      currentDashboard: path,
    });
  }
};

export const setupStoreWithDashboard = (store) => {
  store.commit(
    `monitoringDashboard/${types.RECEIVE_METRICS_DASHBOARD_SUCCESS}`,
    metricsDashboardPayload,
  );
};

export const setupStoreWithLinks = (store) => {
  store.commit(`monitoringDashboard/${types.RECEIVE_METRICS_DASHBOARD_SUCCESS}`, {
    ...metricsDashboardPayload,
    links: [
      {
        title: 'GitLab Website',
        url: `https://gitlab.com/website`,
      },
    ],
  });
};

export const setupStoreWithData = (store) => {
  setupAllDashboards(store);
  setupStoreWithDashboard(store);

  setMetricResult({ store, result: [], panel: 0 });
  setMetricResult({ store, result: metricsResult, panel: 1 });
  setMetricResult({ store, result: metricsResult, panel: 2 });

  setEnvironmentData(store);
};

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 });
};