Skip to content

Commit

Permalink
feat(zimbra): add loading to datagrids
Browse files Browse the repository at this point in the history
ref: MANAGER-15389
Signed-off-by: Tristan WAGNER <[email protected]>
  • Loading branch information
tristanwagner committed Sep 24, 2024
1 parent f523e37 commit f93d5b0
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 137 deletions.
11 changes: 7 additions & 4 deletions packages/manager/apps/zimbra/src/components/Loading/Loading.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React from 'react';
import { OsdsSpinner } from '@ovhcloud/ods-components/react';
import { ODS_SPINNER_MODE, ODS_SPINNER_SIZE } from '@ovhcloud/ods-components';

export default function Loading() {
return (
<div className="flex justify-center">
<div>
<OsdsSpinner />
</div>
<div className="flex justify-center my-5">
<OsdsSpinner
mode={ODS_SPINNER_MODE.indeterminate}
size={ODS_SPINNER_SIZE.md}
inline
></OsdsSpinner>
</div>
);
}
7 changes: 5 additions & 2 deletions packages/manager/apps/zimbra/src/hooks/useAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {

type UseAccountParams = Omit<
UseQueryOptions,
'queryKey' | 'queryFn' | 'enabled' | 'gcTime'
'queryKey' | 'queryFn' | 'gcTime'
> & {
accountId?: string;
noCache?: boolean;
Expand All @@ -25,7 +25,10 @@ export const useAccount = (props: UseAccountParams) => {
...options,
queryKey: getZimbraPlatformAccountDetailQueryKey(platformId, accountId),
queryFn: () => getZimbraPlatformAccountDetail(platformId, accountId),
enabled: !!accountId && !!platformId,
enabled:
(typeof options.enabled !== 'undefined' ? options.enabled : true) &&
!!platformId &&
!!accountId,
gcTime: noCache ? 0 : 5000,
}) as UseQueryResult<AccountType>;
};
6 changes: 4 additions & 2 deletions packages/manager/apps/zimbra/src/hooks/useAccountList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

type UseAccountListParams = Omit<
UseQueryOptions,
'queryKey' | 'queryFn' | 'select' | 'enabled'
'queryKey' | 'queryFn' | 'select'
> & {
domainId?: string;
organizationId?: string;
Expand All @@ -37,6 +37,8 @@ export const useAccountList = (props: UseAccountListParams = {}) => {
...options,
queryKey: getZimbraPlatformAccountsQueryKey(platformId, queryParameters),
queryFn: () => getZimbraPlatformAccounts(platformId, queryParameters),
enabled: !!platformId,
enabled:
(typeof options.enabled !== 'undefined' ? options.enabled : true) &&
!!platformId,
}) as UseQueryResult<AccountType[]>;
};
10 changes: 5 additions & 5 deletions packages/manager/apps/zimbra/src/hooks/useDomains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import {

type UseDomainsParams = Omit<
UseQueryOptions,
'queryKey' | 'queryFn' | 'select' | 'enabled' | 'gcTime'
'queryKey' | 'queryFn' | 'select'
> & {
organizationId?: string;
noCache?: boolean;
};

export const useDomains = (props: UseDomainsParams = {}) => {
const { organizationId, noCache, ...options } = props;
const { organizationId, ...options } = props;
const { platformId } = usePlatform();
const { data: organization } = useOrganization();
const selectedOrganizationId = organization?.id;
Expand All @@ -36,7 +35,8 @@ export const useDomains = (props: UseDomainsParams = {}) => {
platformId,
organizationId || selectedOrganizationId,
),
enabled: !!platformId,
gcTime: noCache ? 0 : 5000,
enabled:
(typeof options.enabled !== 'undefined' ? options.enabled : true) &&
!!platformId,
}) as UseQueryResult<DomainType[]>;
};
17 changes: 13 additions & 4 deletions packages/manager/apps/zimbra/src/hooks/useOrganizationsList.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { useQuery } from '@tanstack/react-query';
import {
useQuery,
UseQueryOptions,
UseQueryResult,
} from '@tanstack/react-query';
import { usePlatform } from '@/hooks';
import {
getZimbraPlatformOrganization,
getZimbraPlatformOrganizationQueryKey,
OrganizationType,
} from '@/api/organization';

