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

[APM] Suppress error toast when data view cannot be created #143639

Merged
merged 2 commits into from Oct 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 25 additions & 3 deletions x-pack/plugins/apm/public/hooks/use_apm_data_view.ts
Expand Up @@ -6,6 +6,7 @@
*/

import { DataView } from '@kbn/data-views-plugin/common';
import { i18n } from '@kbn/i18n';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { useEffect, useState } from 'react';
import { ApmPluginStartDeps } from '../plugin';
Expand All @@ -19,17 +20,38 @@ async function getApmDataViewTitle() {
}

export function useApmDataView() {
const { services } = useKibana<ApmPluginStartDeps>();
const { services, notifications } = useKibana<ApmPluginStartDeps>();
const [dataView, setDataView] = useState<DataView | undefined>();

useEffect(() => {
async function fetchDataView() {
const title = await getApmDataViewTitle();
return services.dataViews.create({ title });
try {
const displayError = false;
return await services.dataViews.create(
{ title },
undefined,
displayError
);
} catch (e) {
const noDataScreen = e.message.includes('No matching indices found');
if (noDataScreen) {
return;
}

notifications.toasts.danger({
title: i18n.translate('xpack.apm.data_view.creation_failed', {
defaultMessage: 'An error occurred while creating the data view',
}),
body: e.message,
});

throw e;
}
}

fetchDataView().then(setDataView);
}, [services.dataViews]);
}, [notifications.toasts, services.dataViews]);

return { dataView };
}