mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
* [ML] Fix error handling for missing data view in data frame analytics wizard * [ML] Fix jest tests Co-authored-by: Pete Harverson <pete@elastic.co>
This commit is contained in:
parent
3d083b6349
commit
f61fdc82ce
2 changed files with 24 additions and 2 deletions
|
@ -76,6 +76,11 @@ jest.mock('../../../../../contexts/kibana', () => ({
|
|||
},
|
||||
}),
|
||||
useNavigateToPath: () => mockNavigateToPath,
|
||||
useNotifications: () => {
|
||||
return {
|
||||
toasts: { addSuccess: jest.fn(), addDanger: jest.fn(), addError: jest.fn() },
|
||||
};
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('../../../../../util/index_utils', () => {
|
||||
|
|
|
@ -23,6 +23,8 @@ import type { SimpleSavedObject } from 'src/core/public';
|
|||
import { SavedObjectFinderUi } from '../../../../../../../../../../src/plugins/saved_objects/public';
|
||||
import { useMlKibana, useNavigateToPath } from '../../../../../contexts/kibana';
|
||||
|
||||
import { useToastNotificationService } from '../../../../../services/toast_notification_service';
|
||||
|
||||
import { getNestedProperty } from '../../../../../util/object_utils';
|
||||
|
||||
import { getDataViewAndSavedSearch, isCcsIndexPattern } from '../../../../../util/index_utils';
|
||||
|
@ -41,6 +43,7 @@ export const SourceSelection: FC<Props> = ({ onClose }) => {
|
|||
|
||||
const [isCcsCallOut, setIsCcsCallOut] = useState(false);
|
||||
const [ccsCallOutBodyText, setCcsCallOutBodyText] = useState<string>();
|
||||
const toastNotificationService = useToastNotificationService();
|
||||
|
||||
const onSearchSelected = async (
|
||||
id: string,
|
||||
|
@ -57,8 +60,22 @@ export const SourceSelection: FC<Props> = ({ onClose }) => {
|
|||
if (type === 'index-pattern') {
|
||||
dataViewName = getNestedProperty(savedObject, 'attributes.title');
|
||||
} else if (type === 'search') {
|
||||
const dataViewAndSavedSearch = await getDataViewAndSavedSearch(id);
|
||||
dataViewName = dataViewAndSavedSearch.dataView?.title ?? '';
|
||||
try {
|
||||
const dataViewAndSavedSearch = await getDataViewAndSavedSearch(id);
|
||||
dataViewName = dataViewAndSavedSearch.dataView?.title ?? '';
|
||||
} catch (error) {
|
||||
// an unexpected error has occurred. This could be caused by a saved search for which the data view no longer exists.
|
||||
toastNotificationService.displayErrorToast(
|
||||
error,
|
||||
i18n.translate(
|
||||
'xpack.ml.dataFrame.analytics.create.searchSelection.errorGettingDataViewTitle',
|
||||
{
|
||||
defaultMessage: 'Error loading data view used by the saved search',
|
||||
}
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isCcsIndexPattern(dataViewName)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue