diff --git a/packages/manager/apps/zimbra/src/api/account/api.ts b/packages/manager/apps/zimbra/src/api/account/api.ts index a09e47dfcbd3..63a249a7018a 100644 --- a/packages/manager/apps/zimbra/src/api/account/api.ts +++ b/packages/manager/apps/zimbra/src/api/account/api.ts @@ -1,6 +1,7 @@ import { fetchIcebergV2, v2 } from '@ovh-ux/manager-core-api'; import { AccountBodyParamsType, AccountType } from './type'; import { getApiPath } from '../utils/apiPath'; +import { APIV2_DEFAULT_PAGESIZE } from '@/utils'; // GET @@ -8,6 +9,7 @@ export const getZimbraPlatformAccounts = ({ platformId, queryParameters, pageParam, + pageSize = APIV2_DEFAULT_PAGESIZE, }: { platformId: string; queryParameters?: { @@ -15,12 +17,13 @@ export const getZimbraPlatformAccounts = ({ domainId?: string; }; pageParam?: unknown; + pageSize?: number; }) => { const params = new URLSearchParams(queryParameters).toString(); const queryString = params ? `?${params}` : ''; return fetchIcebergV2({ route: `${getApiPath(platformId)}account${queryString}`, - pageSize: 25, + pageSize, cursor: pageParam as string, }); }; diff --git a/packages/manager/apps/zimbra/src/api/account/key.ts b/packages/manager/apps/zimbra/src/api/account/key.ts index 6ed247efc4e4..f7d9eb62896d 100644 --- a/packages/manager/apps/zimbra/src/api/account/key.ts +++ b/packages/manager/apps/zimbra/src/api/account/key.ts @@ -4,13 +4,21 @@ export const getZimbraPlatformAccountsQueryKey = ( organizationId?: string; domainId?: string; }, + shouldFetchAll?: boolean, ) => { const params = new URLSearchParams(queryParameters).toString(); const queryString = params ? `?${params}` : ''; - return [`get/zimbra/platform/${platformId}/account${queryString}`]; + return [ + 'get', + 'account', + 'zimbra', + platformId, + queryString, + shouldFetchAll ? 'all' : '', + ].filter(Boolean); }; export const getZimbraPlatformAccountDetailQueryKey = ( platformId: string, accountId?: string, -) => [`get/zimbra/platform/${platformId}/account/${accountId}`]; +) => ['get', 'account', 'zimbra', platformId, accountId]; diff --git a/packages/manager/apps/zimbra/src/api/domain/api.ts b/packages/manager/apps/zimbra/src/api/domain/api.ts index 16d53c529ad7..5a6809ca0108 100644 --- a/packages/manager/apps/zimbra/src/api/domain/api.ts +++ b/packages/manager/apps/zimbra/src/api/domain/api.ts @@ -1,6 +1,7 @@ import { fetchIcebergV2, v2, v6 } from '@ovh-ux/manager-core-api'; import { DomainBodyParamsType, DomainType } from './type'; import { getApiPath } from '../utils/apiPath'; +import { APIV2_DEFAULT_PAGESIZE } from '@/utils'; // GET @@ -8,16 +9,18 @@ export const getZimbraPlatformDomains = ({ platformId, organizationId, pageParam, + pageSize = APIV2_DEFAULT_PAGESIZE, }: { platformId: string; organizationId?: string; pageParam?: unknown; + pageSize?: number; }) => fetchIcebergV2({ route: `${getApiPath(platformId)}domain${ organizationId ? `?organizationId=${organizationId}` : '' }`, - pageSize: 25, + pageSize, cursor: pageParam as string, }); diff --git a/packages/manager/apps/zimbra/src/api/domain/key.ts b/packages/manager/apps/zimbra/src/api/domain/key.ts index 71a1bb986312..2024ac37c3ff 100644 --- a/packages/manager/apps/zimbra/src/api/domain/key.ts +++ b/packages/manager/apps/zimbra/src/api/domain/key.ts @@ -1,13 +1,20 @@ export const getZimbraPlatformDomainsQueryKey = ( platformId: string, organizationId?: string, -) => [ - `get/zimbra/platform/${platformId}/domain?organizationId=${organizationId}`, -]; + shouldFetchAll?: boolean, +) => + [ + 'get', + 'zimbra', + 'domain', + platformId, + shouldFetchAll ? 'all' : '', + organizationId, + ].filter(Boolean); export const getZimbraPlatformDomainQueryKey = ( platformId: string, domainId: string, -) => [`get/zimbra/platform/${platformId}/domain/${domainId}`]; +) => ['get', 'domain', 'zimbra', platformId, domainId]; -export const getDomainsZoneListQueryKey = ['get/domain/zone']; +export const getDomainsZoneListQueryKey = ['get', 'domain', 'zone']; diff --git a/packages/manager/apps/zimbra/src/api/organization/api.ts b/packages/manager/apps/zimbra/src/api/organization/api.ts index 8226a725a97c..74f91aabac6d 100644 --- a/packages/manager/apps/zimbra/src/api/organization/api.ts +++ b/packages/manager/apps/zimbra/src/api/organization/api.ts @@ -1,19 +1,22 @@ import { fetchIcebergV2, v2 } from '@ovh-ux/manager-core-api'; import { OrganizationBodyParamsType, OrganizationType } from './type'; import { getApiPath } from '../utils/apiPath'; +import { APIV2_DEFAULT_PAGESIZE } from '@/utils'; // GET export const getZimbraPlatformOrganization = ({ platformId, pageParam, + pageSize = APIV2_DEFAULT_PAGESIZE, }: { platformId: string; pageParam?: unknown; + pageSize?: number; }) => fetchIcebergV2({ route: `${getApiPath(platformId)}organization`, - pageSize: 25, + pageSize, cursor: pageParam as string, }); diff --git a/packages/manager/apps/zimbra/src/api/organization/key.ts b/packages/manager/apps/zimbra/src/api/organization/key.ts index 46bc996b65e9..f80b68c6b244 100644 --- a/packages/manager/apps/zimbra/src/api/organization/key.ts +++ b/packages/manager/apps/zimbra/src/api/organization/key.ts @@ -1,8 +1,16 @@ -export const getZimbraPlatformOrganizationQueryKey = (platformId: string) => [ - `get/zimbra/platform/${platformId}/organization`, -]; +export const getZimbraPlatformOrganizationQueryKey = ( + platformId: string, + shouldFetchAll?: boolean, +) => + [ + 'get', + 'organization', + 'zimbra', + platformId, + shouldFetchAll ? 'all' : '', + ].filter(Boolean); export const getZimbraPlatformOrganizationDetailsQueryKey = ( platformId: string, organizationId: string, -) => [`get/zimbra/platform/${platformId}/organization/${organizationId}`]; +) => ['get', 'organization', 'zimbra', platformId, organizationId]; diff --git a/packages/manager/apps/zimbra/src/hooks/useAccountList.ts b/packages/manager/apps/zimbra/src/hooks/useAccountList.ts index 67d9f48abd3e..4e223eb32b3b 100644 --- a/packages/manager/apps/zimbra/src/hooks/useAccountList.ts +++ b/packages/manager/apps/zimbra/src/hooks/useAccountList.ts @@ -4,12 +4,14 @@ import { UseInfiniteQueryResult, } from '@tanstack/react-query'; import { useSearchParams } from 'react-router-dom'; +import { useEffect } from 'react'; import { usePlatform } from '@/hooks'; import { AccountType, getZimbraPlatformAccounts, getZimbraPlatformAccountsQueryKey, } from '@/api/account'; +import { APIV2_MAX_PAGESIZE } from '@/utils'; type UseAccountListParams = Omit< UseInfiniteQueryOptions, @@ -17,10 +19,11 @@ type UseAccountListParams = Omit< > & { domainId?: string; organizationId?: string; + shouldFetchAll?: boolean; }; export const useAccountList = (props: UseAccountListParams = {}) => { - const { domainId, organizationId, ...options } = props; + const { domainId, organizationId, shouldFetchAll, ...options } = props; const { platformId } = usePlatform(); const [searchParams] = useSearchParams(); @@ -33,19 +36,24 @@ export const useAccountList = (props: UseAccountListParams = {}) => { ...(selectedDomainId && { domainId: selectedDomainId }), }; - return useInfiniteQuery({ + const query = useInfiniteQuery({ ...options, initialPageParam: null, - queryKey: getZimbraPlatformAccountsQueryKey(platformId, queryParameters), + queryKey: getZimbraPlatformAccountsQueryKey( + platformId, + queryParameters, + shouldFetchAll, + ), queryFn: ({ pageParam }) => getZimbraPlatformAccounts({ platformId, queryParameters, pageParam, + ...(shouldFetchAll ? { pageSize: APIV2_MAX_PAGESIZE } : {}), }), - enabled: (query) => + enabled: (q) => (typeof options.enabled === 'function' - ? options.enabled(query) + ? options.enabled(q) : typeof options.enabled !== 'boolean' || options.enabled) && !!platformId, getNextPageParam: (lastPage: { cursorNext?: string }) => @@ -55,4 +63,12 @@ export const useAccountList = (props: UseAccountListParams = {}) => { (page: UseInfiniteQueryResult) => page.data, ), }); + + useEffect(() => { + if (shouldFetchAll && query.hasNextPage) { + query.fetchNextPage(); + } + }, [query.data]); + + return query; }; diff --git a/packages/manager/apps/zimbra/src/hooks/useDomains.ts b/packages/manager/apps/zimbra/src/hooks/useDomains.ts index 19c1baeae08c..c0bda326d232 100644 --- a/packages/manager/apps/zimbra/src/hooks/useDomains.ts +++ b/packages/manager/apps/zimbra/src/hooks/useDomains.ts @@ -3,6 +3,7 @@ import { UseInfiniteQueryOptions, UseInfiniteQueryResult, } from '@tanstack/react-query'; +import { useEffect } from 'react'; import { usePlatform, useOrganization } from '@/hooks'; import { @@ -10,36 +11,40 @@ import { getZimbraPlatformDomains, getZimbraPlatformDomainsQueryKey, } from '@/api/domain'; +import { APIV2_MAX_PAGESIZE } from '@/utils'; type UseDomainsParams = Omit< UseInfiniteQueryOptions, 'queryKey' | 'queryFn' | 'select' | 'getNextPageParam' | 'initialPageParam' > & { organizationId?: string; + shouldFetchAll?: boolean; }; export const useDomains = (props: UseDomainsParams = {}) => { - const { organizationId, ...options } = props; + const { organizationId, shouldFetchAll, ...options } = props; const { platformId } = usePlatform(); const { data: organization } = useOrganization(); const selectedOrganizationId = organization?.id; - return useInfiniteQuery({ + const query = useInfiniteQuery({ ...options, initialPageParam: null, queryKey: getZimbraPlatformDomainsQueryKey( platformId, organizationId || selectedOrganizationId, + shouldFetchAll, ), queryFn: ({ pageParam }) => getZimbraPlatformDomains({ platformId, organizationId: organizationId || selectedOrganizationId, pageParam, + ...(shouldFetchAll ? { pageSize: APIV2_MAX_PAGESIZE } : {}), }), - enabled: (query) => + enabled: (q) => (typeof options.enabled === 'function' - ? options.enabled(query) + ? options.enabled(q) : typeof options.enabled !== 'boolean' || options.enabled) && !!platformId, getNextPageParam: (lastPage: { cursorNext?: string }) => @@ -49,4 +54,12 @@ export const useDomains = (props: UseDomainsParams = {}) => { (page: UseInfiniteQueryResult) => page.data, ), }); + + useEffect(() => { + if (shouldFetchAll && query.hasNextPage) { + query.fetchNextPage(); + } + }, [query.data]); + + return query; }; diff --git a/packages/manager/apps/zimbra/src/hooks/useOrganizationsList.ts b/packages/manager/apps/zimbra/src/hooks/useOrganizationsList.ts index 7b8858cf9734..26a75e20f1a6 100644 --- a/packages/manager/apps/zimbra/src/hooks/useOrganizationsList.ts +++ b/packages/manager/apps/zimbra/src/hooks/useOrganizationsList.ts @@ -3,30 +3,39 @@ import { UseInfiniteQueryOptions, UseInfiniteQueryResult, } from '@tanstack/react-query'; +import { useEffect } from 'react'; import { usePlatform } from '@/hooks'; import { getZimbraPlatformOrganization, getZimbraPlatformOrganizationQueryKey, OrganizationType, } from '@/api/organization'; +import { APIV2_MAX_PAGESIZE } from '@/utils'; -export const useOrganizationList = ( - options: Omit< - UseInfiniteQueryOptions, - 'queryKey' | 'queryFn' | 'select' | 'getNextPageParam' | 'initialPageParam' - > = {}, -) => { +type UseOrganizationListParams = Omit< + UseInfiniteQueryOptions, + 'queryKey' | 'queryFn' | 'select' | 'getNextPageParam' | 'initialPageParam' +> & { + shouldFetchAll?: boolean; +}; + +export const useOrganizationList = (props: UseOrganizationListParams = {}) => { + const { shouldFetchAll, ...options } = props; const { platformId } = usePlatform(); - return useInfiniteQuery({ + const query = useInfiniteQuery({ ...options, initialPageParam: null, - queryKey: getZimbraPlatformOrganizationQueryKey(platformId), + queryKey: getZimbraPlatformOrganizationQueryKey(platformId, shouldFetchAll), queryFn: ({ pageParam }) => - getZimbraPlatformOrganization({ platformId, pageParam }), - enabled: (query) => + getZimbraPlatformOrganization({ + platformId, + pageParam, + ...(shouldFetchAll ? { pageSize: APIV2_MAX_PAGESIZE } : {}), + }), + enabled: (q) => (typeof options.enabled === 'function' - ? options.enabled(query) + ? options.enabled(q) : typeof options.enabled !== 'boolean' || options.enabled) && !!platformId, getNextPageParam: (lastPage: { cursorNext?: string }) => @@ -36,4 +45,12 @@ export const useOrganizationList = ( (page: UseInfiniteQueryResult) => page.data, ), }); + + useEffect(() => { + if (shouldFetchAll && query.hasNextPage) { + query.fetchNextPage(); + } + }, [query.data]); + + return query; }; diff --git a/packages/manager/apps/zimbra/src/pages/dashboard/AutoReplies/AddAutoReply.page.tsx b/packages/manager/apps/zimbra/src/pages/dashboard/AutoReplies/AddAutoReply.page.tsx index 8ffdfbee8cfb..01be146a6938 100644 --- a/packages/manager/apps/zimbra/src/pages/dashboard/AutoReplies/AddAutoReply.page.tsx +++ b/packages/manager/apps/zimbra/src/pages/dashboard/AutoReplies/AddAutoReply.page.tsx @@ -194,6 +194,7 @@ export default function AddAutoReply() { const { data: domains, isLoading } = useDomains({ enabled: !editEmailAccountId, + shouldFetchAll: true, }); const selectedDomain = useMemo(() => { @@ -205,12 +206,14 @@ export default function AddAutoReply() { const { data: domainAccounts } = useAccountList({ enabled: !editEmailAccountId && !!selectedDomain, domainId: selectedDomain?.id, + shouldFetchAll: true, }); const { data: orgAccounts, isLoading: isOrgAccountsLoading } = useAccountList( { enabled: !!form.sendCopy.value && !!selectedOrganizationId, organizationId: selectedOrganizationId, + shouldFetchAll: true, }, ); diff --git a/packages/manager/apps/zimbra/src/pages/dashboard/Domains/AddDomain.page.tsx b/packages/manager/apps/zimbra/src/pages/dashboard/Domains/AddDomain.page.tsx index 40c861a6a992..3f9a5839356f 100644 --- a/packages/manager/apps/zimbra/src/pages/dashboard/Domains/AddDomain.page.tsx +++ b/packages/manager/apps/zimbra/src/pages/dashboard/Domains/AddDomain.page.tsx @@ -81,7 +81,9 @@ export default function AddDomain() { const { platformId } = usePlatform(); const { data: organization } = useOrganization(); - const { data: organizations, isLoading } = useOrganizationList(); + const { data: organizations, isLoading } = useOrganizationList({ + shouldFetchAll: true, + }); const [selectedOrganization, setSelectedOrganization] = useState( organization?.id || '', diff --git a/packages/manager/apps/zimbra/src/pages/dashboard/Domains/ModalEditDomain.component.tsx b/packages/manager/apps/zimbra/src/pages/dashboard/Domains/ModalEditDomain.component.tsx index b711a1d85ad5..0f99b5d678d4 100644 --- a/packages/manager/apps/zimbra/src/pages/dashboard/Domains/ModalEditDomain.component.tsx +++ b/packages/manager/apps/zimbra/src/pages/dashboard/Domains/ModalEditDomain.component.tsx @@ -52,7 +52,7 @@ export default function ModalEditDomain() { const { data: organizationsList, isLoading: isLoadingOrganizations, - } = useOrganizationList(); + } = useOrganizationList({ shouldFetchAll: true }); const { addError, addSuccess } = useNotifications(); diff --git a/packages/manager/apps/zimbra/src/pages/dashboard/EmailAccounts/AddAndEditEmailAccount.page.tsx b/packages/manager/apps/zimbra/src/pages/dashboard/EmailAccounts/AddAndEditEmailAccount.page.tsx index 3a8e228bb031..9c21f830572b 100644 --- a/packages/manager/apps/zimbra/src/pages/dashboard/EmailAccounts/AddAndEditEmailAccount.page.tsx +++ b/packages/manager/apps/zimbra/src/pages/dashboard/EmailAccounts/AddAndEditEmailAccount.page.tsx @@ -52,7 +52,9 @@ export default function AddAndEditAccount() { enabled: !!editEmailAccountId, }); - const { data: domainList, isLoading: isLoadingDomainRequest } = useDomains(); + const { data: domainList, isLoading: isLoadingDomainRequest } = useDomains({ + shouldFetchAll: true, + }); function activatedTabs(pathMatchers: RegExp[]) { return pathMatchers?.some((pathMatcher) => diff --git a/packages/manager/apps/zimbra/src/pages/dashboard/EmailAccounts/ModalAddAlias.component.tsx b/packages/manager/apps/zimbra/src/pages/dashboard/EmailAccounts/ModalAddAlias.component.tsx index eb3240bea4f8..221c21fe3ec2 100644 --- a/packages/manager/apps/zimbra/src/pages/dashboard/EmailAccounts/ModalAddAlias.component.tsx +++ b/packages/manager/apps/zimbra/src/pages/dashboard/EmailAccounts/ModalAddAlias.component.tsx @@ -71,7 +71,9 @@ export default function ModalAddAndEditOrganization() { const [isFormValid, setIsFormValid] = useState(false); - const { data: domainList, isLoading: isLoadingDomain } = useDomains(); + const { data: domainList, isLoading: isLoadingDomain } = useDomains({ + shouldFetchAll: true, + }); const { data: editAccountDetail, diff --git a/packages/manager/apps/zimbra/src/pages/dashboard/MailingLists/AddAndEditMailingList.page.tsx b/packages/manager/apps/zimbra/src/pages/dashboard/MailingLists/AddAndEditMailingList.page.tsx index fa5c1ece443f..8d27b11a465e 100644 --- a/packages/manager/apps/zimbra/src/pages/dashboard/MailingLists/AddAndEditMailingList.page.tsx +++ b/packages/manager/apps/zimbra/src/pages/dashboard/MailingLists/AddAndEditMailingList.page.tsx @@ -42,7 +42,9 @@ export default function AddAndEditMailingList() { isLoading: isLoadingMailingListDetailRequest, } = useMailingList({ mailingListId: editMailingListId }); - const { data: domainList, isLoading: isLoadingDomainRequest } = useDomains(); + const { data: domainList, isLoading: isLoadingDomainRequest } = useDomains({ + shouldFetchAll: true, + }); useEffect(() => { if ( diff --git a/packages/manager/apps/zimbra/src/pages/dashboard/Redirections/ModalAddAndEditRedirections.page.tsx b/packages/manager/apps/zimbra/src/pages/dashboard/Redirections/ModalAddAndEditRedirections.page.tsx index 40d637f70ffc..036310ec474f 100644 --- a/packages/manager/apps/zimbra/src/pages/dashboard/Redirections/ModalAddAndEditRedirections.page.tsx +++ b/packages/manager/apps/zimbra/src/pages/dashboard/Redirections/ModalAddAndEditRedirections.page.tsx @@ -70,6 +70,7 @@ export default function ModalAddAndEditRedirections() { const { data: domainList, isLoading: isLoadingDomain } = useDomains({ enabled: !editEmailAccountId && !editRedirectionId, + shouldFetchAll: true, }); const { data: accountDetail, isLoading: isLoadingAccount } = useAccount({ diff --git a/packages/manager/apps/zimbra/src/utils/index.ts b/packages/manager/apps/zimbra/src/utils/index.ts index 0d501e478fc3..15e1e236eb1e 100644 --- a/packages/manager/apps/zimbra/src/utils/index.ts +++ b/packages/manager/apps/zimbra/src/utils/index.ts @@ -14,3 +14,6 @@ export const FEATURE_FLAGS = { DOMAIN_DIAGNOSTICS: false, ORDER: false, }; + +export const APIV2_MAX_PAGESIZE = 9999; +export const APIV2_DEFAULT_PAGESIZE = 25;