Skip to content

Commit

Permalink
fix(infra): handle not found view with fallback to default
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Antonio Ghiani committed Apr 28, 2023
1 parent 1ffd3e4 commit cca3426
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 4 additions & 1 deletion x-pack/plugins/infra/public/hooks/use_inventory_views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ export const useInventoryViews = (): UseInventoryViewsResult => {
const { data: currentView, isFetching: isFetchingCurrentView } = useQuery({
queryKey: queryKeys.getById(currentViewId),
queryFn: ({ queryKey: [, id] }) => inventoryViews.client.getInventoryView(id),
onError: (error: ServerError) => notify.getViewFailure(error.body?.message ?? error.message),
onError: (error: ServerError) => {
notify.getViewFailure(error.body?.message ?? error.message);
switchViewById(defaultViewId);
},
placeholderData: null,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ export const useMetricsExplorerViews = (): UseMetricsExplorerViewsResult => {
const { data: currentView, isFetching: isFetchingCurrentView } = useQuery({
queryKey: queryKeys.getById(currentViewId),
queryFn: ({ queryKey: [, id] }) => metricsExplorerViews.client.getMetricsExplorerView(id),
onError: (error: ServerError) => notify.getViewFailure(error.body?.message ?? error.message),
onError: (error: ServerError) => {
notify.getViewFailure(error.body?.message ?? error.message);
switchViewById(defaultViewId);
},
placeholderData: null,
});

Expand Down
14 changes: 9 additions & 5 deletions x-pack/plugins/infra/public/hooks/use_saved_views_notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { i18n } from '@kbn/i18n';
import { useMemo } from 'react';
import { useKibanaContextForPlugin } from './use_kibana';

export const useSavedViewsNotifier = () => {
Expand Down Expand Up @@ -44,9 +45,12 @@ export const useSavedViewsNotifier = () => {
});
};

return {
deleteViewFailure,
getViewFailure,
upsertViewFailure,
};
return useMemo(
() => ({
deleteViewFailure,
getViewFailure,
upsertViewFailure,
}),
[]
);
};

0 comments on commit cca3426

Please sign in to comment.