From 480809431497fc1a0c114452a40526dc32c92ec7 Mon Sep 17 00:00:00 2001 From: Kawika Avilla Date: Fri, 18 Oct 2024 17:55:58 -0700 Subject: [PATCH] [bug] Discover UI stuck on searching after deleting index pattern (#8659) * [bug] Discover UI stuck on searching after deleting index pattern When using Discover with query enhancement enabled, deleting an index pattern from Index Management does not properly update the "Recently selected data" list in Discover. This causes the UI to become stuck in a "Searching" state when attempting to use Discover after deleting an index pattern. Handle the error case where the use index patterns hook caught error when enhancements was enabled. issue resolved: https://github.com/opensearch-project/OpenSearch-Dashboards/issues/8612 Signed-off-by: Kawika Avilla * Changeset file for PR #8659 created/updated --------- Signed-off-by: Kawika Avilla Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> --- changelogs/fragments/8659.yml | 2 ++ .../utils/use_index_pattern.ts | 28 +++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 changelogs/fragments/8659.yml diff --git a/changelogs/fragments/8659.yml b/changelogs/fragments/8659.yml new file mode 100644 index 000000000000..7b007d454736 --- /dev/null +++ b/changelogs/fragments/8659.yml @@ -0,0 +1,2 @@ +fix: +- Discover UI stuck on searching after failing to find deleted index pattern ([#8659](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8659)) \ No newline at end of file diff --git a/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts b/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts index 1ced2beaccfe..7274bf125497 100644 --- a/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts +++ b/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts @@ -74,25 +74,25 @@ export const useIndexPattern = (services: DiscoverViewServices) => { handleIndexPattern(); } } else { - try { - const ip = await fetchIndexPatternDetails(indexPatternIdFromState); - if (isMounted) { - setIndexPattern(ip); - } - } catch (error) { - if (isMounted) { - const warningMessage = i18n.translate('discover.indexPatternFetchErrorWarning', { - defaultMessage: 'Error fetching index pattern: {error}', - values: { error: (error as Error).message }, - }); - toastNotifications.addWarning(warningMessage); - } + const ip = await fetchIndexPatternDetails(indexPatternIdFromState); + if (isMounted) { + setIndexPattern(ip); } } } }; - handleIndexPattern(); + try { + handleIndexPattern(); + } catch (error) { + if (isMounted) { + const warningMessage = i18n.translate('discover.indexPatternFetchErrorWarning', { + defaultMessage: 'Error fetching index pattern: {error}', + values: { error: (error as Error).message }, + }); + toastNotifications.addWarning(warningMessage); + } + } return () => { isMounted = false;