Skip to content

refactor(devtools): adds router graph implementation and demo#58213

Closed
sumitarora wants to merge 2 commits into
angular:mainfrom
sumitarora:feat-router-devtools
Closed

refactor(devtools): adds router graph implementation and demo#58213
sumitarora wants to merge 2 commits into
angular:mainfrom
sumitarora:feat-router-devtools

Conversation

@sumitarora
Copy link
Copy Markdown
Contributor

@sumitarora sumitarora commented Oct 15, 2024

Follow-up PR for #58086 & #58199.

Adds below features to Angular DevTools to display router graph:

  • Add a new router example in the Angular DevTools demo application.
  • Implement the router graph in the Angular DevTools to view the routes that are loaded in the application.
image image

@pullapprove pullapprove Bot requested a review from josephperrott October 15, 2024 18:40
@ngbot ngbot Bot added this to the Backlog milestone Oct 15, 2024
@dgp1130 dgp1130 requested review from AleksanderBodurri and dgp1130 and removed request for josephperrott October 15, 2024 18:59
@dgp1130 dgp1130 added action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release labels Oct 15, 2024
@sumitarora sumitarora force-pushed the feat-router-devtools branch from f70b0c4 to b2bd946 Compare October 15, 2024 20:04
Copy link
Copy Markdown
Contributor

@dgp1130 dgp1130 left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together @sumitarora!

I mostly left a bunch of minor readability improvements. I'll have to defer to @AleksanderBodurri on the DI and d3 stuff, as I'm not super familiar with those pieces and can only leave superficial suggestions.

The biggest missing piece to me is testing. I'd love to test some tests covering the newly added code to the extent we can. That would go a long way to maintaining functionality long term.

Comment thread devtools/projects/ng-devtools-backend/src/lib/client-event-subscribers.ts Outdated
Comment thread devtools/projects/ng-devtools-backend/src/lib/client-event-subscribers.ts Outdated
Comment thread devtools/projects/ng-devtools-backend/src/lib/router-tree.ts Outdated
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.

Suggestion: Avoid any where possible. I get that there's a bunch of pre-existing any types here and it doesn't look like we have an @angular/router dependency here (should we have one?). But anything we can do to avoid proliferating more any types is probably worth the effort, even if we ignore the existing ones.

Comment thread devtools/projects/ng-devtools-backend/src/lib/router-tree.ts Outdated
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.

Bug: What if the viewChild elements change? Should we recreate the RouterTreeVisualizer?

Ideally I think routerTreeVisualizer would be a computed(() => new RouterTreeVisualizer(...)), but I think the need to call .cleanup() makes that tricky. Maybe it should just be an effect dependent on viewChild signals?

This is a bit of an academic concern since those viewChild elements are unlikely to change, so up to you if this is really important to fix or not.

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.

Consider: Since we only snap to root on the first render, could we use something like afterNextRender(() => this.routerTreeVisualizer.snapToRoot(...); in the constructor and then leave it out of renderGraph?

I'm thinking that getting rid of the parameter might make it a little easier to turn this into an effect which is automatically scheduled rather than manually managed.

Comment thread devtools/src/app/demo-app/todo/routes/routes.component.ts Outdated
@zygarios
Copy link
Copy Markdown

Pls, add option to set router tree vertical, not only horizontal

@sumitarora sumitarora force-pushed the feat-router-devtools branch 3 times, most recently from 4d63a1d to 3618607 Compare October 22, 2024 21:35
@sumitarora sumitarora force-pushed the feat-router-devtools branch 3 times, most recently from 523aaed to 00e541d Compare October 29, 2024 15:00
Copy link
Copy Markdown
Contributor

@dgp1130 dgp1130 left a comment

Choose a reason for hiding this comment

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

Thanks for these changes! It's looking a lot better already.

Is there anything we can do to write tests for some of the new additions? Maybe testing the new functionality in client-event-subscribers or router-tree.component / router-tree-visualizer?

I get that d3 probably isn't super conducive to unit testing, but even just making sure the right content was loaded and rendered at all goes a long way, even if we can't easily assert the exact layout of the graph.

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.

Suggestion: I think find would be more appropriate than filter here. Also should we check that we actually found a Router instance? Not everyone will have @angular/router installed.

Comment thread devtools/projects/ng-devtools-backend/src/lib/router-tree.ts Outdated
Comment thread devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.ts Outdated
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.

Consider: I think this can be marked protected?

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.

Consider: I think this can be protected too?

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.

Suggestion: Prefer boolean here as well (or just infer from false).

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.

Question: What about rendering multiple routes?

@sumitarora sumitarora force-pushed the feat-router-devtools branch 3 times, most recently from df1b144 to d2d3324 Compare November 2, 2024 03:53
Copy link
Copy Markdown
Contributor

@dgp1130 dgp1130 left a comment

Choose a reason for hiding this comment

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

Added a handful of minor suggestions, but nothing too major.

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.

Consider: We can simplify this with a spread operator: serializedProviderRecords.push(...nonMultiRecords);

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.

Nit: Unnecessary trailing space.

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.

Typo: DEFAULT_FILTER

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.

But I don't think ^ works after a .. What does "start of line" mean after a different character for a non-multiline regex?

IIUC:

  • .* would match anything.
  • ^. would match "starts a line with one character".
  • .^ would match "one character followed by the start of a line" which feels like it would be never? Playing around with this myself, I can't get it to match any string.

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.

Consider: The default case does new RegExp(DEFAULT_FILTER /* already a RegExp */). This seems to work, but maybe we should move the new RegExp into the non-default part of this condition to avoid duplicating the regex?

@sumitarora sumitarora force-pushed the feat-router-devtools branch from d2d3324 to 150d43f Compare November 8, 2024 20:28
@sumitarora sumitarora force-pushed the feat-router-devtools branch 3 times, most recently from c545ade to a29a356 Compare November 20, 2024 18:51
Copy link
Copy Markdown
Member

@AleksanderBodurri AleksanderBodurri Nov 25, 2024

Choose a reason for hiding this comment

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

nit: This seems very similar to getInjectorProvidersCallback. Can we consolidate the logic (we can use this helper function in the getInjectorProvidersCallback logic).

@dgp1130 dgp1130 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Nov 27, 2024
@dgp1130 dgp1130 added target: patch This PR is targeted for the next patch release and removed target: major This PR is targeted for the next major release labels Nov 27, 2024
@pkozlowski-opensource pkozlowski-opensource added target: minor This PR is targeted for the next minor release action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Nov 28, 2024
@pkozlowski-opensource
Copy link
Copy Markdown
Member

Adding cleanup label as it needs rebase

Follow-up PR for angular#58086 & angular#58199.

Adds below features to Angular DevTools to display router graph:
- Add a new router example in the Angular DevTools demo application.
- Implement the router graph in the Angular DevTools to view the routes that are loaded in the application.
@sumitarora sumitarora force-pushed the feat-router-devtools branch from a29a356 to f399068 Compare December 1, 2024 23:57
@sumitarora
Copy link
Copy Markdown
Contributor Author

@pkozlowski-opensource rebased and fixed conflicts.

- removed unused styles
- refactored tests and adding types
@sumitarora sumitarora force-pushed the feat-router-devtools branch from f399068 to 9887e94 Compare December 2, 2024 18:31
@dgp1130 dgp1130 added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Dec 2, 2024
@pkozlowski-opensource
Copy link
Copy Markdown
Member

This PR was merged into the repository by commit 42b1662.

The changes were merged into the following branches: main

pkozlowski-opensource pushed a commit that referenced this pull request Dec 3, 2024
…#58213)

- removed unused styles
- refactored tests and adding types

PR Close #58213
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jan 3, 2025
PrajaktaB27 pushed a commit to PrajaktaB27/angular that referenced this pull request Feb 7, 2025
…r#58213)

Follow-up PR for angular#58086 & angular#58199.

Adds below features to Angular DevTools to display router graph:
- Add a new router example in the Angular DevTools demo application.
- Implement the router graph in the Angular DevTools to view the routes that are loaded in the application.

PR Close angular#58213
PrajaktaB27 pushed a commit to PrajaktaB27/angular that referenced this pull request Feb 7, 2025
…angular#58213)

- removed unused styles
- refactored tests and adding types

PR Close angular#58213
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: devtools target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants