-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Changes from 21 commits
e53c650
b3dd5d3
4ea8b09
4ca752d
50cc230
12c7820
a4166c0
66c356f
80e772a
21fa65d
9c6893c
247702b
4e2fd39
a801588
88968d8
98b9124
b084fb7
2245f97
5c9b6d5
525c577
e548f25
95a5de0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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]); | ||
}; |
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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 { mount } from 'enzyme'; | ||
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(), | ||
})); | ||
|
||
describe('PageError component', () => { | ||
const mountError = (name: string, error: InfraHttpError) => | ||
mount( | ||
<I18nProvider> | ||
<PageError name={name} error={error} /> | ||
</I18nProvider> | ||
).find('PageError'); | ||
|
||
it('renders correctly and set title', () => { | ||
const mounted = mountError('test', { | ||
body: { | ||
statusCode: 500, | ||
message: 'Error Message', | ||
}, | ||
message: 'Error Message', | ||
} as InfraHttpError); | ||
|
||
const callOut = mounted.find('EuiCallOut'); | ||
expect(callOut.render()).toMatchSnapshot(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of matching a snapshot, how about if we just assert the existence of the "Please click the back button and try again." on the page? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the snapshot and I added a check for the error name and message |
||
|
||
expect(useDocumentTitle).toHaveBeenCalledWith([{ text: `${errorTitle}` }]); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to add a test for this one! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} /> | ||
) : ( | ||
|
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.
Enzyme works just fine, especially if we need to play with component internals and state. In this case we don't need to do that so I believe we could use react-testing-library. What do you think?
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.
That's a good point, thank you. I agree, I realize that we don't actually need to change the internal state there - just to test if the hook is called and the text error message is correct. I updated it 👍