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(html): Reveal elements with Anchor abstraction #33537

Merged
merged 7 commits into from
Nov 19, 2024

Conversation

Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Nov 11, 2024

Replaces our custom reveal implementation with an abstracted one. useAnchor allows subscribing to anchor changes, <Anchor> implements scrollIntoView behaviour.

When I demo'd this on Friday, we discussed something about an engage/disengage switch for asynchronous reveals. I don't see a need for that right now, so i've kept it out.

Screen.Recording.2024-11-11.at.11.19.24.mov

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

packages/html-reporter/src/links.tsx Outdated Show resolved Hide resolved
>
{children}
</Chip>;
anchorId?: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

I find it strange that the first and only usage is inside AutoChip. I'd prefer to separate them for now, and wrap with Anchor where needed to separate concerns.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we want the chip to auto-expand on reveal, then we need to combine them. If not, then i'm happy to separate.

const [expanded, setExpanded] = React.useState(initialExpanded ?? true);
const onChangeReveal = React.useCallback((isRevealed: boolean) => {
if (isRevealed)
setExpanded(true);
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 we need this logic? If it is collapsed by default, perhaps it's fine for it to be collapsed after scrolling into view?

Copy link
Member Author

Choose a reason for hiding this comment

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

UX-Wise, I think uncollapsing on reveal saves one click. This might not make a difference for Traces or Videos. But we'll extend this to a specific attachment in the future, and there's no way of revealing an element in a collapsed Chip.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about this one, it means in addition to scrolling into view, we might need to perform other actions to reveal, for example expand the chip.

If we think broadly, the way to solve it would be to add revealing logic to various UI elements:

  • Make expandable/switchable elements accept anchorId that they will useAnchor() with and reveal the respective part of the UI.
  • Separate Anchor that will scroll into view from the AutoChip that will expand, and pass the same anchorId to both.
  • Make anchorId hierarchical in the future, so that we can in theory say "AutoChip that contains all attachments has anchorId=attachments/*", and then inside it put individual "Attachment with anchorId=attachments/0".

Let me know what you think.

Copy link
Member Author

@Skn0tt Skn0tt Nov 12, 2024

Choose a reason for hiding this comment

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

You've put into words what I couldn't, yes! That's why useAnchor is probably gonna be exported in the next PR, and why anchorId already accepts a predicate. I'll look at separating the expanding + scrolling logic in AutoChip.

packages/html-reporter/src/links.tsx Outdated Show resolved Hide resolved
packages/html-reporter/src/links.tsx Outdated Show resolved Hide resolved

export function useAnchor(id: AnchorID, onChange: (isRevealed: boolean) => void) {
React.useEffect(() => {
const listener = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this going to trigger if I click the same "reveal" link again? I'd like the item to be revealed even when it's already in the url. And vice versa, I wouldn't want the item to be revealed on mere re-render, e.g. switching a tab in a tabbed pane.

Copy link
Member Author

Choose a reason for hiding this comment

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

It triggers for each popstate event, unrelated of re-rendering. As you can see in the video, this includes clicking the link again. If you have a tabbed pane, and that tabbed pane leads to popstate events, then I guess the tabbed pane shouldn't include the anchor param in its links.

This comment has been minimized.

@Skn0tt Skn0tt requested a review from dgozman November 19, 2024 09:11
@Skn0tt
Copy link
Member Author

Skn0tt commented Nov 19, 2024

I've implemented the separation we discussed in dc064d4.

}, [id, onReveal]);
}

export function Anchor({ id, onReveal, children }: React.PropsWithChildren<{ id: AnchorID, onReveal?(): void }>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need onReveal anymore, let's drop it.

This comment has been minimized.

Copy link
Contributor

Test results for "tests 1"

2 flaky ⚠️ [chromium-page] › page/page-event-request.spec.ts:138:3 › should report navigation requests and responses handled by service worker with routing @ubuntu-20.04-chromium-tip-of-tree
⚠️ [playwright-test] › ui-mode-test-watch.spec.ts:145:5 › should watch all @windows-latest-node18-1

36951 passed, 650 skipped
✔️✔️✔️

Merge workflow run.

@Skn0tt Skn0tt merged commit 4979ce2 into microsoft:main Nov 19, 2024
29 checks passed
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