-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.12] [Observability][Infra] Add parent link in host detail's breadc…
…rumb (#170792) (#173735) # Backport This will backport the following commits from `main` to `8.12`: - [[Observability][Infra] Add parent link in host detail's breadcrumb (#170792)](#170792) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"ruhshan","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-12-20T12:38:57Z","message":"[Observability][Infra] Add parent link in host detail's breadcrumb (#170792)\n\n## Summary\r\n\r\nFixes #170642\r\n\r\nAdded link to hosts in the breadcrumb for host details page.\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/5312918/273c3b86-bfbd-485c-9bfe-92559caed847)\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by: Cauê Marcondes <[email protected]>\r\nCo-authored-by: jennypavlova <[email protected]>\r\nCo-authored-by: Kibana Machine <[email protected]>","sha":"fbd3601ced7ab4411d3a2d71a3f9fbe137696f48","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","💝community","v8.12.0","v8.13.0"],"number":170792,"url":"https://github.com/elastic/kibana/pull/170792","mergeCommit":{"message":"[Observability][Infra] Add parent link in host detail's breadcrumb (#170792)\n\n## Summary\r\n\r\nFixes #170642\r\n\r\nAdded link to hosts in the breadcrumb for host details page.\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/5312918/273c3b86-bfbd-485c-9bfe-92559caed847)\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by: Cauê Marcondes <[email protected]>\r\nCo-authored-by: jennypavlova <[email protected]>\r\nCo-authored-by: Kibana Machine <[email protected]>","sha":"fbd3601ced7ab4411d3a2d71a3f9fbe137696f48"}},"sourceBranch":"main","suggestedTargetBranches":["8.12"],"targetPullRequestStates":[{"branch":"8.12","label":"v8.12.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/170792","number":170792,"mergeCommit":{"message":"[Observability][Infra] Add parent link in host detail's breadcrumb (#170792)\n\n## Summary\r\n\r\nFixes #170642\r\n\r\nAdded link to hosts in the breadcrumb for host details page.\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/5312918/273c3b86-bfbd-485c-9bfe-92559caed847)\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by: Cauê Marcondes <[email protected]>\r\nCo-authored-by: jennypavlova <[email protected]>\r\nCo-authored-by: Kibana Machine <[email protected]>","sha":"fbd3601ced7ab4411d3a2d71a3f9fbe137696f48"}}]}] BACKPORT--> Co-authored-by: ruhshan <[email protected]>
- Loading branch information
1 parent
ddcf10b
commit e352a31
Showing
7 changed files
with
103 additions
and
19 deletions.
There are no files selected for viewing
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
59 changes: 59 additions & 0 deletions
59
.../plugins/infra/public/pages/metrics/metric_detail/hooks/use_parent_breadcrumb_resolver.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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { InventoryItemType } from '@kbn/metrics-data-access-plugin/common/inventory_models/types'; | ||
import { useLinkProps } from '@kbn/observability-shared-plugin/public'; | ||
import { useLocation } from 'react-router-dom'; | ||
import { hostsTitle, inventoryTitle } from '../../../../translations'; | ||
import { BreadcrumbOptions } from '../types'; | ||
|
||
interface LocationStateProps { | ||
originPathname: string; | ||
} | ||
|
||
export function useParentBreadcrumbResolver() { | ||
const hostsLinkProps = useLinkProps({ | ||
app: 'metrics', | ||
pathname: 'hosts', | ||
}); | ||
|
||
const inventoryLinkProps = useLinkProps({ | ||
app: 'metrics', | ||
pathname: 'inventory', | ||
}); | ||
|
||
const breadcrumbMap = new Map<string, BreadcrumbOptions>([ | ||
['/hosts', { text: hostsTitle, link: hostsLinkProps }], | ||
['/inventory', { text: inventoryTitle, link: inventoryLinkProps }], | ||
]); | ||
|
||
const defaultOption: BreadcrumbOptions = breadcrumbMap.get('/inventory')!; | ||
|
||
const { state } = useLocation(); | ||
const locationState: LocationStateProps = state as LocationStateProps; | ||
|
||
function getOptionsByNodeType(nodeType: InventoryItemType): BreadcrumbOptions { | ||
if (nodeType === 'host') { | ||
return breadcrumbMap.get('/hosts')!; | ||
} | ||
return defaultOption; | ||
} | ||
|
||
function getBreadcrumbOptions(nodeType: InventoryItemType) { | ||
if (locationState === undefined) { | ||
return getOptionsByNodeType(nodeType); | ||
} | ||
|
||
const originalPathBreadcrumb = locationState.originPathname | ||
? breadcrumbMap.get(locationState.originPathname) | ||
: undefined; | ||
|
||
return originalPathBreadcrumb ?? defaultOption; | ||
} | ||
|
||
return { getBreadcrumbOptions }; | ||
} |
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
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