diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 15:07:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 15:07:48 +0300 |
commit | 5a6b36b60502c50ab59c0bc3c345793b70a3d548 (patch) | |
tree | 7cf2effbd48359b44970f8f345cfa12ce6843dfd /app/assets/javascripts/clusters_list | |
parent | a76d34e6716aa8267111ecdcd21416e9dec3a08d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/clusters_list')
-rw-r--r-- | app/assets/javascripts/clusters_list/store/actions.js | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/app/assets/javascripts/clusters_list/store/actions.js b/app/assets/javascripts/clusters_list/store/actions.js index 39fd9fdf625..79bc9932438 100644 --- a/app/assets/javascripts/clusters_list/store/actions.js +++ b/app/assets/javascripts/clusters_list/store/actions.js @@ -1,17 +1,36 @@ 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 }) => { - return axios - .get(state.endpoint) - .then(({ data }) => { + 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); - }) - .catch(() => flash(__('An error occurred while loading clusters'))); + }, + 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 |