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-7429] - Add Parent/Proxy 'Switch Account' button and drawer to user profile dropdown menu #10031

Merged
merged 13 commits into from
Jan 8, 2024

Conversation

mjac0bs
Copy link
Contributor

@mjac0bs mjac0bs commented Jan 3, 2024

Description 📝

This PR introduces a more intuitive design for the profile dropdown menu and implements a new drawer specifically for listing child accounts. The profile dropdown menu should now visually distinguish between parent and proxy account types, providing a clearer representation of the user's account hierarchy.

Note

This story focuses solely on enhancing the user interface and does not involve token issuance or the actual switching to the proxy account, which will be handled separately (in M3-7430).

Changes 🔄

Subtle differences between the two drawers are bolded.

Parent View:

  • We should see which account the parent user is logged into (parent company).
  • "Switch Account" button should be visible.
  • "Switch Account" button should open "Switch Account" drawer with list of child accounts.
  • The child accounts should be scrollable if the list is too long.
    • For the purposes of this PR, we just expect the drawer to scroll; a follow up PR will look into a virtualized list.
  • Upon closing drawer, profile dropdown menu should remain open.

Proxy View:

  • We should see which company the parent user is logged into (child company).
  • "Switch Account" button should be visible.
  • "Switch Account" button should open "Switch Account" drawer with list of child accounts.
  • There should be a link to switch back to parent account.
  • Upon closing drawer, profile dropdown menu should remain open.

Child View:

  • No change, same as typical user without a parent/child relationship

Preview 📷

Screenshots
Before After
User Menu Popover Screenshot 2024-01-05 at 4 25 02 PM Screenshot 2024-01-05 at 4 24 55 PM
Switch Account Drawer - Parent View Screenshot 2024-01-05 at 4 10 32 PM
Switch Account Drawer - Proxy View Screenshot 2024-01-05 at 4 11 03 PM
Switch Account Drawer - Error Views Screenshot 2024-01-05 at 4 11 57 PM Screenshot 2024-01-05 at 4 11 30 PM

How to test 🧪

Prerequisites

(How to setup test environment)

  • Check out this PR and yarn dev.
  • Make sure the Parent Child Account Access feature flag is on and mocks are on.

Verification steps

(How to verify changes)

  1. Click on the Profile & Account button in the top menu to open the user menu popover.
  2. Observe that the Mock Company name is displayed and a Switch Account button is visible.
  3. Confirm the changes described above in "Parent View". If you want to test a long list of child accounts, uncomment the return statement on L1180 of the mocks.
  4. Go to serverHandlers.ts and edit the account/users/:user request to the following in order to mock a proxy user:
  rest.get('*/account/users/:user', (req, res, ctx) => {
  // Parent/Child: switch the `user_type` depending on what account view you need to mock.
  return res(ctx.json(accountUserFactory.build({ user_type: 'proxy' })));
  }),
  1. Repeat steps 1-3 above for proxy view.
  2. Repeat step 4 for a Child user and confirm parity with prod.
  3. Toggle off feature flag and confirm parity with prod.
  4. Verify unit tests pass:
yarn test UserMenu SwitchAccountDrawer

As an Author I have considered 🤔

Check all that apply

  • 👀 Doing a self review
  • ❔ Our contribution guidelines
  • 🤏 Splitting feature into small PRs
  • ➕ Adding a changeset
  • 🧪 Providing/Improving test coverage
  • 🔐 Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • 👣 Providing comprehensive reproduction steps
  • 📑 Providing or updating our documentation
  • 🕛 Scheduling a pair reviewing session
  • 📱 Providing mobile support
  • ♿ Providing accessibility support

@mjac0bs mjac0bs force-pushed the M3-7429-user-profile-dropdown-menu branch from 5dcd208 to c520b4b Compare January 4, 2024 23:35
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the diff in this file. I added a describe; most of the tests were already existing. See the comments below for the test added in this PR.

Comment on lines +112 to +134
it('shows the parent company name and Switch Account button in the dropdown menu for a parent user', async () => {
server.use(
rest.get('*/account', (req, res, ctx) => {
return res(
ctx.json(accountFactory.build({ company: 'Parent Company' }))
);
}),
rest.get('*/account/users/*', (req, res, ctx) => {
return res(ctx.json(accountUserFactory.build({ user_type: 'parent' })));
})
);

const { findByLabelText, findByTestId } = renderWithTheme(<UserMenu />, {
flags: { parentChildAccountAccess: true },
});

const userMenuButton = await findByLabelText('Profile & Account');
fireEvent.click(userMenuButton);

const userMenuPopover = await findByTestId('user-menu-popover');

expect(within(userMenuPopover).getByText('Parent Company')).toBeVisible();
expect(within(userMenuPopover).getByText('Switch Account')).toBeVisible();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a new test.

Comment on lines +137 to +160
it('shows the child company name and Switch Account button in the dropdown menu for a proxy user', async () => {
server.use(
rest.get('*/account', (req, res, ctx) => {
return res(
ctx.json(accountFactory.build({ company: 'Child Company' }))
);
}),
rest.get('*/account/users/*', (req, res, ctx) => {
return res(ctx.json(accountUserFactory.build({ user_type: 'proxy' })));
})
);

const { findByLabelText, findByTestId } = renderWithTheme(<UserMenu />, {
flags: { parentChildAccountAccess: true },
});

const userMenuButton = await findByLabelText('Profile & Account');
fireEvent.click(userMenuButton);

const userMenuPopover = await findByTestId('user-menu-popover');

expect(within(userMenuPopover).getByText('Child Company')).toBeVisible();
expect(within(userMenuPopover).getByText('Switch Account')).toBeVisible();
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a new test.

>
<Stack data-qa-user-menu minWidth={250} spacing={2}>
{isAccountSwitchable && (
<Typography>You are currently logged in as:</Typography>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I diverged from the mocks with this copy because I think it sounds nicer than 'Current account:', but open to feedback if reviewers disagree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The SwitchAccountButton will be reused on the Account landing page for parent/proxy users. (M3-7475)

@@ -1177,6 +1177,7 @@ export const handlers = [
}),
];
return res(ctx.json(makeResourcePage(childAccounts)));
// return res(ctx.json(makeResourcePage(accountFactory.buildList(101))));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added for ease of testing a long list of child accounts; will clean up later in the project after a follow-up ticket on scrolling is done.

@mjac0bs mjac0bs marked this pull request as ready for review January 6, 2024 00:33
@mjac0bs mjac0bs requested a review from a team as a code owner January 6, 2024 00:33
@mjac0bs mjac0bs requested review from bnussman-akamai and jaalah-akamai and removed request for a team January 6, 2024 00:33
@mjac0bs mjac0bs added the Add'tl Approval Needed Waiting on another approval! label Jan 8, 2024
Copy link

github-actions bot commented Jan 8, 2024

Coverage Report:
Base Coverage: 79.86%
Current Coverage: 79.86%

Copy link
Contributor

@jaalah-akamai jaalah-akamai left a comment

Choose a reason for hiding this comment

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

  • Confirmed button appears for both types of users and clicking it opens the drawer and user menu remains open
  • Confirmed link appears on proxy account to go back to parent account
  • Confirmed these are feature flagged

@jaalah-akamai jaalah-akamai added Approved Multiple approvals and ready to merge! and removed Add'tl Approval Needed Waiting on another approval! labels Jan 8, 2024
@mjac0bs mjac0bs merged commit 23ca92f into linode:develop Jan 8, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved Multiple approvals and ready to merge! Parent / Child Account
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants