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

fix: Refactor and fix AppLayout and side navigation panel state and behaviour #1434

Merged
merged 17 commits into from
Aug 25, 2023

Conversation

rubencarvalho
Copy link
Contributor

@rubencarvalho rubencarvalho commented Aug 10, 2023

Description

When clicking a navigation link in mobile AppLayout side navigation, the panel should close automatically. Furthermore, on mobile viewports, the side navigation should also be closed by default.

This used to be handled in our code, but has regressed:

This behavior is supposed to be handled by the AppLayout.
However, our side navigation was blocking this code. I've split the event listener to be applied to both the header text and trigger button for the expandable section, so we don't need the stopPropagation.

There was also a unit test for it, but very artificial and this is why the regression was not caught:

test('closes navigation when clicking on links', () => {

Related links: AWSUI-21892

How has this been tested?

Existing tests, updated some "artificial ones" and added new ones to cover the expected behaviour.

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link

codecov bot commented Aug 14, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (99e8bbf) 93.78% compared to head (4c020a8) 93.79%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1434   +/-   ##
=======================================
  Coverage   93.78%   93.79%           
=======================================
  Files         639      639           
  Lines       17228    17231    +3     
  Branches     5665     5667    +2     
=======================================
+ Hits        16158    16161    +3     
  Misses        997      997           
  Partials       73       73           
Files Changed Coverage Δ
...c/expandable-section/expandable-section-header.tsx 100.00% <ø> (ø)
src/side-navigation/internal.tsx 100.00% <ø> (ø)
src/app-layout/index.tsx 92.83% <100.00%> (+0.05%) ⬆️
src/app-layout/visual-refresh/context.tsx 89.36% <100.00%> (+0.15%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/app-layout/index.tsx Outdated Show resolved Hide resolved
@rubencarvalho rubencarvalho marked this pull request as ready for review August 22, 2023 15:06
@rubencarvalho rubencarvalho requested a review from a team as a code owner August 22, 2023 15:06
@rubencarvalho rubencarvalho requested review from timogasda and removed request for a team August 22, 2023 15:06
@just-boris just-boris self-requested a review August 22, 2023 15:20
@rubencarvalho rubencarvalho force-pushed the rucarva-applayout-navigation-panel branch from cf9007a to b9eb880 Compare August 22, 2023 15:35
Comment on lines 205 to 206
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isMobile]);
Copy link
Member

Choose a reason for hiding this comment

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

As opposed to adding more eslint-disable-next-line exceptions, I suggest converting const onNavigationToggle = useCallback(() => {}, []) to const onNavigationToggle = useStableCallback(() => {}). This value will be safe to put into effects

@@ -412,6 +412,7 @@ function ExpandableLinkGroup({ definition, fireFollow, fireChange, activeHref, v
variant="navigation"
expanded={userExpanded ?? expanded}
onChange={onExpandedChange}
__disableExpandChangeOnHeaderTextClick={disableExpandChangeOnHeaderTextClick}
Copy link
Member

Choose a reason for hiding this comment

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

Can we do this without an internal prop?

For example, what if we baked this behavior into the navigation variant of expandable section?

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've changed from using an internal prop (for detecting the desired behaviour of the trigger to expand the section) into the "navigation" variant of the expandable section.

navigation - Use this variant in the navigation panel with anchors and custom styled content. It doesn't have any default styles.

This is a more impactful change, but between a successful dry-run (ID: 6564992503) and our current guidelines (above), I'm confident this is the best approach.

Copy link
Member

Choose a reason for hiding this comment

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

Let's do it!

@@ -87,7 +87,7 @@ export function describeEachAppLayout(callback: () => void) {
(useMobile as jest.Mock).mockReset();
(useVisualRefresh as jest.Mock).mockReset();
});
callback();
callback(size as 'desktop' | 'mobile');
Copy link
Member

Choose a reason for hiding this comment

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

minor: Instead of casting the value of the variable (technically not safe), it would be better to cast the array that you iterate over (const size of ['desktop', 'mobile'] as const)

@@ -95,14 +95,15 @@ const ExpandableNavigationHeader = ({
icon,
}: ExpandableNavigationHeaderProps) => {
return (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

<ExpandableNavigationHeader /> is rendered conditionally only for the navigation variant, so the change below is only applied to this variant.

if (variant === 'navigation') {
return (
<ExpandableNavigationHeader
className={clsx(className, wrapperClassName)}
ariaLabelledBy={ariaLabelledBy}
{...defaultHeaderProps}
>
{headerText ?? header}
</ExpandableNavigationHeader>
);
}

@rubencarvalho rubencarvalho merged commit f0d128b into main Aug 25, 2023
24 checks passed
@rubencarvalho rubencarvalho deleted the rucarva-applayout-navigation-panel branch August 25, 2023 09:22
avinashbot added a commit that referenced this pull request Aug 25, 2023
@rubencarvalho rubencarvalho restored the rucarva-applayout-navigation-panel branch August 28, 2023 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants