Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upcoming: [M3-7455] - Add child account access column and disable button when account has child accounts #10012

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3845183
added column and disabled button when account has child accounts
tyler-akamai Dec 20, 2023
76024d1
removed child access for child accounts in msw
tyler-akamai Dec 20, 2023
bf43651
Added changeset
tyler-akamai Dec 20, 2023
bb58dbd
Update pr-10012-upcoming-features-1703090453195.md
tyler-akamai Dec 20, 2023
d56ce3d
add notice for disabled Close Account button
tyler-akamai Dec 27, 2023
6298f47
Place disabled dialog behind feature flag
tyler-akamai Dec 27, 2023
6b3b99e
add unit tests but one is failing
tyler-akamai Dec 28, 2023
5fed31c
Merge remote-tracking branch 'upstream/develop' into M3-7455-add-chil…
tyler-akamai Dec 28, 2023
8f293eb
unit tests not passing
tyler-akamai Dec 28, 2023
c6016b7
unit tests failing
tyler-akamai Dec 28, 2023
f0ed502
added makeResourcePage, still failing though
tyler-akamai Dec 28, 2023
d3eda04
fix unit tests, shoutout Mariah
tyler-akamai Dec 28, 2023
101694e
unit test failing
tyler-akamai Dec 29, 2023
8d9e5c1
updated tests
tyler-akamai Dec 29, 2023
65401eb
Address feedback: unit test
mjac0bs Jan 2, 2024
a98ec9d
Address feedback: notice copy and unit tests
mjac0bs Jan 2, 2024
132485f
Address feedback: fix conditional for col display; Make table col num…
mjac0bs Jan 2, 2024
f53d3ea
Update unit test, still one skipped test to fix
mjac0bs Jan 2, 2024
62f4892
Merge branch 'develop' into M3-7455-add-child-access-column-to-users-…
mjac0bs Jan 2, 2024
fc94ec4
Fix typo
mjac0bs Jan 2, 2024
d795584
Fix user landing crash and unit tests
mjac0bs Jan 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

Add child account access column and disable delete account button when account has child accounts ([#10012](https://github.com/linode/manager/pull/10012))
20 changes: 19 additions & 1 deletion packages/manager/src/features/Account/CloseAccountSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,36 @@ import * as React from 'react';

import { Accordion } from 'src/components/Accordion';
import { Button } from 'src/components/Button/Button';
import { Notice } from 'src/components/Notice/Notice';
import { useFlags } from 'src/hooks/useFlags';
import { useChildAccounts } from 'src/queries/account';

import CloseAccountDialog from './CloseAccountDialog';

const CloseAccountSetting = () => {
const [dialogOpen, setDialogOpen] = React.useState<boolean>(false);

const { data: childAccounts } = useChildAccounts({});
const flags = useFlags();
const closeAccountDisabled = flags.parentChildAccountAccess
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the current account has child accounts, disable the 'Close Account' button

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to simplify this:
const closeAccountDisabled = flags.parentChildAccountAccess && Boolean(childAccounts?.data?.length);

? Boolean(childAccounts?.data?.length)
: false;

return (
<>
<Accordion defaultExpanded={true} heading="Close Account">
<Grid container direction="column">
<Grid>
<Button buttonType="outlined" onClick={() => setDialogOpen(true)}>
{closeAccountDisabled && (
<Notice spacingBottom={20} variant="info">
Copy link
Contributor Author

@tyler-akamai tyler-akamai Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not in the mocks but we should tell the user why the button is disabled. I can run this by the UI team.

I tried to keep this consistent with the 'Backup Auto Enrollment' Section:
Screenshot 2023-12-27 at 3 42 03 PM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is a good call. Exact copy TBD - I know you reached out to Magda; we can be sure to get a response from her or Jan on that, whether it's finalized in this ticket or a follow up for copy changes.

Remove child accounts before closing the account.
</Notice>
)}
<Button
buttonType="outlined"
disabled={closeAccountDisabled}
onClick={() => setDialogOpen(true)}
>
Close Account
</Button>
</Grid>
Expand Down
11 changes: 10 additions & 1 deletion packages/manager/src/features/Users/UserRow.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Stack } from 'src/components/Stack';
import React from 'react';

import { Box } from 'src/components/Box';
import { Chip } from 'src/components/Chip';
import { DateTimeDisplay } from 'src/components/DateTimeDisplay';
import { GravatarByEmail } from 'src/components/GravatarByEmail';
import { Hidden } from 'src/components/Hidden';
import { Stack } from 'src/components/Stack';
import { StatusIcon } from 'src/components/StatusIcon/StatusIcon';
import { TableCell } from 'src/components/TableCell';
import { TableRow } from 'src/components/TableRow';
import { Typography } from 'src/components/Typography';
import { useFlags } from 'src/hooks/useFlags';
import { useAccountUserGrants } from 'src/queries/accountUsers';
import { capitalize } from 'src/utilities/capitalize';

import { UsersActionMenu } from './UsersActionMenu';
Expand All @@ -22,6 +24,8 @@ interface Props {
}

export const UserRow = ({ onDelete, user }: Props) => {
const flags = useFlags();
const { data: grants } = useAccountUserGrants(user.username);
return (
<TableRow ariaLabel={`User ${user.username}`} key={user.username}>
<TableCell>
Expand All @@ -36,6 +40,11 @@ export const UserRow = ({ onDelete, user }: Props) => {
<TableCell>{user.email}</TableCell>
</Hidden>
<TableCell>{user.restricted ? 'Limited' : 'Full'}</TableCell>
{flags.parentChildAccountAccess && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should provide a better check here as opposed to just relying on the feature flag, since that will disappear in the future and this entire column will be conditionally rendered.

<TableCell>
{grants?.global.child_account_access ? 'Enabled' : 'Disabled'}
mjac0bs marked this conversation as resolved.
Show resolved Hide resolved
</TableCell>
)}
<Hidden lgDown>
<TableCell>
<LastLogin last_login={user.last_login} />
Expand Down
5 changes: 5 additions & 0 deletions packages/manager/src/features/Users/UsersLanding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { TableRowEmpty } from 'src/components/TableRowEmpty/TableRowEmpty';
import { TableRowError } from 'src/components/TableRowError/TableRowError';
import { TableRowLoading } from 'src/components/TableRowLoading/TableRowLoading';
import { TableSortCell } from 'src/components/TableSortCell';
import { useFlags } from 'src/hooks/useFlags';
import { useOrder } from 'src/hooks/useOrder';
import { usePagination } from 'src/hooks/usePagination';
import { useAccountUsers } from 'src/queries/accountUsers';
Expand All @@ -24,6 +25,7 @@ import { UserDeleteConfirmationDialog } from './UserDeleteConfirmationDialog';
import { UserRow } from './UserRow';

export const UsersLanding = () => {
const flags = useFlags();
const { data: profile } = useProfile();

const pagination = usePagination(1, 'account-users');
Expand Down Expand Up @@ -115,6 +117,9 @@ export const UsersLanding = () => {
</TableSortCell>
</Hidden>
<TableCell>Account Access</TableCell>
{flags.parentChildAccountAccess && (
mjac0bs marked this conversation as resolved.
Show resolved Hide resolved
<TableCell>Child Account Access</TableCell>
)}
<Hidden lgDown>
<TableCell>Last Login</TableCell>
</Hidden>
Expand Down
15 changes: 14 additions & 1 deletion packages/manager/src/queries/accountUsers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { deleteUser, getUser, getUsers } from '@linode/api-v4/lib/account';
import {
deleteUser,
getGrants,
getUser,
getUsers,
} from '@linode/api-v4/lib/account';
import { useMutation, useQuery, useQueryClient } from 'react-query';

import { useProfile } from 'src/queries/profile';
Expand All @@ -8,6 +13,7 @@ import { queryKey } from './account';
import type {
APIError,
Filter,
Grants,
Params,
ResourcePage,
User,
Expand Down Expand Up @@ -35,6 +41,13 @@ export const useAccountUser = (username: string) => {
);
};

export const useAccountUserGrants = (username: string) => {
return useQuery<Grants, APIError[]>(
[queryKey, 'users', 'grants', username],
() => getGrants(username)
);
};

export const useAccountUserDeleteMutation = (username: string) => {
const queryClient = useQueryClient();
return useMutation<{}, APIError[]>(() => deleteUser(username), {
Expand Down