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

actions.js « store « clusters_list « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 79bc9932438d90d37d4d6371620123054a5f2232 (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
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import Poll from '~/lib/utils/poll';
import axios from '~/lib/utils/axios_utils';
import Visibility from 'visibilityjs';
import flash from '~/flash';
import { __ } from '~/locale';
import * as types from './mutation_types';

export const fetchClusters = ({ state, commit }) => {
  const poll = new Poll({
    resource: {
      fetchClusters: endpoint => axios.get(endpoint),
    },
    data: state.endpoint,
    method: 'fetchClusters',
    successCallback: ({ data }) => {
      commit(types.SET_CLUSTERS_DATA, convertObjectPropsToCamelCase(data, { deep: true }));
      commit(types.SET_LOADING_STATE, false);
    },
    errorCallback: () => flash(__('An error occurred while loading clusters')),
  });

  if (!Visibility.hidden()) {
    poll.makeRequest();
  }

  Visibility.change(() => {
    if (!Visibility.hidden()) {
      poll.restart();
    } else {
      poll.stop();
    }
  });
};

// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};