-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Endpoint] Task/add nav bar #58604
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
Merged
+134
−0
Merged
[Endpoint] Task/add nav bar #58604
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
db1e116
add nav bar
kevinlog b9b37d9
style, refactor
kevinlog 11db5b7
use EuiTabs, use onClick to push to history
kevinlog 69c0ecb
revert change
kevinlog 625635c
remove unused import
kevinlog 7d2d58a
i18n for nav names
kevinlog 09382af
add tests
kevinlog e90a9ac
Update x-pack/plugins/endpoint/public/applications/endpoint/component…
kevinlog 3e928f3
correct build, add href
kevinlog 9ae3933
Merge branch 'master' into task/add-nav-bar
elasticmachine 59e822d
fix type and typo
kevinlog d8425ec
Merge branch 'task/add-nav-bar' of github.com:kevinlog/kibana into ta…
kevinlog 94d5f0d
add basepath
kevinlog d9de5a7
adjust format
kevinlog 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
76 changes: 76 additions & 0 deletions
76
x-pack/plugins/endpoint/public/applications/endpoint/components/header_nav.tsx
This file contains hidden or 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,76 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import React, { MouseEvent } from 'react'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { EuiTabs, EuiTab } from '@elastic/eui'; | ||
| import { useHistory, useLocation } from 'react-router-dom'; | ||
|
|
||
| export interface NavTabs { | ||
| name: string; | ||
| id: string; | ||
| href: string; | ||
| } | ||
|
|
||
| export const navTabs: NavTabs[] = [ | ||
| { | ||
| id: 'home', | ||
| name: i18n.translate('xpack.endpoint.headerNav.home', { | ||
| defaultMessage: 'Home', | ||
| }), | ||
| href: '/', | ||
| }, | ||
| { | ||
| id: 'management', | ||
| name: i18n.translate('xpack.endpoint.headerNav.management', { | ||
| defaultMessage: 'Management', | ||
| }), | ||
| href: '/management', | ||
| }, | ||
| { | ||
| id: 'alerts', | ||
| name: i18n.translate('xpack.endpoint.headerNav.alerts', { | ||
| defaultMessage: 'Alerts', | ||
| }), | ||
| href: '/alerts', | ||
| }, | ||
| { | ||
| id: 'policies', | ||
| name: i18n.translate('xpack.endpoint.headerNav.policies', { | ||
| defaultMessage: 'Policies', | ||
| }), | ||
| href: '/policy', | ||
| }, | ||
| ]; | ||
|
|
||
| export const HeaderNavigation: React.FunctionComponent<{ basename: string }> = React.memo( | ||
| ({ basename }) => { | ||
| const history = useHistory(); | ||
| const location = useLocation(); | ||
|
|
||
| function renderNavTabs(tabs: NavTabs[]) { | ||
| return tabs.map((tab, index) => { | ||
| return ( | ||
| <EuiTab | ||
| data-testid={`${tab.id}EndpointTab`} | ||
| data-test-subj={`${tab.id}EndpointTab`} | ||
| key={index} | ||
| href={`${basename}${tab.href}`} | ||
| onClick={(event: MouseEvent) => { | ||
| event.preventDefault(); | ||
| history.push(tab.href); | ||
| }} | ||
| isSelected={tab.href === location.pathname} | ||
| > | ||
| {tab.name} | ||
| </EuiTab> | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| return <EuiTabs>{renderNavTabs(navTabs)}</EuiTabs>; | ||
| } | ||
| ); | ||
This file contains hidden or 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 hidden or 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,55 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import expect from '@kbn/expect'; | ||
| import { FtrProviderContext } from '../../ftr_provider_context'; | ||
|
|
||
| export default ({ getPageObjects, getService }: FtrProviderContext) => { | ||
| const pageObjects = getPageObjects(['common', 'endpoint']); | ||
| const testSubjects = getService('testSubjects'); | ||
|
|
||
| describe('Header nav', function() { | ||
| this.tags('ciGroup7'); | ||
| before(async () => { | ||
| await pageObjects.common.navigateToApp('endpoint'); | ||
| }); | ||
|
|
||
| it('renders the tabs when the app loads', async () => { | ||
| const homeTabText = await testSubjects.getVisibleText('homeEndpointTab'); | ||
| const managementTabText = await testSubjects.getVisibleText('managementEndpointTab'); | ||
| const alertsTabText = await testSubjects.getVisibleText('alertsEndpointTab'); | ||
| const policiesTabText = await testSubjects.getVisibleText('policiesEndpointTab'); | ||
|
|
||
| expect(homeTabText.trim()).to.be('Home'); | ||
| expect(managementTabText.trim()).to.be('Management'); | ||
| expect(alertsTabText.trim()).to.be('Alerts'); | ||
| expect(policiesTabText.trim()).to.be('Policies'); | ||
| }); | ||
|
|
||
| it('renders the management page when the Management tab is selected', async () => { | ||
| await (await testSubjects.find('managementEndpointTab')).click(); | ||
| await testSubjects.existOrFail('managementViewTitle'); | ||
| }); | ||
|
|
||
| it('renders the alerts page when the Alerts tab is selected', async () => { | ||
| await (await testSubjects.find('alertsEndpointTab')).click(); | ||
| await testSubjects.existOrFail('alertListPage'); | ||
| }); | ||
|
|
||
| it('renders the policy page when Policy tab is selected', async () => { | ||
| await (await testSubjects.find('policiesEndpointTab')).click(); | ||
| await testSubjects.existOrFail('policyViewTitle'); | ||
| }); | ||
|
|
||
| it('renders the home page when Home tab is selected after selecting another tab', async () => { | ||
| await (await testSubjects.find('managementEndpointTab')).click(); | ||
| await testSubjects.existOrFail('managementViewTitle'); | ||
|
|
||
| await (await testSubjects.find('homeEndpointTab')).click(); | ||
| await testSubjects.existOrFail('welcomeTitle'); | ||
| }); | ||
| }); | ||
| }; |
This file contains hidden or 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
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.
@paul-tavares does the
basePathconcern apply here as well?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.
@bkimmel no - here its ok because we're using this value against react-router which we initialize with a
basePath(the one provided during plugin initialization). So these should be (absolute) relative tobasePath