mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[DataViews] fix behavior for loading a missing data view (#139044)
* [DataViews] fix behavior for loading a missing data view * remove link text from error message * add functional test * update error toast notification title * cleanups * update content and add toastMessage * revert change to error message params * update content per feedback * error might be null-ish * fix bug
This commit is contained in:
parent
220578bf48
commit
348d59c92d
3 changed files with 75 additions and 14 deletions
|
@ -6,31 +6,53 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { withRouter, RouteComponentProps } from 'react-router-dom';
|
||||
import { DataView } from '@kbn/data-views-plugin/public';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { useKibana } from '@kbn/kibana-react-plugin/public';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { RouteComponentProps, withRouter } from 'react-router-dom';
|
||||
import { EditIndexPattern } from '.';
|
||||
import { IndexPatternManagmentContext } from '../../types';
|
||||
import { getEditBreadcrumbs } from '../breadcrumbs';
|
||||
|
||||
import { EditIndexPattern } from '.';
|
||||
|
||||
const EditIndexPatternCont: React.FC<RouteComponentProps<{ id: string }>> = ({ ...props }) => {
|
||||
const { dataViews, setBreadcrumbs } = useKibana<IndexPatternManagmentContext>().services;
|
||||
const { dataViews, setBreadcrumbs, notifications } =
|
||||
useKibana<IndexPatternManagmentContext>().services;
|
||||
const [error, setError] = useState<Error | undefined>();
|
||||
const [indexPattern, setIndexPattern] = useState<DataView>();
|
||||
|
||||
useEffect(() => {
|
||||
dataViews.get(props.match.params.id).then((ip: DataView) => {
|
||||
setIndexPattern(ip);
|
||||
setBreadcrumbs(getEditBreadcrumbs(ip));
|
||||
});
|
||||
}, [dataViews, props.match.params.id, setBreadcrumbs]);
|
||||
dataViews
|
||||
.get(props.match.params.id)
|
||||
.then((ip: DataView) => {
|
||||
setIndexPattern(ip);
|
||||
setBreadcrumbs(getEditBreadcrumbs(ip));
|
||||
})
|
||||
.catch((err) => {
|
||||
setError(err);
|
||||
});
|
||||
}, [dataViews, props.match.params.id, setBreadcrumbs, setError]);
|
||||
|
||||
if (indexPattern) {
|
||||
return <EditIndexPattern indexPattern={indexPattern} />;
|
||||
} else {
|
||||
return <></>;
|
||||
if (error) {
|
||||
const [errorTitle, errorMessage] = [
|
||||
i18n.translate('indexPatternManagement.editIndexPattern.couldNotLoadTitle', {
|
||||
defaultMessage: 'Unable to load data view',
|
||||
}),
|
||||
i18n.translate('indexPatternManagement.editIndexPattern.couldNotLoadMessage', {
|
||||
defaultMessage:
|
||||
'The data view with id:{objectId} could not be loaded. Try creating a new one.',
|
||||
values: { objectId: props.match.params.id },
|
||||
}),
|
||||
];
|
||||
|
||||
notifications.toasts.addError(error ?? new Error(errorTitle), {
|
||||
title: errorTitle,
|
||||
toastMessage: errorMessage,
|
||||
});
|
||||
props.history.push('/');
|
||||
}
|
||||
|
||||
return indexPattern != null ? <EditIndexPattern indexPattern={indexPattern} /> : null;
|
||||
};
|
||||
|
||||
export const EditIndexPatternContainer = withRouter(EditIndexPatternCont);
|
||||
|
|
38
test/functional/apps/management/_handle_not_found.ts
Normal file
38
test/functional/apps/management/_handle_not_found.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
|
||||
export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
||||
const esArchiver = getService('esArchiver');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
const PageObjects = getPageObjects(['common', 'settings']);
|
||||
const testSubjects = getService('testSubjects');
|
||||
const toasts = getService('toasts');
|
||||
|
||||
describe('index pattern not found', function () {
|
||||
before(async () => {
|
||||
await esArchiver.emptyKibanaIndex();
|
||||
await kibanaServer.uiSettings.replace({});
|
||||
await PageObjects.settings.navigateTo();
|
||||
});
|
||||
|
||||
it(`redirects to the main view if data view is missing`, async () => {
|
||||
await PageObjects.common.navigateToUrl('settings', 'kibana/dataViews/patterns/111111111111', {
|
||||
shouldUseHashForSubUrl: false,
|
||||
});
|
||||
|
||||
await testSubjects.existOrFail('noDataViewsPrompt');
|
||||
const { message } = await toasts.getErrorToast();
|
||||
expect(message).to.contain(
|
||||
'The data view with id:111111111111 could not be loaded. Try creating a new one.'
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -41,6 +41,7 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
|
|||
loadTestFile(require.resolve('./_test_huge_fields'));
|
||||
loadTestFile(require.resolve('./_handle_alias'));
|
||||
loadTestFile(require.resolve('./_handle_version_conflict'));
|
||||
loadTestFile(require.resolve('./_handle_not_found'));
|
||||
loadTestFile(require.resolve('./_data_view_relationships'));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue