diff options
Diffstat (limited to 'app/assets/javascripts/notes/stores/actions.js')
-rw-r--r-- | app/assets/javascripts/notes/stores/actions.js | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/app/assets/javascripts/notes/stores/actions.js b/app/assets/javascripts/notes/stores/actions.js index 7eb10f647a0..c862a29ad9c 100644 --- a/app/assets/javascripts/notes/stores/actions.js +++ b/app/assets/javascripts/notes/stores/actions.js @@ -1,4 +1,3 @@ -/* eslint-disable @gitlab/require-string-literal-i18n-helpers */ import $ from 'jquery'; import Visibility from 'visibilityjs'; import Vue from 'vue'; @@ -71,7 +70,7 @@ export const setUserData = ({ commit }, data) => commit(types.SET_USER_DATA, dat export const setLastFetchedAt = ({ commit }, data) => commit(types.SET_LAST_FETCHED_AT, data); export const setInitialNotes = ({ commit }, discussions) => - commit(types.SET_INITIAL_DISCUSSIONS, discussions); + commit(types.ADD_OR_UPDATE_DISCUSSIONS, discussions); export const setTargetNoteHash = ({ commit }, data) => commit(types.SET_TARGET_NOTE_HASH, data); @@ -90,14 +89,51 @@ export const fetchDiscussions = ({ commit, dispatch }, { path, filter, persistFi ? { params: { notes_filter: filter, persist_filter: persistFilter } } : null; + if (window.gon?.features?.paginatedIssueDiscussions) { + return dispatch('fetchDiscussionsBatch', { path, config, perPage: 20 }); + } + return axios.get(path, config).then(({ data }) => { - commit(types.SET_INITIAL_DISCUSSIONS, data); + commit(types.ADD_OR_UPDATE_DISCUSSIONS, data); commit(types.SET_FETCHING_DISCUSSIONS, false); dispatch('updateResolvableDiscussionsCounts'); }); }; +export const fetchDiscussionsBatch = ({ commit, dispatch }, { path, config, cursor, perPage }) => { + const params = { ...config?.params, per_page: perPage }; + + if (cursor) { + params.cursor = cursor; + } + + return axios.get(path, { params }).then(({ data, headers }) => { + commit(types.ADD_OR_UPDATE_DISCUSSIONS, data); + + if (headers['x-next-page-cursor']) { + const nextConfig = { ...config }; + + if (config?.params?.persist_filter) { + delete nextConfig.params.notes_filter; + delete nextConfig.params.persist_filter; + } + + return dispatch('fetchDiscussionsBatch', { + path, + config: nextConfig, + cursor: headers['x-next-page-cursor'], + perPage: Math.min(Math.round(perPage * 1.5), 100), + }); + } + + commit(types.SET_FETCHING_DISCUSSIONS, false); + dispatch('updateResolvableDiscussionsCounts'); + + return undefined; + }); +}; + export const updateDiscussion = ({ commit, state }, discussion) => { commit(types.UPDATE_DISCUSSION, discussion); @@ -621,7 +657,7 @@ export const submitSuggestion = ( const flashMessage = errorMessage || defaultMessage; createFlash({ - message: __(flashMessage), + message: flashMessage, parent: flashContainer, }); }) @@ -657,7 +693,7 @@ export const submitSuggestionBatch = ({ commit, dispatch, state }, { message, fl const flashMessage = errorMessage || defaultMessage; createFlash({ - message: __(flashMessage), + message: flashMessage, parent: flashContainer, }); }) |