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: Empty notifications height #2856

Merged
merged 7 commits into from
Oct 14, 2024
Merged

Conversation

just-boris
Copy link
Member

@just-boris just-boris commented Oct 11, 2024

Description

Widget friendly version of #2810. Thanks @georgylobko for the original code.

See inline comments for more details

Related links, issue #, if available: n/a

How has this been tested?

  • Locally
  • Updated integration test
  • New screenshot test CR-153803954
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.

]}
/>
);
return <Flashbar items={notifications} />;
Copy link
Member Author

Choose a reason for hiding this comment

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

Updated demo implementation to represent real-world use-cases more closely

@@ -167,11 +167,18 @@ describe.each(['classic', 'refresh', 'refresh-toolbar'] as Theme[])('%s', theme
test(
'does not render notifications slot when it is empty',
Copy link
Member Author

Choose a reason for hiding this comment

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

We already had a test which was supposed to catch the issue, but it was asserting size of the wrong element. Refactored the test. It is now more strict and may require an update even on unrelated design changes, but this is still better than silently passing

@@ -23,8 +24,9 @@ export function AppLayoutNotificationsImplementation({
children,
}: AppLayoutNotificationsImplementationProps) {
const { ariaLabels, stickyNotifications, setNotificationsHeight, verticalOffsets } = appLayoutInternals;
const ref = useRef<HTMLElement>(null);
useResizeObserver(ref, entry => setNotificationsHeight(entry.borderBoxHeight));
const [hasNotificationsContent, contentRef] = useContainerQuery(rect => rect.borderBoxHeight > 0);
Copy link
Member Author

Choose a reason for hiding this comment

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

an extra resize observer may seem like a waste, but it allows us to resolve this rendering logic without talking outside this component, which is useful in the widget environment (compatibility with existing code)

@just-boris just-boris changed the title Fix/empty notifications height 2 fix: Empty notifications height Oct 11, 2024
@just-boris just-boris force-pushed the fix/empty-notifications-height-2 branch from 361636e to 936684e Compare October 11, 2024 16:04
Copy link

codecov bot commented Oct 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.19%. Comparing base (09a1b44) to head (c07c3ef).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2856      +/-   ##
==========================================
- Coverage   96.20%   96.19%   -0.01%     
==========================================
  Files         761      761              
  Lines       21436    21438       +2     
  Branches     6939     7327     +388     
==========================================
  Hits        20622    20622              
+ Misses        806      763      -43     
- Partials        8       53      +45     

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

@just-boris just-boris marked this pull request as ready for review October 11, 2024 16:16
@just-boris just-boris requested a review from a team as a code owner October 11, 2024 16:16
@just-boris just-boris removed the request for review from a team October 11, 2024 16:16
return null;
const notifications: Array<FlashbarProps.MessageDefinition> = [];
if (visible) {
notifications.push({
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you push an element to the array on the rendering condition? Why not directly provide an array with a single item based on visible? At least it would be more readable

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you want something like this

return <Flashbar items={visible ? [demoNotification] : []}>

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

georgylobko
georgylobko previously approved these changes Oct 11, 2024
@@ -167,11 +167,19 @@ describe.each(['classic', 'refresh', 'refresh-toolbar'] as Theme[])('%s', theme
test(
'does not render notifications slot when it is empty',
setupTest({ pageName: 'with-notifications' }, async page => {
const { height: originalHeight } = await page.getBoundingBox(wrapper.findNotifications().toSelector());
expect(originalHeight).toBeGreaterThan(0);
const { height: headerHeight } = await page.getBoundingBox('#h');
Copy link
Member Author

Choose a reason for hiding this comment

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

This height is different between CI and my local. I got it working when reading this value dynamically

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you elaborate what is "dynamic" in this code? And why the height is different in different environments?

Copy link
Member Author

Choose a reason for hiding this comment

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

The header height depends on system font rendering which is not deterministic and varies between Mac/Linux.

Tried to make it more deterministic: 14de51b

It broke other tests, so I abandoned this path

@@ -167,11 +167,19 @@ describe.each(['classic', 'refresh', 'refresh-toolbar'] as Theme[])('%s', theme
test(
'does not render notifications slot when it is empty',
setupTest({ pageName: 'with-notifications' }, async page => {
const { height: originalHeight } = await page.getBoundingBox(wrapper.findNotifications().toSelector());
expect(originalHeight).toBeGreaterThan(0);
const { height: headerHeight } = await page.getBoundingBox('#h');
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you elaborate what is "dynamic" in this code? And why the height is different in different environments?

refresh: headerHeight + 12,
'refresh-toolbar': headerHeight + 54,
}[theme];
expect(contentTop).toEqual(expectedOffset);
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it be easier to only check notification container height and make sure it equals 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is how original test was structured and it still allowed this regression to happen.

The new approach makes sure this test fails every time there is an extended top offset of the main content, regardless how it is implemented internally

@just-boris just-boris added this pull request to the merge queue Oct 14, 2024
Merged via the queue into main with commit 25f4435 Oct 14, 2024
34 checks passed
@just-boris just-boris deleted the fix/empty-notifications-height-2 branch October 14, 2024 13:49
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.

2 participants