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

replace match.params with useParams hook #1837

Merged
merged 5 commits into from
Oct 1, 2023

Conversation

anshgoyalevil
Copy link
Member

@anshgoyalevil anshgoyalevil commented Sep 30, 2023

Which problem is this PR solving?

Description of the changes

  • In rrd v6, we can no longer use match prop. Since the introduction of hooks, we need to use useParams() hook for accessing that.
  • rrd v5 to v5.1 guide recommends using <Route children .. instead of `<Route component ..> since it would be deprecated in v6.
  • This is the last PR for the v6 preparation. The next PR would finally upgrade rrd to v6.

How was this change tested?

  • Manually, by visiting each page.
screen-capture.4.webm

Checklist

Signed-off-by: Ansh Goyal <anshgoyal1704@gmail.com>
@anshgoyalevil anshgoyalevil marked this pull request as draft September 30, 2023 20:42
@codecov
Copy link

codecov bot commented Sep 30, 2023

Signed-off-by: Ansh Goyal <anshgoyal1704@gmail.com>
@anshgoyalevil anshgoyalevil marked this pull request as ready for review September 30, 2023 20:58
@@ -309,4 +310,4 @@ function mapDispatchToProps(dispatch) {
};
}

export default connect(mapStateToProps, mapDispatchToProps)(SearchTracePageImpl);
export default withRouteProps(connect(mapStateToProps, mapDispatchToProps)(SearchTracePageImpl));
Copy link
Member

Choose a reason for hiding this comment

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

Curious, why wasn't this change needed in the previous PR where withRouteProps was introduced? Does it work both ways?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it doesn't work both ways.

In the previous PR's code, it was working fine. I have just verified with the code on the main branch.

This file uses: this.props.history.push and even in the previous PR, I didn't see it using withRouter.
So, where did its history prop come from in the main branch? That's strange.

Copy link
Member Author

@anshgoyalevil anshgoyalevil Oct 1, 2023

Choose a reason for hiding this comment

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

You can too verify this by clicking on a trace spot from this chart:

image

In the main branch's code, it is working.

But in this PR's code, without the use of withRouteProps, this doesn't seem to work. I couldn't figure out why.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just figured it out.

Actually, it is due to the change in how we are using Route children and Route component.

mapStateToProps,
mapDispatchToProps
)(TraceDiffImpl);
export default withRouteProps(
Copy link
Member

Choose a reason for hiding this comment

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

could you please add documentation to this function (should've asked in the prev PR)?

export default function withRouteProps(WrappedComponent: React.ElementType) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Documentation in the form of jsDocs comments added throughout the function? Or is there any dedicated documentation guide for each function used in Jaeger-UI?

@@ -46,7 +46,7 @@ type TDispatchProps = {

type TOwnProps = {
history: RouterHistory;
match: match<TDiffRouteParams>;
params: TDiffRouteParams;
Copy link
Member

Choose a reason for hiding this comment

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

Does this change have any impart on the shape of the URL? IIUC the state is included in the URL.

Copy link
Member Author

Choose a reason for hiding this comment

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

No. Absolutely not.

Previous URL structure:

http://localhost:5173/trace/4e9e0a8990106fdd...196659de1e174bd4?cohort=4e9e0a8990106fdd&cohort=196659de1e174bd4

Current:

http://localhost:5173/trace/51c935040996787d...0f7faf874d731c2c?cohort=51c935040996787d&cohort=0f7faf874d731c2c

It's just the place from where we use the extracted URL parameters.

Comment on lines +59 to +61
<Route path={searchPath}>
<SearchTracePage />
</Route>
Copy link
Member Author

Choose a reason for hiding this comment

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

With this change, the child components, SearchTracePage in this example, would no longer receive the Route props.
So, we need to use the withRouteProps HOC to get them.

Signed-off-by: Ansh Goyal <anshgoyal1704@gmail.com>
Signed-off-by: Ansh Goyal <anshgoyal1704@gmail.com>
Signed-off-by: Ansh Goyal <anshgoyal1704@gmail.com>
@yurishkuro yurishkuro merged commit 3292b53 into jaegertracing:main Oct 1, 2023
9 checks passed
@anshgoyalevil anshgoyalevil deleted the 3_rrd branch October 9, 2023 06:31
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.

None yet

2 participants