-
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.
[Logs & Metrics] refactor breadcrumbs (#103249)
* [Logs & Metrics] refactor breadcrumbs * [Logs & Metrics] remove Header component, move translations and create readonly badge hook * add breadcrumb to metric detail page * fix check_file_casing ci issues * create separate breadcrumb hook for logs and metrics * fix metrics translation title * fix wrong imports and unused variables * fix translation imports * fix unused import * refactor use_breadcrumbs * remove Header component * fix linter exhaustive-deps error by wrapping into useMemo * refactor use_readonly_badge * remove commented out code Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
1b75ac5
commit ba85f45
Showing
19 changed files
with
222 additions
and
117 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,37 @@ | ||
/* | ||
* 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 { ChromeBreadcrumb } from 'kibana/public'; | ||
import { useEffect } from 'react'; | ||
import { observabilityTitle } from '../translations'; | ||
import { useKibanaContextForPlugin } from './use_kibana'; | ||
import { useLinkProps } from './use_link_props'; | ||
|
||
type AppId = 'logs' | 'metrics'; | ||
|
||
export const useBreadcrumbs = (app: AppId, appTitle: string, extraCrumbs: ChromeBreadcrumb[]) => { | ||
const { | ||
services: { chrome }, | ||
} = useKibanaContextForPlugin(); | ||
|
||
const observabilityLinkProps = useLinkProps({ app: 'observability-overview' }); | ||
const appLinkProps = useLinkProps({ app }); | ||
|
||
useEffect(() => { | ||
chrome?.setBreadcrumbs?.([ | ||
{ | ||
...observabilityLinkProps, | ||
text: observabilityTitle, | ||
}, | ||
{ | ||
...appLinkProps, | ||
text: appTitle, | ||
}, | ||
...extraCrumbs, | ||
]); | ||
}, [appLinkProps, appTitle, chrome, extraCrumbs, observabilityLinkProps]); | ||
}; |
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/infra/public/hooks/use_logs_breadcrumbs.tsx
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,15 @@ | ||
/* | ||
* 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 { ChromeBreadcrumb } from 'kibana/public'; | ||
import { useBreadcrumbs } from './use_breadcrumbs'; | ||
import { LOGS_APP } from '../../common/constants'; | ||
import { logsTitle } from '../translations'; | ||
|
||
export const useLogsBreadcrumbs = (extraCrumbs: ChromeBreadcrumb[]) => { | ||
useBreadcrumbs(LOGS_APP, logsTitle, extraCrumbs); | ||
}; |
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/infra/public/hooks/use_metrics_breadcrumbs.tsx
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,15 @@ | ||
/* | ||
* 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 { ChromeBreadcrumb } from 'kibana/public'; | ||
import { useBreadcrumbs } from './use_breadcrumbs'; | ||
import { METRICS_APP } from '../../common/constants'; | ||
import { metricsTitle } from '../translations'; | ||
|
||
export const useMetricsBreadcrumbs = (extraCrumbs: ChromeBreadcrumb[]) => { | ||
useBreadcrumbs(METRICS_APP, metricsTitle, extraCrumbs); | ||
}; |
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,32 @@ | ||
/* | ||
* 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 { useEffect } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { useKibana } from '../../../../../src/plugins/kibana_react/public'; | ||
|
||
export const useReadOnlyBadge = (isReadOnly = false) => { | ||
const chrome = useKibana().services.chrome; | ||
|
||
useEffect(() => { | ||
chrome?.setBadge( | ||
isReadOnly | ||
? { | ||
text: i18n.translate('xpack.infra.header.badge.readOnly.text', { | ||
defaultMessage: 'Read only', | ||
}), | ||
tooltip: i18n.translate('xpack.infra.header.badge.readOnly.tooltip', { | ||
defaultMessage: 'Unable to change source configuration', | ||
}), | ||
iconType: 'glasses', | ||
} | ||
: undefined | ||
); | ||
}, [chrome, isReadOnly]); | ||
|
||
return null; | ||
}; |
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
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
Oops, something went wrong.