-
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
[SharedUx] Chrome/Navigation package #152510
Merged
tsullivan
merged 46 commits into
elastic:main
from
tsullivan:shared-ux/chrome/navigation
Apr 28, 2023
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
308b8f9
shared ux navigation package
tsullivan 45803c2
setNavIsOpen service
tsullivan de11016
refactor out navigation_buckets data modeling
tsullivan 33de083
setActiveNavitationItemId stubs
tsullivan 80a991d
add activeNavItemId$ observable
tsullivan 56256ab
fix home href
tsullivan 3df721d
fix logo link
tsullivan 30283c3
fix some mgmt links
tsullivan e843ca6
service to provide `getLocator`, not a wrapper
tsullivan 6e29bf6
Add registerNavItemClick to services
tsullivan b8ff745
href support, default activeNavId
tsullivan 20125e8
fill in some locator IDs
tsullivan 9154f32
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine a9bd56b
navigateToUrl
tsullivan 4539f64
loadingCount
tsullivan 5f922b6
simplify nav model methods
tsullivan 5c7fb71
fix anchor nesting
tsullivan 8021047
add link to cloud
tsullivan 33512d3
create single locators package
tsullivan 150066e
variable rename and comment
tsullivan 24c027a
Remove locators package
tsullivan c32666a
Remove reference to locators
tsullivan 817ec1f
replace configured locator objects with href strings
tsullivan 2c7f3db
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 3ff81ba
simple unit tests
tsullivan 1df05ee
Final nav items config fixes
tsullivan 044d768
remove stale fixme comment
tsullivan 36c17e0
remove descoped recent items integration
tsullivan c1168c4
Merge branch 'shared-ux/chrome/navigation' of github.com:tsullivan/ki…
tsullivan e1dfb32
fix commented code for investigating dark bg
tsullivan 94a3567
Merge branch 'main' into shared-ux/chrome/navigation
tsullivan 902759a
more recent items cleanup
tsullivan e45301d
more ts fix
tsullivan 07f26d8
fix todo
tsullivan 99af20a
add initial translatable strings
tsullivan ceab9d7
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 62f40d2
fix i18n issue
tsullivan 1fa1f88
Merge branch 'shared-ux/chrome/navigation' of github.com:tsullivan/ki…
tsullivan a3acb90
fix ts
tsullivan 8f5f601
Merge remote-tracking branch 'elastic/main' into shared-ux/chrome/nav…
tsullivan d1cd551
Remove services that will not be needed for future iteration
tsullivan f2bd9f8
Merge remote-tracking branch 'elastic/main' into shared-ux/chrome/nav…
tsullivan f9d53f8
Implement dark background
tsullivan 76427ee
use light mode for now
tsullivan 4257ba2
remove in-progress work on collapsed view
tsullivan 5fbb3fc
fix link to dashboards app
tsullivan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
id: sharedUX/Chrome/Navigation | ||
slug: /shared-ux/chrome/navigation | ||
title: Kibana Chrome Navigation | ||
description: Navigation container to render items for cross-app linking | ||
tags: ['shared-ux', 'component', 'chrome', 'navigation'] | ||
date: 2023-02-28 | ||
--- | ||
|
||
## Description | ||
|
||
Empty package generated by @kbn/generate | ||
@kbn/shared-ux-chrome-navigation | ||
Navigation container to render items for cross-app linking | ||
|
||
## API | ||
|
||
| Export | Description | | ||
|---|---| | ||
| `NavigationProvider` | Provides contextual services to `Navigation`. | | ||
| `NavigationKibanaProvider` | Maps Kibana dependencies to provide contextual services to `Navigation`. | | ||
| `Navigation` | Uses a `Provider` to access contextual services and render the component. | | ||
|
||
## EUI Promotion Status | ||
|
||
This component is not currently considered for promotion to EUI. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { NavigationKibanaProvider, NavigationProvider } from './src/services'; | ||
export { Navigation } from './src/ui/navigation'; | ||
export type { NavigationProps, NavigationServices, NavItemProps } from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../../..', | ||
roots: ['<rootDir>/packages/shared-ux/chrome/navigation'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/shared-ux-chrome-navigation", | ||
"owner": "@elastic/appex-sharedux" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { | ||
getServicesMock as getNavigationServicesMock, | ||
getSolutionPropertiesMock, | ||
} from './src/jest'; | ||
export { StorybookMock as NavigationStorybookMock } from './src/storybook'; | ||
export type { Params as NavigationStorybookParams } from './src/storybook'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { NavigationServices, SolutionProperties } from '../../types'; | ||
|
||
export const getServicesMock = (): NavigationServices => { | ||
const navigateToUrl = jest.fn().mockResolvedValue(undefined); | ||
const basePath = { prepend: jest.fn((path: string) => `/base${path}`) }; | ||
const loadingCount = 0; | ||
|
||
return { | ||
basePath, | ||
loadingCount, | ||
navIsOpen: true, | ||
navigateToUrl, | ||
}; | ||
}; | ||
|
||
export const getSolutionPropertiesMock = (): SolutionProperties => ({ | ||
id: 'example_project', | ||
icon: 'logoObservability', | ||
name: 'Example project', | ||
items: [ | ||
{ | ||
id: 'root', | ||
name: '', | ||
items: [ | ||
{ | ||
id: 'get_started', | ||
name: 'Get started', | ||
href: '/app/example_project/get_started', | ||
}, | ||
{ | ||
id: 'alerts', | ||
name: 'Alerts', | ||
href: '/app/example_project/alerts', | ||
}, | ||
{ | ||
id: 'cases', | ||
name: 'Cases', | ||
href: '/app/example_project/cases', | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'example_settings', | ||
name: 'Settings', | ||
items: [ | ||
{ | ||
id: 'logs', | ||
name: 'Logs', | ||
href: '/app/management/logs', | ||
}, | ||
{ | ||
id: 'signals', | ||
name: 'Signals', | ||
href: '/app/management/signals', | ||
}, | ||
{ | ||
id: 'tracing', | ||
name: 'Tracing', | ||
href: '/app/management/tracing', | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
59 changes: 59 additions & 0 deletions
59
packages/shared-ux/chrome/navigation/mocks/src/storybook.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { AbstractStorybookMock } from '@kbn/shared-ux-storybook-mock'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { NavigationProps, NavigationServices } from '../../types'; | ||
|
||
type Arguments = NavigationProps & NavigationServices; | ||
export type Params = Pick< | ||
Arguments, | ||
'activeNavItemId' | 'loadingCount' | 'navIsOpen' | 'platformConfig' | 'solutions' | ||
>; | ||
|
||
export class StorybookMock extends AbstractStorybookMock<NavigationProps, NavigationServices> { | ||
propArguments = {}; | ||
|
||
serviceArguments = { | ||
navIsOpen: { | ||
control: 'boolean', | ||
defaultValue: true, | ||
}, | ||
loadingCount: { | ||
control: 'number', | ||
defaultValue: 0, | ||
}, | ||
}; | ||
|
||
dependencies = []; | ||
|
||
getServices(params: Params): NavigationServices { | ||
const { navIsOpen } = params; | ||
|
||
const navAction = action('Navigate to'); | ||
const navigateToUrl = (url: string) => { | ||
navAction(url); | ||
return Promise.resolve(); | ||
}; | ||
|
||
return { | ||
...params, | ||
basePath: { prepend: (suffix: string) => `/basepath${suffix}` }, | ||
navigateToUrl, | ||
navIsOpen, | ||
}; | ||
} | ||
|
||
getProps(params: Params): NavigationProps { | ||
return { | ||
...params, | ||
homeHref: '#', | ||
linkToCloud: 'projects', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@kbn/shared-ux-chrome-navigation", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "SSPL-1.0 OR Elastic License 2.0" | ||
} |
77 changes: 77 additions & 0 deletions
77
packages/shared-ux/chrome/navigation/src/model/create_side_nav.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { EuiSideNavItemType } from '@elastic/eui'; | ||
import type { NavigationModelDeps } from '.'; | ||
import type { NavItemProps, PlatformSectionConfig } from '../../types'; | ||
|
||
type MyEuiSideNavItem = EuiSideNavItemType<unknown>; | ||
type OnClickFn = MyEuiSideNavItem['onClick']; | ||
|
||
/** | ||
* Factory function to return a function that processes modeled nav items into EuiSideNavItemType | ||
* The factory puts memoized function arguments in scope for iterations of the recursive item processing. | ||
*/ | ||
export const createSideNavDataFactory = ( | ||
deps: NavigationModelDeps, | ||
activeNavItemId: string | undefined | ||
) => { | ||
const { basePath, navigateToUrl } = deps; | ||
const createSideNavData = ( | ||
parentIds: string | number = '', | ||
navItems: NavItemProps[], | ||
platformSectionConfig?: PlatformSectionConfig | ||
): Array<EuiSideNavItemType<unknown>> => | ||
navItems.reduce<MyEuiSideNavItem[]>((accum, item) => { | ||
const { id, name, items: subNav, href } = item; | ||
const config = platformSectionConfig?.properties?.[id]; | ||
if (config?.enabled === false) { | ||
// return accumulated set without the item that is not enabled | ||
return accum; | ||
} | ||
|
||
let onClick: OnClickFn | undefined; | ||
|
||
const fullId = [parentIds, id].filter(Boolean).join('.'); | ||
|
||
if (href) { | ||
onClick = (event: React.MouseEvent) => { | ||
event.preventDefault(); | ||
navigateToUrl(basePath.prepend(href)); | ||
}; | ||
} | ||
|
||
let filteredSubNav: MyEuiSideNavItem[] | undefined; | ||
if (subNav) { | ||
// recursion | ||
const nextConfig = platformSectionConfig?.properties?.[id]; | ||
filteredSubNav = createSideNavData(fullId, subNav, nextConfig); | ||
} | ||
|
||
let isSelected: boolean = false; | ||
let subjId = fullId; | ||
if (!subNav && fullId === activeNavItemId) { | ||
// if there are no subnav items and ID is current, mark the item as selected | ||
isSelected = true; | ||
subjId += '-selected'; | ||
} | ||
|
||
const next: MyEuiSideNavItem = { | ||
id: fullId, | ||
name, | ||
isSelected, | ||
onClick, | ||
href, | ||
items: filteredSubNav, | ||
['data-test-subj']: `nav-item-${subjId}`, | ||
}; | ||
return [...accum, next]; | ||
}, []); | ||
|
||
return createSideNavData; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { BasePathService, NavigateToUrlFn } from '../../types/internal'; | ||
import { analyticsItemSet } from './platform_nav/analytics'; | ||
import { devtoolsItemSet } from './platform_nav/devtools'; | ||
import { mlItemSet } from './platform_nav/machine_learning'; | ||
import { managementItemSet } from './platform_nav/management'; | ||
|
||
export interface NavigationModelDeps { | ||
basePath: BasePathService; | ||
navigateToUrl: NavigateToUrlFn; | ||
} | ||
|
||
/** | ||
* @public | ||
*/ | ||
export enum Platform { | ||
Recents = 'recents', | ||
Analytics = 'analytics', | ||
MachineLearning = 'ml', | ||
DevTools = 'devTools', | ||
Management = 'management', | ||
} | ||
|
||
/** | ||
* @public | ||
*/ | ||
export const navItemSet = { | ||
[Platform.Analytics]: analyticsItemSet, | ||
[Platform.MachineLearning]: mlItemSet, | ||
[Platform.DevTools]: devtoolsItemSet, | ||
[Platform.Management]: managementItemSet, | ||
}; | ||
|
||
export { NavigationModel } from './model'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🙇♂️