export const useOrganizationList = (options = {}) => {
export const useOrganizationList = (
options: Omit<UseQueryOptions, 'queryKey' | 'queryFn' | 'select'> = {},
) => {
const { platformId } = usePlatform();

return useQuery({
...options,
queryKey: getZimbraPlatformOrganizationQueryKey(platformId),
queryFn: () => getZimbraPlatformOrganization(platformId),
enabled: !!platformId,
});
enabled:
(typeof options.enabled !== 'undefined' ? options.enabled : true) &&
!!platformId,
}) as UseQueryResult<OrganizationType[]>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import ActionButtonDomain from './ActionButtonDomain';
import LabelChip from '@/components/LabelChip';
import { IAM_ACTIONS } from '@/utils/iamAction.constants';
import { DATAGRID_REFRESH_INTERVAL, DATAGRID_REFRESH_ON_MOUNT } from '@/utils';
import Loading from '@/components/Loading/Loading';

export type DomainsItem = {
id: string;
Expand Down Expand Up @@ -81,14 +82,14 @@ const columns: DatagridColumn<DomainsItem>[] = [
export default function Domains() {
const { t } = useTranslation('domains');
const { platformUrn } = usePlatform();
const isOverridedPage = useOverridePage();

const { data } = useDomains({
const { data, isLoading } = useDomains({
refetchInterval: DATAGRID_REFRESH_INTERVAL,
refetchOnMount: DATAGRID_REFRESH_ON_MOUNT,
enabled: !isOverridedPage,
});

const isOverriddedPage = useOverridePage();

const hrefAddDomain = useGenerateUrl('./add', 'href');

const items: DomainsItem[] =
Expand All @@ -102,46 +103,57 @@ export default function Domains() {
),
})) ?? [];

if (!platformUrn) {
return (
<div className="py-6 mt-8">
<Notifications />
<Outlet />
</div>
);
}

return (
<>
{!isOverriddedPage && (
<div className="py-6 mt-8">
<Notifications />
<div className="py-6 mt-8">
<Notifications />
<Outlet />
{!isOverridedPage && (
<>
<div className="flex items-center justify-between">
{platformUrn && (
<ManagerButton
color={ODS_THEME_COLOR_INTENT.primary}
inline
size={ODS_BUTTON_SIZE.sm}
href={hrefAddDomain}
urn={platformUrn}
iamActions={[IAM_ACTIONS.domain.create]}
data-testid="add-domain-btn"
className="mb-6"
>
<span slot="start">
<OsdsIcon
name={ODS_ICON_NAME.PLUS}
size={ODS_ICON_SIZE.sm}
color={ODS_THEME_COLOR_INTENT.primary}
contrasted
></OsdsIcon>
</span>
<span slot="end">{t('zimbra_domains_add_domain_title')}</span>
</ManagerButton>
)}
<ManagerButton
color={ODS_THEME_COLOR_INTENT.primary}
inline
size={ODS_BUTTON_SIZE.sm}
href={hrefAddDomain}
urn={platformUrn}
iamActions={[IAM_ACTIONS.domain.create]}
data-testid="add-domain-btn"
className="mb-6"
>
<span slot="start">
<OsdsIcon
name={ODS_ICON_NAME.PLUS}
size={ODS_ICON_SIZE.sm}
color={ODS_THEME_COLOR_INTENT.primary}
contrasted
></OsdsIcon>
</span>
<span slot="end">{t('zimbra_domains_add_domain_title')}</span>
</ManagerButton>
</div>
<Datagrid
columns={columns.map((column) => ({
...column,
label: t(column.label),
}))}
items={items}
totalItems={items.length}
/>
</div>
{isLoading ? (
<Loading />
) : (
<Datagrid
columns={columns.map((column) => ({
...column,
label: t(column.label),
}))}
items={items}
totalItems={items.length}
/>
)}
</>
)}
<Outlet />
</>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
DATAGRID_REFRESH_ON_MOUNT,
} from '@/utils';
import { IAM_ACTIONS } from '@/utils/iamAction.constants';
import Loading from '@/components/Loading/Loading';

export type EmailsItem = {
id: string;
Expand Down Expand Up @@ -106,11 +107,12 @@ const columns: DatagridColumn<EmailsItem>[] = [
export default function EmailAccounts() {
const { t } = useTranslation('accounts');
const { platformUrn } = usePlatform();
const { data } = useAccountList({
const isOverridedPage = useOverridePage();
const { data, isLoading } = useAccountList({
refetchInterval: DATAGRID_REFRESH_INTERVAL,
refetchOnMount: DATAGRID_REFRESH_ON_MOUNT,
enabled: !isOverridedPage,
});
const isOverriddedPage = useOverridePage();

const items: EmailsItem[] =
data?.map((item: AccountType) => ({
Expand All @@ -127,51 +129,60 @@ export default function EmailAccounts() {

const hrefAddEmailAccount = useGenerateUrl('./add', 'href');

return (
<>
<Outlet />
if (!platformUrn) {
return (
<div className="py-6 mt-8">
<Notifications />
{!isOverriddedPage && (
<>
<div className="mb-8">
<OsdsText
color={ODS_THEME_COLOR_INTENT.text}
hue={ODS_TEXT_COLOR_HUE._500}
size={ODS_TEXT_SIZE._200}
className="font-bold mr-4"
>
{t('zimbra_account_datagrid_webmail_label')}
</OsdsText>
<Links
href={webmailUrl}
type={LinkType.external}
label={webmailUrl}
target={OdsHTMLAnchorElementTarget._blank}
></Links>
</div>
{platformUrn && (
<ManagerButton
<Outlet />
</div>
);
}

return (
<div className="py-6 mt-8">
<Notifications />
<Outlet />
{!isOverridedPage && (
<>
<div className="mb-8">
<OsdsText
color={ODS_THEME_COLOR_INTENT.text}
hue={ODS_TEXT_COLOR_HUE._500}
size={ODS_TEXT_SIZE._200}
className="font-bold mr-4"
>
{t('zimbra_account_datagrid_webmail_label')}
</OsdsText>
<Links
href={webmailUrl}
type={LinkType.external}
label={webmailUrl}
target={OdsHTMLAnchorElementTarget._blank}
></Links>
</div>
<ManagerButton
color={ODS_THEME_COLOR_INTENT.primary}
inline
size={ODS_BUTTON_SIZE.sm}
urn={platformUrn}
iamActions={[IAM_ACTIONS.account.create]}
href={hrefAddEmailAccount}
data-testid="add-account-btn"
className="mb-6"
>
<span slot="start">
<OsdsIcon
name={ODS_ICON_NAME.PLUS}
size={ODS_ICON_SIZE.sm}
color={ODS_THEME_COLOR_INTENT.primary}
inline
size={ODS_BUTTON_SIZE.sm}
urn={platformUrn}
iamActions={[IAM_ACTIONS.account.create]}
href={hrefAddEmailAccount}
data-testid="add-account-btn"
className="mb-6"
>
<span slot="start">
<OsdsIcon
name={ODS_ICON_NAME.PLUS}
size={ODS_ICON_SIZE.sm}
color={ODS_THEME_COLOR_INTENT.primary}
contrasted
></OsdsIcon>
</span>
<span slot="end">{t('zimbra_account_account_add')}</span>
</ManagerButton>
)}
contrasted
></OsdsIcon>
</span>
<span slot="end">{t('zimbra_account_account_add')}</span>
</ManagerButton>
{isLoading ? (
<Loading />
) : (
<Datagrid
columns={columns.map((column) => ({
...column,
Expand All @@ -180,9 +191,9 @@ export default function EmailAccounts() {
items={items}
totalItems={items.length}
/>
</>
)}
</div>
</>
)}
</>
)}
</div>
);
}
Loading

0 comments on commit f93d5b0

Please sign in to comment.