Skip to content

ref(replays): Refactor tab filters to use the url bar to store data#39030

Merged
ryan953 merged 6 commits into
masterfrom
ryan953/replay-deeplink-filters
Sep 20, 2022
Merged

ref(replays): Refactor tab filters to use the url bar to store data#39030
ryan953 merged 6 commits into
masterfrom
ryan953/replay-deeplink-filters

Conversation

@ryan953

@ryan953 ryan953 commented Sep 19, 2022

Copy link
Copy Markdown
Member

Refactor the Console, DOM & Network tabs so that their filter inputs put their state inside the url instead of inside a useState hook.

This means users will be able to share their view of the page with each other, and also we'll be able to deep-link into some views.

#38861

it('filters console breadcrumbs by search term', () => {
const result = filterBreadcrumbs(breadcrumbs, 'comp', []);
expect(result.length).toEqual(2);
it('should update the url on user input', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this isn't really testing user input is it? it's more url params

@ryan953 ryan953 Sep 19, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah.. that's very true. I'll rename it.

To test the user input properly we'd want to write an RTL test that loads up the react component i think.

},
});

result.current.setSearchTerm('component');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what is current?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

current comes out of RTL, it's a ref (?) i guess that holds the last output of the hook: https://testing-library.com/docs/react-testing-library/api/#renderhook

/* eslint-disable react-hooks/exhaustive-deps */
const stringyLogLevel = JSON.stringify(query.consoleLogLevel);
const logLevel = useMemo(() => decodeList(query.consoleLogLevel), [stringyLogLevel]);
/* eslint-enable react-hooks/exhaustive-deps */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Which dep list would this rule yell at?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I didn't want to pass in query.consoleLogLevel because it's a string[], so it'll be a new object often enough. Instead I was playing with shoving that array into JSON.stringify and then using that as the hook dep.

useMemo complains because it expected query.consoleLogLevel to be in the deps array.

JSON.stringify(item.html).toLowerCase().includes(searchTerm),
};

function useDomFilters({actions}: Options): Return {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like a lot of similar code between this hook and the console filters

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, same structure in all three. I'll look at what can be done.

also, i'm mocking more data for tests. Not the most exciting but once we have the examples the next tests will be easier.

@ryan953 ryan953 enabled auto-merge (squash) September 20, 2022 20:46
@ryan953 ryan953 merged commit b8b5e36 into master Sep 20, 2022
@ryan953 ryan953 deleted the ryan953/replay-deeplink-filters branch September 20, 2022 20:54
ryan953 added a commit that referenced this pull request Sep 22, 2022
…ab (#39038)

Updated the header to have a link that will open the Console tab, and
auto-select the 'error' filter:

![Screen Shot 2022-09-21 at 9 33 07
AM](https://user-images.githubusercontent.com/187460/191561421-652ef647-ec0f-41c1-89f3-79771c08f96f.png)

If there are no errors in the replay, then clicking the link will still
open the Console tab, and set the filter to be `level=error`. Normally
you wouldn't be able to set `level=error` yourself when there are no
errors because the dropdown is populated only with values that exist in
the data.

Depends on #39030
Fixes #38861
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants