-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[SharedUxChromeNavigation] Detect active nav route(s) #159906
[SharedUxChromeNavigation] Detect active nav route(s) #159906
Conversation
1e73505
to
af27ff8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Have some questions/suggestions. In the meantime, I'll start working on breadcrumbs and see if I have any more questions
@@ -107,6 +107,15 @@ export const NavigationSectionUI: FC<Props> = ({ | |||
|
|||
const groupHasLink = Boolean(navNode.deepLink) || Boolean(navNode.href); | |||
|
|||
useEffect(() => { | |||
// We only want to set the collapsed state during the "mounting" phase (500ms). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to track if the section was manually opened and in that case not auto-collapse it or something like this?
Or maybe possible to rely on the initial render?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is "the "mounting" phase" in this sense? Does this mean that initially "isActive" is incorrect? Why so? Can we make it correct on the first render?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think related #159906 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that initially "isActive" is incorrect? Why so?
I am not sure it would be possible or would require quite a complex logic.
The state order is:
isActive: false
- item register themselves in their parents
- the root
Navigation
component register the tree in the ChromeService - the ChromeService updates the
activeNodes
based on the navigation tree + the current location - the active nodes are returned to the
Navigation
- each node checks if it is active and updates the
isActive
state
That's why all node initially mount as isActive: false
and only after they are mounted the activeNodes
array is constructed.
is it possible to track if the section was manually opened and in that case not auto-collapse it or something like this?
It is not only when it was manually opened, also if it was opened automatically on page load because one of the children is active.
You can disable the if
statement around setIsCollapsed(!isActive);
and see for yourself why it is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically we don't want to close automatically a group that has been opened (manually or automatically).
packages/shared-ux/chrome/navigation/src/ui/components/navigation.tsx
Outdated
Show resolved
Hide resolved
packages/shared-ux/chrome/navigation/src/ui/components/navigation.tsx
Outdated
Show resolved
Hide resolved
...ore/chrome/core-chrome-browser-internal/src/project_navigation/project_navigation_service.ts
Outdated
Show resolved
Hide resolved
...ore/chrome/core-chrome-browser-internal/src/project_navigation/project_navigation_service.ts
Outdated
Show resolved
Hide resolved
packages/core/chrome/core-chrome-browser/src/project_navigation.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
limits.yml
…ga/kibana into chrome-nav/detect-active-nav-route
…-ref HEAD~1..HEAD --fix'
…ga/kibana into chrome-nav/detect-active-nav-route
Thanks for the review @Dosant ! I addressed all of your feedback, can you have another look? Cheers! |
...ore/chrome/core-chrome-browser-internal/src/project_navigation/project_navigation_service.ts
Outdated
Show resolved
Hide resolved
…ga/kibana into chrome-nav/detect-active-nav-route
…ga/kibana into chrome-nav/detect-active-nav-route
💚 Build Succeeded
Metrics [docs]Module Count
Public APIs missing comments
Async chunks
Public APIs missing exports
Page load bundle
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @sebelga |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested while working on breadcrumbs 👍
This PR add the active navigation detection in the side navigation.
getActiveNavigationNodes$()
The
serverless
plugin exposes a newgetActiveNavigationNodes$()
which returns the active nodes in the navigation tree based on the current browser location. The active node is the one with the longesturl
match.The result is a jagged array of branches of active nodes.
getIsActive()
It is possible to override the default matching mechanism and provide a handler to set the active state of a node. This handler is called whenever the location changes.
Note
There is an issue to change the style of the active state. This PR does not solve it as it should be done in EUI. We use the
isSelected
state declared on theitems
of the<EuiSideNav />
component. When this component is updated the new style will be applied here.Screenshot
Fixes #156664