Skip to content
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

[Infra Monitoring UI] Change infrastructure pages titles to use breadcrumbs #135874 #140824

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e53c650
Use breadcrumbs to set page title intead of DocumentTitle
jennypavlova Sep 14, 2022
b3dd5d3
Remove document title component and use breadcrumbs - Logs Page
jennypavlova Sep 15, 2022
4ea8b09
Remove no longer needed document title translations
jennypavlova Sep 19, 2022
4ca752d
Use docTitle.change in error page and remove document title component
jennypavlova Sep 21, 2022
50cc230
Add document title check to the functional tests
jennypavlova Sep 22, 2022
12c7820
Move test to check title after load
jennypavlova Sep 22, 2022
a4166c0
test: Title change
jennypavlova Sep 22, 2022
66c356f
Merge branch 'main' into 135874-change-infrastructure-pages-titles-to…
jennypavlova Sep 23, 2022
80e772a
Merge branch 'main' into 135874-change-infrastructure-pages-titles-to…
jennypavlova Sep 26, 2022
21fa65d
Merge branch 'main' into 135874-change-infrastructure-pages-titles-to…
kibanamachine Sep 26, 2022
9c6893c
Merge branch 'main' into 135874-change-infrastructure-pages-titles-to…
kibanamachine Sep 27, 2022
247702b
Remove unnecessary docTitle type
jennypavlova Sep 27, 2022
4e2fd39
Add error page tests
jennypavlova Sep 27, 2022
a801588
Merge branch 'main' into 135874-change-infrastructure-pages-titles-to…
jennypavlova Sep 27, 2022
88968d8
Update snapshot
jennypavlova Sep 27, 2022
98b9124
Merge branch 'main' into 135874-change-infrastructure-pages-titles-to…
jennypavlova Sep 27, 2022
b084fb7
Merge branch 'main' into 135874-change-infrastructure-pages-titles-to…
jennypavlova Sep 27, 2022
2245f97
Functional tests: Wait for loading the header before checking the title
jennypavlova Sep 27, 2022
5c9b6d5
Merge branch 'main' into 135874-change-infrastructure-pages-titles-to…
jennypavlova Sep 27, 2022
525c577
Merge branch 'main' into 135874-change-infrastructure-pages-titles-to…
jennypavlova Sep 27, 2022
e548f25
Merge branch 'main' into 135874-change-infrastructure-pages-titles-to…
jennypavlova Sep 28, 2022
95a5de0
Change test to use react testing library
jennypavlova Sep 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/plugins/infra/public/apps/metrics_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const renderApp = (
);

return () => {
core.chrome.docTitle.reset();
ReactDOM.unmountComponentAtNode(element);
plugins.data.search.session.clear();
};
Expand Down
72 changes: 0 additions & 72 deletions x-pack/plugins/infra/public/components/document_title.tsx

This file was deleted.

9 changes: 7 additions & 2 deletions x-pack/plugins/infra/public/hooks/use_breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useBreadcrumbs = (app: AppId, appTitle: string, extraCrumbs: Chrome
const appLinkProps = useLinkProps({ app });

useEffect(() => {
chrome?.setBreadcrumbs?.([
const breadcrumbs = [
{
...observabilityLinkProps,
text: observabilityTitle,
Expand All @@ -32,6 +32,11 @@ export const useBreadcrumbs = (app: AppId, appTitle: string, extraCrumbs: Chrome
text: appTitle,
},
...extraCrumbs,
]);
];

const docTitle = [...breadcrumbs].reverse().map((breadcrumb) => breadcrumb.text as string);

chrome.docTitle.change(docTitle);
chrome.setBreadcrumbs(breadcrumbs);
}, [appLinkProps, appTitle, chrome, extraCrumbs, observabilityLinkProps]);
};
25 changes: 25 additions & 0 deletions x-pack/plugins/infra/public/hooks/use_document_title.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 '@kbn/core/public';
import { useEffect } from 'react';
import { observabilityTitle } from '../translations';
import { useKibanaContextForPlugin } from './use_kibana';

export const useDocumentTitle = (extraTitles: ChromeBreadcrumb[]) => {
const {
services: { chrome },
} = useKibanaContextForPlugin();

useEffect(() => {
const docTitle = [{ text: observabilityTitle }, ...extraTitles]
.reverse()
.map((breadcrumb) => breadcrumb.text as string);

chrome.docTitle.change(docTitle);
}, [chrome, extraTitles]);
};
3 changes: 0 additions & 3 deletions x-pack/plugins/infra/public/pages/logs/page_content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Route, Switch } from 'react-router-dom';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { HeaderMenuPortal, useLinkProps } from '@kbn/observability-plugin/public';
import { AlertDropdown } from '../../alerting/log_threshold';
import { DocumentTitle } from '../../components/document_title';
import { HelpCenterContent } from '../../components/help_center_content';
import { useReadOnlyBadge } from '../../hooks/use_readonly_badge';
import { HeaderActionMenuContext } from '../../utils/header_action_menu_provider';
Expand Down Expand Up @@ -62,8 +61,6 @@ export const LogsPageContent: React.FunctionComponent = () => {

return (
<>
<DocumentTitle title={pageTitle} />

<HelpCenterContent feedbackLink={feedbackLinkUrl} appName={pageTitle} />

{setHeaderActionMenu && theme$ && (
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/infra/public/pages/logs/stream/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import React from 'react';
import { useTrackPageview } from '@kbn/observability-plugin/public';
import { useLogsBreadcrumbs } from '../../../hooks/use_logs_breadcrumbs';
import { StreamPageContent } from './page_content';
import { StreamPageHeader } from './page_header';
import { LogsPageProviders } from './page_providers';
import { streamTitle } from '../../../translations';

Expand All @@ -26,7 +25,6 @@ export const StreamPage = () => {
return (
<EuiErrorBoundary>
<LogsPageProviders>
<StreamPageHeader />
<StreamPageContent />
</LogsPageProviders>
</EuiErrorBoundary>
Expand Down
28 changes: 0 additions & 28 deletions x-pack/plugins/infra/public/pages/logs/stream/page_header.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions x-pack/plugins/infra/public/pages/metrics/hosts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
*/

import { EuiErrorBoundary } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { useTrackPageview } from '@kbn/observability-plugin/public';
import { APP_WRAPPER_CLASS } from '@kbn/core/public';

import { DocumentTitle } from '../../../components/document_title';

import { SourceErrorPage } from '../../../components/source_error_page';
import { SourceLoadingPage } from '../../../components/source_loading_page';
import { useSourceContext } from '../../../containers/metrics_source';
Expand Down Expand Up @@ -42,16 +39,6 @@ export const HostsPage = () => {
]);
return (
<EuiErrorBoundary>
<DocumentTitle
title={(previousTitle: string) =>
i18n.translate('xpack.infra.infrastructureHostsPage.documentTitle', {
defaultMessage: '{previousTitle} | Hosts',
values: {
previousTitle,
},
})
}
/>
{isLoading && !source ? (
<SourceLoadingPage />
) : metricIndicesExist && source ? (
Expand Down
7 changes: 0 additions & 7 deletions x-pack/plugins/infra/public/pages/metrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { useKibana } from '@kbn/kibana-react-plugin/public';
import { HeaderMenuPortal } from '@kbn/observability-plugin/public';
import { useLinkProps } from '@kbn/observability-plugin/public';
import { MetricsSourceConfigurationProperties } from '../../../common/metrics_sources';
import { DocumentTitle } from '../../components/document_title';
import { HelpCenterContent } from '../../components/help_center_content';
import { useReadOnlyBadge } from '../../hooks/use_readonly_badge';
import {
Expand Down Expand Up @@ -73,12 +72,6 @@ export const InfrastructurePage = ({ match }: RouteComponentProps) => {
<WaffleTimeProvider>
<WaffleFiltersProvider>
<InfraMLCapabilitiesProvider>
<DocumentTitle
title={i18n.translate('xpack.infra.homePage.documentTitle', {
defaultMessage: 'Metrics',
})}
/>

<HelpCenterContent
feedbackLink="https://discuss.elastic.co/c/metrics"
appName={i18n.translate('xpack.infra.header.infrastructureHelpAppName', {
Expand Down
14 changes: 0 additions & 14 deletions x-pack/plugins/infra/public/pages/metrics/inventory_view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
*/

import { EuiErrorBoundary } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { useTrackPageview } from '@kbn/observability-plugin/public';
import { APP_WRAPPER_CLASS } from '@kbn/core/public';
import { FilterBar } from './components/filter_bar';

import { DocumentTitle } from '../../../components/document_title';

import { SourceErrorPage } from '../../../components/source_error_page';
import { SourceLoadingPage } from '../../../components/source_loading_page';
import { useSourceContext } from '../../../containers/metrics_source';
Expand Down Expand Up @@ -49,16 +45,6 @@ export const SnapshotPage = () => {

return (
<EuiErrorBoundary>
<DocumentTitle
title={(previousTitle: string) =>
i18n.translate('xpack.infra.infrastructureSnapshotPage.documentTitle', {
defaultMessage: '{previousTitle} | Inventory',
values: {
previousTitle,
},
})
}
/>
{isLoading && !source ? (
<SourceLoadingPage />
) : metricIndicesExist ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 React from 'react';
import { render } from '@testing-library/react';

import { PageError } from './page_error';
import { errorTitle } from '../../../../translations';
import { InfraHttpError } from '../../../../types';
import { useDocumentTitle } from '../../../../hooks/use_document_title';
import { I18nProvider } from '@kbn/i18n-react';

jest.mock('../../../../hooks/use_document_title', () => ({
useDocumentTitle: jest.fn(),
}));

const renderErrorPage = () =>
render(
<I18nProvider>
<PageError
name={'test'}
error={
{
body: {
statusCode: 500,
message: 'Error Message',
},
message: 'Error Message',
} as InfraHttpError
}
/>
</I18nProvider>
);

describe('PageError component', () => {
it('renders correctly and set title', () => {
const { getByText } = renderErrorPage();
expect(useDocumentTitle).toHaveBeenCalledWith([{ text: `${errorTitle}` }]);

expect(getByText('Error Message')).toBeInTheDocument();
expect(getByText('Please click the back button and try again.')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,22 @@
*/

import React from 'react';
import { i18n } from '@kbn/i18n';
import { useDocumentTitle } from '../../../../hooks/use_document_title';
import { InvalidNodeError } from './invalid_node';
import { DocumentTitle } from '../../../../components/document_title';
import { ErrorPageBody } from '../../../error';
import { InfraHttpError } from '../../../../types';
import { errorTitle } from '../../../../translations';

interface Props {
name: string;
error: InfraHttpError;
}

export const PageError = ({ error, name }: Props) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add a test for this one!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added one unit test for the error page component and a functional test 4e2fd39

useDocumentTitle([{ text: errorTitle }]);

return (
<>
<DocumentTitle
title={(previousTitle: string) =>
i18n.translate('xpack.infra.metricDetailPage.documentTitleError', {
defaultMessage: '{previousTitle} | Uh oh',
values: {
previousTitle,
},
})
}
/>
{error.body?.statusCode === 404 ? (
<InvalidNodeError nodeName={name} />
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { i18n } from '@kbn/i18n';
import React, { useState } from 'react';
import { EuiTheme, withTheme } from '@kbn/kibana-react-plugin/common';
import { useLinkProps } from '@kbn/observability-plugin/public';
import { DocumentTitle } from '../../../components/document_title';
import { withMetricPageProviders } from './page_providers';
import { useMetadata } from './hooks/use_metadata';
import { useMetricsBreadcrumbs } from '../../../hooks/use_metrics_breadcrumbs';
Expand Down Expand Up @@ -100,14 +99,6 @@ export const MetricDetail = withMetricPageProviders(

return (
<>
<DocumentTitle
title={i18n.translate('xpack.infra.metricDetailPage.documentTitle', {
defaultMessage: 'Infrastructure | Metrics | {name}',
values: {
name,
},
})}
/>
{metadata ? (
<NodeDetailsPage
name={name}
Expand Down
Loading