diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /app/assets/javascripts/search/store/actions.js | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'app/assets/javascripts/search/store/actions.js')
-rw-r--r-- | app/assets/javascripts/search/store/actions.js | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/app/assets/javascripts/search/store/actions.js b/app/assets/javascripts/search/store/actions.js index a6af5644681..40513a7f363 100644 --- a/app/assets/javascripts/search/store/actions.js +++ b/app/assets/javascripts/search/store/actions.js @@ -18,31 +18,35 @@ export const fetchGroups = ({ commit }, search) => { }); }; -export const fetchProjects = ({ commit, state }, search) => { +export const fetchProjects = ({ commit, state }, search, emptyCallback = () => {}) => { commit(types.REQUEST_PROJECTS); const groupId = state.query?.group_id; - const callback = (data) => { - if (data) { - commit(types.RECEIVE_PROJECTS_SUCCESS, data); - } else { - createFlash({ message: __('There was an error fetching projects') }); - commit(types.RECEIVE_PROJECTS_ERROR); - } + + const handleCatch = () => { + createFlash({ message: __('There was an error fetching projects') }); + commit(types.RECEIVE_PROJECTS_ERROR); + }; + const handleSuccess = ({ data }) => { + commit(types.RECEIVE_PROJECTS_SUCCESS, data); }; if (groupId) { - // TODO (https://gitlab.com/gitlab-org/gitlab/-/issues/323331): For errors `createFlash` is called twice; in `callback` and in `Api.groupProjects` Api.groupProjects( groupId, search, - { order_by: 'similarity', with_shared: false, include_subgroups: true }, - callback, - ); + { + order_by: 'similarity', + with_shared: false, + include_subgroups: true, + }, + emptyCallback, + true, + ) + .then(handleSuccess) + .catch(handleCatch); } else { // The .catch() is due to the API method not handling a rejection properly - Api.projects(search, { order_by: 'similarity' }, callback).catch(() => { - callback(); - }); + Api.projects(search, { order_by: 'similarity' }).then(handleSuccess).catch(handleCatch); } }; |