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

Refactor: Rewrite components into functional components to enable useHooks #2588

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Zen-cronic
Copy link
Contributor

Which problem is this PR solving?

Description of the changes

  • Converted several class-based components into functional ones, to enable the use of useHooks from rrd v6

How was this change tested?

  • npm run test
  • Currently, many failing tests - will address if this concept works

Checklist

@Zen-cronic
Copy link
Contributor Author

Update:

This is the default page after clicking "Find Traces" form:
Notice the params in the url.

before-missing-params

The DDG page functions as expected (after clicking on "Deep Dependency Graph").
But the page url lost its many of its params:

missing-params

This is the expected result, with full params:

working-ddg

I'll explain further in the review section.

// Graph displayed only when the state.router.location.search is used, which contains all the params
// ownProps.location.search contains only the `?view=dgg` param
// const urlState = getUrlState(ownProps.location.search);
const urlState = getUrlState(state.router.location.search);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

as said in the inline comments, the ddg is displayed only with the url params stored in the redux state.

Copy link
Member

Choose a reason for hiding this comment

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

sounds like a regression. Jaeger UI links are supposed to be shareable and capture the complete state.

render(): React.ReactNode {
const { location } = this.props;
export const TracesDdgImpl: React.FC<TProps> = (props) => {
const location = useLocation();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i expected useLocation to provide us with the same value as state.router.location due to the use of redux-first-history in the store:

export const history = createReduxHistory(store);

that's what the library is for - to sync the history object shared by react-redux and rrd. From the docs, in rrdv6, we should get useLocation() === state.router.location, but that's not the case here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

our current implementation stores the url (the params) in the redux store, and related components subscribe to the store and update it via mapStateToProps. E.g.,

export function mapStateToProps(state: ReduxState, ownProps: TOwnProps): TReduxProps {

But as said above, the useLocation hook doesn't provide us with the synchronized location object. That's probably why the url doesn't get updated correctly:

const urlState = getUrlState(ownProps.location.search);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

folks have been facing similar issues.

we shouldn't rely anymore on the redux state anymore for navigating url routes and updating query params, and instead use rrdv5-compat and rrdv6's useHooks.

@Zen-cronic Zen-cronic changed the title Refactor: Rewrite search page related components into functional comp… Refactor: Rewrite search page related components into functional components Jan 16, 2025
};
// Navigated to `/search?view=ddg`
// should be the full `/search?end=1736992218835000&limit=20&lookback=1h&maxDuration&minDuration&service=frontend&start=1736988618835000&view=ddg` or &view=traces
navigate(getUrl({ ...urlState, view }));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the discrepancy between location provided by useLocation and what's in the redux state.
This is what's making the ddg displayed correctly under the wrong url (missing params).

@hari45678
Copy link
Contributor

hari45678 commented Jan 16, 2025

@Zen-cronic I am working on removing redux-form dependency from past few days. We would eventually have to remove history package as rrd v7 handles that internally. And as a result, redux-first-history would need to be removed. We can rewrite the class components to functional components gradually, one by one, otherwise some errors might stay uncaught by the automated tests. I would volunteer by your side in rewriting these components.

For this PR, my recommendation would be to go for one chain of related changes only and testing that change manually. For example, rewrite a single component, check which other components depend/it depends on. Only change that part of code that keeps those related components in a working state, instead of rewriting those components to functional components as well

@Zen-cronic
Copy link
Contributor Author

thanks for your suggestion, hari.

my goal is to unblock #2580 by following this official v5-v6 migration guide.

from now on, here's my process:

  1. Rewrite a component if it meets this criteria:
  • if it reads location from the redux state. e.g. SearchTracePage and/or
  • if it updates the query params to the redux state e.g. UiFindInput
  1. Replace history, location, and query params in the redux state with useHooks b/c routing should be decoupled from the store

  2. repeat this process for another set of related components

@Zen-cronic Zen-cronic changed the title Refactor: Rewrite search page related components into functional components Refactor: Rewrite components into functional components to enable useHooks Jan 23, 2025
…nal components"

- Restart from one component/related components at a time.

This reverts commit 9308a1d.
Copy link

codecov bot commented Jan 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.61%. Comparing base (2d880b4) to head (9af2a82).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2588   +/-   ##
=======================================
  Coverage   96.61%   96.61%           
=======================================
  Files         255      255           
  Lines        7738     7738           
  Branches     1988     2006   +18     
=======================================
  Hits         7476     7476           
  Misses        262      262           

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

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