Skip to content

ref(replays): Add component name to selector - #68631

Merged
c298lee merged 11 commits into
masterfrom
cl/component-name-in-selector
Apr 12, 2024
Merged

c298lee merged 11 commits into
masterfrom
cl/component-name-in-selector

Conversation

@c298lee

@c298lee c298lee commented Apr 10, 2024 •

Copy link
Copy Markdown
Contributor

Adds the component name to the selector as an attribute.
Example: div#myid.class1.class2[role="button"][alt="Alt"][testid="1"][aria="AriaLabel"][title="MyTitle"][component_name="SignUpForm"]

Relates to #64673

@c298lee
c298lee requested a review from a team April 10, 2024 17:10
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 10, 2024
@codecov

codecov Bot commented Apr 10, 2024 •

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 5.39kB ⬆️

Bundle name Size Change
sentry-webpack-bundle-array-push 26.28MB 5.39kB ⬆️

@codecov

codecov Bot commented Apr 10, 2024 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 40.00000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 79.77%. Comparing base (74593d2) to head (bbacc61).
Report is 153 commits behind head on master.

❗ Current head bbacc61 differs from pull request most recent head 7d95d14. Consider uploading reports for the commit 7d95d14 to get more accurate results

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #68631    +/-   ##
========================================
  Coverage   79.76%   79.77%            
========================================
  Files        6409     6413     +4     
  Lines      283806   284152   +346     
  Branches    48903    48980    +77     
========================================
+ Hits       226384   226679   +295     
- Misses      57035    57086    +51     
  Partials      387      387            
Files Coverage Δ
src/sentry/apidocs/examples/replay_examples.py 100.00% <ø> (ø)
...ys/endpoints/organization_replay_selector_index.py 94.01% <100.00%> (+0.05%) ⬆️
src/sentry/replays/lib/query.py 26.82% <0.00%> (-0.29%) ⬇️

... and 96 files with indirect coverage changes

@JoshFerge JoshFerge left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm!

assert (
response_data["data"][0]["dom_element"]
== 'div#myid.class1.class2[role="button"][alt="Alt"][testid="1"][aria="AriaLabel"][title="MyTitle"]'
== 'SignUpForm[role="button"][alt="Alt"][testid="1"][aria="AriaLabel"][title="MyTitle"]'

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.

looks like tag along with id and class attrs are gone, replaced by the component name. other attrs remain.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes if the component name exists, we want to show the component name everywhere instead of the tag, id and class since it's more readable and descriptive. This also makes it so that you can search the component name in dead and rage selectors.

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.

We might want to leave id in there, it's generally pretty descriptive/readable and not autogenerated like class

@@ -77,19 +77,19 @@ class ReplayExamples:
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could we also keep an example where there isn't a component name? could just be another elem in the data array

assert (
response_data["data"][0]["dom_element"]
== 'div#myid.class1.class2[role="button"][alt="Alt"][testid="1"][aria="AriaLabel"][title="MyTitle"]'
== 'SignUpForm[role="button"][alt="Alt"][testid="1"][aria="AriaLabel"][title="MyTitle"]'

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.

We might want to leave id in there, it's generally pretty descriptive/readable and not autogenerated like class

if row["click_component_name"]:
selector = row["click_component_name"]
if row["click_id"]:
selector = selector + f"#{row['click_id']}"

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.

Is there a reason we don't want to include the classes? They are part of the aggregation key as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we want to switch to use component name if that's available since the class is usually autogenerated in react and not descriptive

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.

We're still aggregating by class. We're hiding the true name of the aggregation key not altering the aggregation. We should remove class aggregation if its not valuable.

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.

Ah, can we generate a "display name" type selector on the frontend and keep the selector the same?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we want to be able to search by the component name in the r&d selectors too, which would require changing the selectors.

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.

Searching is a different problem to aggregation. We can search by component name regardless of this change.

If we're aggregating two rows:

Component Name Classes
SignUpForm [blue, square]
SignUpForm [red, circle]

Should we return:

["SignUpFrom", "SignUpForm"]

Or should we return:

["SignUpFrom"]

Or should we return:

["SignUpFrom.blue.square", "SignUpForm.red.circle"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are keeping the selector mostly the same, except with an added component name attribute, and we will generate a "display name" type selector in the frontend

@cmanallen cmanallen left a comment

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.

@c298lee Can you write test coverage that asserts your component_name attribute is searchable. You can updates this test here:

queries = [
"click.alt:Alt",
"click.class:class1",
"click.class:class2",
"click.class:class3",
"click.id:myid",
"click.label:AriaLabel",
"click.component_name:SignUpForm",
"click.role:button",
"click.tag:div",
"click.tag:button",
"click.testid:1",
"click.textContent:Hello",
"click.title:MyTitle",
"click.selector:div#myid",
"click.selector:div[alt=Alt]",
"click.selector:div[title=MyTitle]",
"click.selector:div[data-sentry-component=SignUpForm]",
"click.selector:div[data-testid='1']",
"click.selector:div[data-test-id='1']",
"click.selector:div[role=button]",
"click.selector:div#myid.class1.class2",
"dead.selector:div#myid",
"rage.selector:div#myid",
# Assert selectors with special characters in them can be queried.
"click.selector:div.class%5C:hover",
# Single quotes around attribute value.
"click.selector:div[role='button']",
"click.selector:div#myid.class1.class2[role=button][aria-label='AriaLabel']",
]
for query in queries:
response = self.client.get(self.url + f"?field=id&query={query}")
assert response.status_code == 200, query
response_data = response.json()
assert len(response_data["data"]) == 1, query

There's already a mock component SignUpForm so no need to insert anything in the database. Just add a selector filter to the list and whatever code is needed to transform the selector to a valid query.

@c298lee
c298lee requested a review from cmanallen April 12, 2024 19:11
@c298lee
c298lee merged commit f25ba66 into master Apr 12, 2024
@c298lee
c298lee deleted the cl/component-name-in-selector branch April 12, 2024 19:42
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 28, 2024

This branch was successfully deployed

1 active deployment
Preview — 7d95d14b Deployed Apr 12, 2024 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants