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

chore: Render breadcrumbs slot in the skeleton state #2981

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

just-boris
Copy link
Member

@just-boris just-boris commented Nov 4, 2024

Description

Make breadcrumbs slot rendered even when the app layout widget is in the loading state, because it is important for funnel metrics tracking

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

How has this been tested?

  • Added extra unit tests
  • Also tested end-to-end in my dev pipeline
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.

Copy link

codecov bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.27%. Comparing base (672e7f8) to head (c5a8373).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2981   +/-   ##
=======================================
  Coverage   96.27%   96.27%           
=======================================
  Files         769      771    +2     
  Lines       21768    21774    +6     
  Branches     7039     7039           
=======================================
+ Hits        20958    20964    +6     
  Misses        802      802           
  Partials        8        8           

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

@@ -281,11 +281,11 @@ describeEachAppLayout({ themes: ['refresh-toolbar'], sizes: ['desktop'] }, () =>
<DestructibleLayout />
</>
);
expect(wrapper.find('[data-testid="local-breadcrumbs"]')!.getElement()).toBeEmptyDOMElement();
expect(wrapper.find('[data-testid="local-breadcrumbs"]')!.findBreadcrumbGroup()).toBeFalsy();
Copy link
Member Author

Choose a reason for hiding this comment

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

New behavior here – instead of rendering nothing we render breadcrumbs placeholder to be discovered by our funnel metrics collector

@@ -128,17 +127,16 @@ describe('BreadcrumbGroup Item', () => {
lastLink.click();
expect(onFollowSpy).not.toHaveBeenCalled();
});

test('should add a data-analytics attribute for the funnel name to the last item', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to other tests in the file above

ghost?: boolean;
itemIndex: number;
totalCount: number;
disableAnalytics?: boolean;
}

export const FunnelBreadcrumbItem = React.forwardRef<HTMLSpanElement, FunnelBreadcrumbItemProps>(
Copy link
Member Author

Choose a reason for hiding this comment

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

Refactored FunnelBreadcrumbItem to allow us rendering "no-UI" breadcrumbs we use to collect funnel metrics

Comment on lines -3 to -7
import breadcrumbGroupItemStyles from '../../breadcrumb-group/item/styles.css.js';
import breadcrumbGroupStyles from '../../breadcrumb-group/styles.css.js';

export const getBreadcrumbLinkSelector = (index: number) =>
`.${breadcrumbGroupStyles['breadcrumb-group']} .${breadcrumbGroupStyles.item}:nth-child(${index}) .${breadcrumbGroupItemStyles.anchor}`;
Copy link
Member Author

Choose a reason for hiding this comment

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

These class names are random and may resolve incorrectly, if breadcrumb on a page runs from a different version than this code.

Replaced with a data-attribute marker, which is more reliable

export function createWidgetizedComponent<Component extends FunctionComponent<any>>(Implementation: Component) {
export function createWidgetizedComponent<Component extends FunctionComponent<any>>(
Implementation: Component,
Skeleton?: React.ForwardRefExoticComponent<PropsType<Component> & React.RefAttributes<HTMLElement>>
Copy link
Member Author

Choose a reason for hiding this comment

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

New feature here, in addition to the fully working implementation we also receive a skeleton state to render while loading.

@just-boris just-boris marked this pull request as ready for review November 9, 2024 22:21
@just-boris just-boris requested a review from a team as a code owner November 9, 2024 22:21
@just-boris just-boris requested review from connorlanigan and removed request for a team November 9, 2024 22:21
*/

// backward compatibility before this commit: 7a4b7b3e3b1d50830383805a8f4ab6cd93c9701f
.breadcrumbs-own:not(:empty) + .breadcrumbs-discovered {
Copy link
Member Author

Choose a reason for hiding this comment

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

Not new code, just moved following BreadcrumbsSlot extraction into a separate mini-component

@connorlanigan
Copy link
Member

It looks like we switched from reading the third breadcrumb item (1-based)

resourceType: props.funnelResourceType || getTextFromSelector(getBreadcrumbLinkSelector(3)),

to reading the second breadcrumb item (when converted from 0-based indexing):

if (itemIndex === 1) {

Is this intended?

@just-boris
Copy link
Member Author

yes, intentional.

The second child is the ellipsis item which is always rendered when it is empty. The existing regression tests confirm that we still resolve to the expected text

@just-boris just-boris added this pull request to the merge queue Nov 12, 2024
Merged via the queue into main with commit 774fff4 Nov 12, 2024
40 checks passed
@just-boris just-boris deleted the fix-breadcrumb-skeleton branch November 12, 2024 17:22
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