From c6f72c764fbbf3fddd141ac6c47fa4120fc30b5d Mon Sep 17 00:00:00 2001 From: Carlos Crespo Date: Fri, 8 Sep 2023 15:05:45 +0200 Subject: [PATCH] [Infra UI] Propagate flyout state to node details page and some fixes (#165956) closes [#164300](https://github.com/elastic/kibana/issues/164300) ## Summary This PR enables state propagation between asset details flyout and full page view. https://github.com/elastic/kibana/assets/2767137/7e05a3c9-afa1-447c-98fd-91c40ee6cefb There are other places in Kibana that redirect to node details outside the infra plugin such as APM and Observability/Overview. They use the `link-to/${assetType}-detail` path, so It's best, for now, to keep retro-compatibility with this route and propagate the state via query string. I've also refactored how we were persisting state via route navigation, to use native the `state` attribute found in the `location` object from `react-router` ### How to tests - Start a Kibana instance - Navigate to `Infrastructure` > `Host` - Open the flyout, click in one of the tabs, and click on "Open as Page". The page should open in the same state as the flyout. --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../context/fixtures/asset_details_props.ts | 14 ++-- .../components/asset_details/constants.ts | 2 + .../asset_details/content/content.tsx | 30 ++++---- .../hooks/use_asset_details_render_props.ts | 6 +- .../hooks/use_asset_details_url_state.ts | 39 ++++++----- .../asset_details/hooks/use_date_range.ts | 25 +++---- .../asset_details/hooks/use_metadata_state.ts | 9 +++ .../asset_details/hooks/use_page_header.tsx | 16 ++--- .../asset_details/hooks/use_tab_switcher.tsx | 4 +- .../links/link_to_node_details.tsx | 25 ++++--- .../metadata_summary_list.tsx | 4 +- .../asset_details/template/flyout.tsx | 11 ++- .../public/components/asset_details/types.ts | 13 ++-- .../public/components/asset_details/utils.ts | 10 +++ .../components/metrics_node_details_link.tsx | 5 +- .../infra/public/pages/link_to/index.ts | 5 ++ .../public/pages/link_to/query_params.ts | 10 --- .../pages/link_to/redirect_to_node_detail.tsx | 67 ++++++++++-------- .../use_node_details_redirect.test.tsx | 37 ++++++++-- .../link_to/use_node_details_redirect.ts | 70 +++++++++++-------- .../components/host_details_flyout/tabs.ts | 14 ++-- .../hosts/components/table/entry_title.tsx | 15 ++-- .../metrics/hosts/hooks/use_hosts_table.tsx | 11 +-- .../infra/public/pages/metrics/index.tsx | 4 +- .../components/node_details/overlay.tsx | 6 +- .../components/waffle/node_context_menu.tsx | 6 +- .../metric_detail/asset_detail_page.tsx | 41 +++-------- .../pages/metrics/metric_detail/index.tsx | 14 ++-- .../metrics/metric_detail/page_providers.tsx | 21 ------ .../components/chart_context_menu.tsx | 5 +- .../public/hooks/use_link_props.ts | 7 +- 31 files changed, 284 insertions(+), 262 deletions(-) delete mode 100644 x-pack/plugins/infra/public/pages/metrics/metric_detail/page_providers.tsx diff --git a/x-pack/plugins/infra/public/components/asset_details/__stories__/context/fixtures/asset_details_props.ts b/x-pack/plugins/infra/public/components/asset_details/__stories__/context/fixtures/asset_details_props.ts index 05e17c16eb929..b6e35dbf51773 100644 --- a/x-pack/plugins/infra/public/components/asset_details/__stories__/context/fixtures/asset_details_props.ts +++ b/x-pack/plugins/infra/public/components/asset_details/__stories__/context/fixtures/asset_details_props.ts @@ -6,42 +6,42 @@ */ import { i18n } from '@kbn/i18n'; -import { type AssetDetailsProps, FlyoutTabIds, type Tab } from '../../../types'; +import { type AssetDetailsProps, ContentTabIds, type Tab } from '../../../types'; const links: AssetDetailsProps['links'] = ['alertRule', 'nodeDetails', 'apmServices']; const tabs: Tab[] = [ { - id: FlyoutTabIds.OVERVIEW, + id: ContentTabIds.OVERVIEW, name: i18n.translate('xpack.infra.nodeDetails.tabs.overview.title', { defaultMessage: 'Overview', }), }, { - id: FlyoutTabIds.LOGS, + id: ContentTabIds.LOGS, name: i18n.translate('xpack.infra.nodeDetails.tabs.logs', { defaultMessage: 'Logs', }), }, { - id: FlyoutTabIds.METADATA, + id: ContentTabIds.METADATA, name: i18n.translate('xpack.infra.metrics.nodeDetails.tabs.metadata', { defaultMessage: 'Metadata', }), }, { - id: FlyoutTabIds.PROCESSES, + id: ContentTabIds.PROCESSES, name: i18n.translate('xpack.infra.metrics.nodeDetails.tabs.processes', { defaultMessage: 'Processes', }), }, { - id: FlyoutTabIds.ANOMALIES, + id: ContentTabIds.ANOMALIES, name: i18n.translate('xpack.infra.nodeDetails.tabs.anomalies', { defaultMessage: 'Anomalies', }), }, { - id: FlyoutTabIds.LINK_TO_APM, + id: ContentTabIds.LINK_TO_APM, name: i18n.translate('xpack.infra.infra.nodeDetails.apmTabLabel', { defaultMessage: 'APM', }), diff --git a/x-pack/plugins/infra/public/components/asset_details/constants.ts b/x-pack/plugins/infra/public/components/asset_details/constants.ts index 726f47450d0cc..cdd5b95082158 100644 --- a/x-pack/plugins/infra/public/components/asset_details/constants.ts +++ b/x-pack/plugins/infra/public/components/asset_details/constants.ts @@ -8,3 +8,5 @@ export const ASSET_DETAILS_FLYOUT_COMPONENT_NAME = 'infraAssetDetailsFlyout'; export const METRIC_CHART_HEIGHT = 300; export const APM_HOST_FILTER_FIELD = 'host.hostname'; + +export const ASSET_DETAILS_URL_STATE_KEY = 'assetDetails'; diff --git a/x-pack/plugins/infra/public/components/asset_details/content/content.tsx b/x-pack/plugins/infra/public/components/asset_details/content/content.tsx index c9d622cf01493..0cf51f1fff3d7 100644 --- a/x-pack/plugins/infra/public/components/asset_details/content/content.tsx +++ b/x-pack/plugins/infra/public/components/asset_details/content/content.tsx @@ -10,7 +10,7 @@ import React from 'react'; import { DatePicker } from '../date_picker/date_picker'; import { useTabSwitcherContext } from '../hooks/use_tab_switcher'; import { Anomalies, Metadata, Processes, Osquery, Logs, Overview } from '../tabs'; -import { FlyoutTabIds } from '../types'; +import { ContentTabIds } from '../types'; export const Content = () => { return ( @@ -18,31 +18,31 @@ export const Content = () => { - + - + - + - + - + - + @@ -50,11 +50,11 @@ export const Content = () => { ); }; -const DatePickerWrapper = ({ visibleFor }: { visibleFor: FlyoutTabIds[] }) => { +const DatePickerWrapper = ({ visibleFor }: { visibleFor: ContentTabIds[] }) => { const { activeTabId } = useTabSwitcherContext(); return ( -