[ChromeNavPackage] Refactor to work with ChromeNavigationNode#156526
[ChromeNavPackage] Refactor to work with ChromeNavigationNode#156526sebelga merged 3 commits intoelastic:mainfrom
Conversation
| import { ChromeNavigationNodeViewModel } from '../../../types'; | ||
|
|
||
| export const analyticsItemSet: NavItemProps[] = [ | ||
| // TODO: Declare ChromeNavigationNode[] (with "link" to app id or deeplink id) |
There was a problem hiding this comment.
The idea is to not use href here but link. The same way links will be defined when calling the chrome.project.setNavigation(/*<config-with-nodes-and-links>*/).
This can be done as a second chunk of work to limit the changes in this PR.
| }, []); | ||
|
|
||
| return createSideNavData; | ||
| export const parseNavItems = ( |
There was a problem hiding this comment.
This utility handler is only in charge of building the path of each node and to remove any node that is not enabled.
The conversion to a MyEuiSideNavItem will occur at the component level (inside navigation_bucket.tsx)
| export const NavigationBucket = (opts: NavigationBucketProps) => { | ||
| const { id, items, activeNavItemId, ...props } = opts; | ||
| const { navIsOpen } = useNavigation(); | ||
| const navigationNodeToEuiItem = ( |
There was a problem hiding this comment.
This is where we convert our ChromeNavigationNodeViewModel to a EuiSideNavItemType to render the jsx.
| * Full path that points to this node (includes all parent ids). If not set | ||
| * the path is the id | ||
| */ | ||
| path?: string; |
There was a problem hiding this comment.
For what do you think this will be used?
Wouldn't path: string[] be more convenient?
Will this path include this node as the last item? or only parents?
There was a problem hiding this comment.
This path includes everything. We could keep an array, but at the same time we can always build the array later if needed.
const path: string = 'stackManagement.someIntermediateSection.indexManagement.someDeepLinkId'| */ | ||
| path?: string; | ||
| isActive?: boolean; | ||
| href?: string; |
There was a problem hiding this comment.
I think we should repeat what Chrome uses to generate the current side nav:
href is an absolute path used to enable right-click navigation/open in a new tab
url is a relative path used to call navigate() in onclick handler to prevent page reload
Basically I agree with an idea, but we will likely need to add more things here, I don't mind doing it as we go
There was a problem hiding this comment.
I like the idea. Not sure about naming but we can see later. I wonder if url for absolute and relativePath for navigate purpose?
There was a problem hiding this comment.
I don't think href needs to be an absolute path. You can still right-click the link and choose to open it in a new tab when you use a relative string for href. It should be fine to use the same string for the href attribute and navigating. Unless there is some corner case I'm not aware of. But that's how it worked in the POC.
|
I've tested the PR using @tsullivan PR for search navigation (#156465) and it works well except the active state. This was expected as the active route should be provided by the Chrome service. You can test it by creating this file inside the // nav.tsx
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { CoreStart } from '@kbn/core/public';
import {
Navigation,
NavigationKibanaProvider,
ChromeNavigationNodeViewModel,
} from '@kbn/shared-ux-chrome-navigation';
import React from 'react';
const navItems: ChromeNavigationNodeViewModel[] = [
{
title: '',
id: 'root',
items: [
{ id: 'overview', title: 'Overview', href: '/app/enterprise_search/overview' },
{ id: 'indices', title: 'Indices', href: '/app/enterprise_search/content/search_indices' },
{ id: 'engines', title: 'Engines', href: '/app/enterprise_search/content/engines' },
{ id: 'api_keys', title: 'API keys', href: '/app/management/security/api_keys' },
{
id: 'ingest_pipelines',
title: 'Ingest pipelines',
href: '/app/management/ingest/ingest_pipelines',
},
],
},
];
export const serverlessSearchSideNavComponentProvider = (core: CoreStart) => () =>
(
<NavigationKibanaProvider core={core}>
<Navigation
navigationTree={[
{
id: 'search_project_nav',
items: navItems,
title: 'Search',
icon: 'logoEnterpriseSearch',
},
]}
activeNavItemId="search_project_nav.root.overview"
platformConfig={{}}
homeHref="/app/enterprise_search/content/setup_guide"
linkToCloud="projects"
/>
</NavigationKibanaProvider>
);And then update the // public/plugin.ts
...
public start(
core: CoreStart,
_startDeps: ServerlessSearchPluginStartDependencies
): ServerlessSearchPluginStart {
core.chrome.project.setSideNavComponent(serverlessSearchSideNavComponentProvider(core));
return {};
} |
|
Pinging @elastic/appex-sharedux (Team:SharedUX) |
|
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Public APIs missing exports
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 |
In this PR I've refactored the
@kbn/shared-ux-chrome-navigationto (hopefully) simplify the data model. This is a preparation work to be able to expose an api on the core Chrome service to set the navigation.Goal
ChromeNavigationNodeChromeNavigationNodeViewModelChromeNavigationNodeViewModelto eui nav props at the component levelWhat it unblocks
ChromeNavigationNodeandChromeNavigationNodeViewModelwill be imported by the Chrome serviceChromeNavigationNode[]to aChromeNavigationNodeViewModel[]: converting thelink(pointing to appIds or deeplinkIds) to properthref