mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Discover] Redirect to main page when route not found (#113678)
* [Discover] redirect to main page on route not found discover error * [Discover] remove services from dependencies * [Discover] apply suggestions * [Discover] return invalid link, but make it not clickable Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
32f4a6c950
commit
2c8686770e
2 changed files with 28 additions and 8 deletions
|
@ -9,6 +9,7 @@ import React, { useEffect } from 'react';
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import { EuiCallOut } from '@elastic/eui';
|
||||
import { FormattedMessage } from '@kbn/i18n/react';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import { toMountPoint } from '../../../../../kibana_react/public';
|
||||
import { DiscoverServices } from '../../../build_services';
|
||||
import { getUrlTracker } from '../../../kibana_services';
|
||||
|
@ -23,7 +24,8 @@ let bannerId: string | undefined;
|
|||
|
||||
export function NotFoundRoute(props: NotFoundRouteProps) {
|
||||
const { services } = props;
|
||||
const { urlForwarding } = services;
|
||||
const { urlForwarding, core, history } = services;
|
||||
const currentLocation = history().location.pathname;
|
||||
|
||||
useEffect(() => {
|
||||
const path = window.location.hash.substr(1);
|
||||
|
@ -34,14 +36,17 @@ export function NotFoundRoute(props: NotFoundRouteProps) {
|
|||
defaultMessage: 'Page not found',
|
||||
});
|
||||
|
||||
bannerId = services.core.overlays.banners.replace(
|
||||
bannerId = core.overlays.banners.replace(
|
||||
bannerId,
|
||||
toMountPoint(
|
||||
<EuiCallOut color="warning" iconType="iInCircle" title={bannerMessage}>
|
||||
<p>
|
||||
<p data-test-subj="invalidRouteMessage">
|
||||
<FormattedMessage
|
||||
id="discover.noMatchRoute.bannerText"
|
||||
defaultMessage="Invalid URL for Discover application."
|
||||
defaultMessage="Discover application doesn't recognize this route: {route}"
|
||||
values={{
|
||||
route: history().location.state.referrer,
|
||||
}}
|
||||
/>
|
||||
</p>
|
||||
</EuiCallOut>
|
||||
|
@ -51,10 +56,10 @@ export function NotFoundRoute(props: NotFoundRouteProps) {
|
|||
// hide the message after the user has had a chance to acknowledge it -- so it doesn't permanently stick around
|
||||
setTimeout(() => {
|
||||
if (bannerId) {
|
||||
services.core.overlays.banners.remove(bannerId);
|
||||
core.overlays.banners.remove(bannerId);
|
||||
}
|
||||
}, 15000);
|
||||
}, [services.core.overlays.banners, services.history, urlForwarding]);
|
||||
}, [core.overlays.banners, history, urlForwarding]);
|
||||
|
||||
return null;
|
||||
return <Redirect to={{ pathname: '/', state: { referrer: currentLocation } }} />;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,8 @@ import { FtrProviderContext } from '../../ftr_provider_context';
|
|||
export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
||||
const esArchiver = getService('esArchiver');
|
||||
const toasts = getService('toasts');
|
||||
const PageObjects = getPageObjects(['common', 'discover', 'timePicker']);
|
||||
const testSubjects = getService('testSubjects');
|
||||
const PageObjects = getPageObjects(['common', 'header', 'discover', 'timePicker']);
|
||||
|
||||
describe('errors', function describeIndexTests() {
|
||||
before(async function () {
|
||||
|
@ -33,5 +34,19 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|||
expect(painlessStackTrace).not.to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('not found', () => {
|
||||
it('should redirect to main page when trying to access invalid route', async () => {
|
||||
await PageObjects.common.navigateToUrl('discover', '#/invalid-route', {
|
||||
useActualUrl: true,
|
||||
});
|
||||
await PageObjects.header.awaitKibanaChrome();
|
||||
|
||||
const invalidLink = await testSubjects.find('invalidRouteMessage');
|
||||
expect(await invalidLink.getVisibleText()).to.be(
|
||||
`Discover application doesn't recognize this route: /invalid-route`
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue