From 6d3a87e27221587656aa264dc5f530905d8b1894 Mon Sep 17 00:00:00 2001 From: "anton.buksa" Date: Thu, 3 Oct 2024 10:48:52 +0200 Subject: [PATCH] restore custom pagination in get all groups call Changelog: changed --- .../mattermost-redux/src/actions/groups.ts | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/groups.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/groups.ts index 7992db22f5..ce09b4c107 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/groups.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/groups.ts @@ -158,17 +158,42 @@ export function getGroup(id: string, includeMemberCount = false) { }); } -export function getGroups(opts: GetGroupsParams) { - return bindClientFunc({ - clientFunc: async (opts) => { - const result = await Client4.getGroups(opts); - return result; - }, - onSuccess: [GroupTypes.RECEIVED_GROUPS], - params: [ - opts, - ], - }); +export function getGroups(opts: GetGroupsParams): ActionFuncAsync { + // return bindClientFunc({ + // clientFunc: async (opts) => { + // const result = await Client4.getGroups(opts); + // return result; + // }, + // onSuccess: [GroupTypes.RECEIVED_GROUPS], + // params: [ + // opts, + // ], + // }); + // Infomaniak custom with pagination + return async (dispatch) => { + let groups: Group[] = []; + let currentFetch: Group[] = []; + + try { + // eslint-disable-next-line no-constant-condition + while (true) { + // eslint-disable-next-line no-await-in-loop + currentFetch = await Client4.getGroups(opts); + groups = groups.concat(currentFetch); + if (!opts.per_page || currentFetch.length < opts.per_page) { + break; + } + opts.page += 1; + } + dispatch({ + type: GroupTypes.RECEIVED_GROUPS, + data: groups, + }); + } catch (error) { + dispatch(logError(error)); + } + return {data: groups}; + }; } export function getGroupsNotAssociatedToTeam(teamID: string, q = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT, source = GroupSource.Ldap) {