Skip to content

Commit 51bc332

Browse files
upcoming: [UIE-10251] - Empty message for SwitchAccountDrawer child accounts table (#13412)
* fix + test * Added changeset: Empty message for `SwitchAccountDrawer` child accounts table * feedback @bnussman-akamai
1 parent 93b1a59 commit 51bc332

File tree

5 files changed

+110
-28
lines changed

5 files changed

+110
-28
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Upcoming Features
3+
---
4+
5+
Empty message for `SwitchAccountDrawer` child accounts table ([#13412](https://github.com/linode/manager/pull/13412))

packages/manager/src/features/Account/SwitchAccountDrawer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ export const SwitchAccountDrawer = (props: Props) => {
297297
? currentParentTokenWithBearer
298298
: currentTokenWithBearer
299299
}
300+
filter={filter}
300301
isLoading={isLoading}
301302
isSwitchingChildAccounts={isSwitchingChildAccounts}
302303
onClose={onClose}

packages/manager/src/features/Account/SwitchAccounts/ChildAccountList.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { Box, CircleProgress, LinkButton, Notice, Stack } from '@linode/ui';
22
import React from 'react';
33
import { Waypoint } from 'react-waypoint';
44

5-
import { useIsIAMDelegationEnabled } from 'src/features/IAM/hooks/useIsIAMEnabled';
6-
75
import type { ChildAccount, Filter, UserType } from '@linode/api-v4';
86

97
export interface ChildAccountListProps {
@@ -43,8 +41,6 @@ export const ChildAccountList = React.memo(
4341
fetchNextPage,
4442
isFetchingNextPage,
4543
}: ChildAccountListProps) => {
46-
const { isIAMDelegationEnabled } = useIsIAMDelegationEnabled();
47-
4844
if (isLoading) {
4945
return (
5046
<Box display="flex" justifyContent="center">
@@ -53,11 +49,7 @@ export const ChildAccountList = React.memo(
5349
);
5450
}
5551

56-
if (
57-
!isIAMDelegationEnabled &&
58-
childAccounts &&
59-
childAccounts.length === 0
60-
) {
52+
if (childAccounts && childAccounts.length === 0) {
6153
return (
6254
<Notice variant="info">
6355
There are no child accounts
@@ -69,21 +61,6 @@ export const ChildAccountList = React.memo(
6961
);
7062
}
7163

72-
if (
73-
isIAMDelegationEnabled &&
74-
childAccounts &&
75-
childAccounts.length === 0 &&
76-
!Object.prototype.hasOwnProperty.call(filter, 'company')
77-
) {
78-
return (
79-
<Notice variant="info">
80-
You don&apos;t have access to other accounts. You must be added to a
81-
delegation by your account administrator to have access to other
82-
accounts.
83-
</Notice>
84-
);
85-
}
86-
8764
const renderChildAccounts = childAccounts?.map((childAccount, idx) => {
8865
const euuid = childAccount.euuid;
8966
return (
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import React from 'react';
2+
3+
import { accountFactory } from 'src/factories';
4+
import { renderWithTheme } from 'src/utilities/testHelpers';
5+
6+
import { ChildAccountsTable } from './ChildAccountsTable';
7+
8+
import type { ChildAccountsTableProps } from './ChildAccountsTable';
9+
10+
const childAccounts = accountFactory.buildList(5).map((account, i) => ({
11+
...account,
12+
company: `Child Account ${i}`,
13+
}));
14+
15+
const childAccountsWithMoreThan25 = accountFactory
16+
.buildList(30)
17+
.map((account, i) => ({
18+
...account,
19+
company: `Child Account ${i}`,
20+
}));
21+
22+
const props: ChildAccountsTableProps = {
23+
childAccounts,
24+
currentTokenWithBearer: 'Bearer 123',
25+
onSwitchAccount: vi.fn(),
26+
page: 1,
27+
pageSize: 25,
28+
setIsSwitchingChildAccounts: vi.fn(),
29+
totalResults: 0,
30+
userType: undefined,
31+
filter: {},
32+
isLoading: false,
33+
isSwitchingChildAccounts: false,
34+
onClose: vi.fn(),
35+
onPageChange: vi.fn(),
36+
onPageSizeChange: vi.fn(),
37+
};
38+
39+
describe('ChildAccountsTable', () => {
40+
it('should display a list of child accounts', async () => {
41+
const { getByTestId, getAllByText } = renderWithTheme(
42+
<ChildAccountsTable {...props} />
43+
);
44+
45+
expect(getByTestId('child-accounts-table')).toHaveAttribute(
46+
'aria-label',
47+
'List of Child Accounts'
48+
);
49+
50+
childAccounts.forEach((account) => {
51+
expect(getAllByText(account.company)).toHaveLength(1);
52+
});
53+
});
54+
55+
it('should display pagination when there are more than 25 child accounts', async () => {
56+
const firstPageAccounts = childAccountsWithMoreThan25.slice(0, 25);
57+
58+
const { getByTestId } = renderWithTheme(
59+
<ChildAccountsTable
60+
{...props}
61+
childAccounts={firstPageAccounts}
62+
totalResults={childAccountsWithMoreThan25.length}
63+
/>
64+
);
65+
66+
expect(getByTestId('child-accounts-table-pagination')).toBeVisible();
67+
});
68+
69+
it('should display an empty state when no child accounts are found', async () => {
70+
const { getByText } = renderWithTheme(
71+
<ChildAccountsTable {...props} childAccounts={[]} />
72+
);
73+
74+
expect(
75+
getByText(
76+
/You don't have access to other accounts. You must be added to a delegation by an account administrator to have access to other accounts./
77+
)
78+
).toBeInTheDocument();
79+
});
80+
});

packages/manager/src/features/Account/SwitchAccounts/ChildAccountsTable.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, CircleProgress, LinkButton, useTheme } from '@linode/ui';
1+
import { Box, CircleProgress, LinkButton, Notice, useTheme } from '@linode/ui';
22
import { Pagination } from 'akamai-cds-react-components/Pagination';
33
import {
44
Table,
@@ -10,11 +10,12 @@ import React from 'react';
1010

1111
import { MIN_PAGE_SIZE } from 'src/components/PaginationFooter/PaginationFooter.constants';
1212

13-
import type { Account, UserType } from '@linode/api-v4';
13+
import type { Account, Filter, UserType } from '@linode/api-v4';
1414

15-
interface ChildAccountsTableProps {
15+
export interface ChildAccountsTableProps {
1616
childAccounts?: Account[];
1717
currentTokenWithBearer?: string;
18+
filter: Filter;
1819
isLoading: boolean;
1920
isSwitchingChildAccounts: boolean;
2021
onClose: () => void;
@@ -42,6 +43,7 @@ interface ChildAccountsTableProps {
4243

4344
export const ChildAccountsTable = (props: ChildAccountsTableProps) => {
4445
const {
46+
filter,
4547
childAccounts,
4648
currentTokenWithBearer,
4749
isLoading,
@@ -74,9 +76,25 @@ export const ChildAccountsTable = (props: ChildAccountsTableProps) => {
7476
);
7577
}
7678

79+
if (
80+
childAccounts &&
81+
childAccounts.length === 0 &&
82+
!Object.prototype.hasOwnProperty.call(filter, 'company')
83+
) {
84+
return (
85+
<Notice variant="info">
86+
You don&apos;t have access to other accounts. You must be added to a
87+
delegation by an account administrator to have access to other accounts.
88+
</Notice>
89+
);
90+
}
91+
7792
return (
7893
<>
79-
<Table aria-label="List of Child Accounts">
94+
<Table
95+
aria-label="List of Child Accounts"
96+
data-testid="child-accounts-table"
97+
>
8098
<TableBody>
8199
{childAccounts?.map((childAccount, idx) => (
82100
<TableRow key={childAccount.euuid}>
@@ -111,6 +129,7 @@ export const ChildAccountsTable = (props: ChildAccountsTableProps) => {
111129
{totalResults > MIN_PAGE_SIZE && (
112130
<Pagination
113131
count={totalResults}
132+
data-testid="child-accounts-table-pagination"
114133
itemsLabel="Accounts: "
115134
onPageChange={(e: CustomEvent<number>) =>
116135
handlePageChange(Number(e.detail))

0 commit comments

Comments
 (0)