diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-30 18:09:00 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-30 18:09:00 +0300 |
commit | f4199ade274d43b2627d17d9087f42d0f8175369 (patch) | |
tree | f8b2311aeae6d4eeed80ee2db7eb8b06e5f7cba8 /app/assets/javascripts/search | |
parent | e672c333df6dc238e5050ab5eb709d6df5c87380 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/search')
-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); } }; |