From 63917efaa72737ab2a7cbac640d7afd33d7df393 Mon Sep 17 00:00:00 2001 From: Sean Li Date: Tue, 30 Jul 2024 08:47:34 -0700 Subject: [PATCH] [Discover 2.0] Loading fix for databases (#7567) * add back in useeffect for loading databases Signed-off-by: Sean Li * Changeset file for PR #7567 created/updated --------- Signed-off-by: Sean Li Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> --- changelogs/fragments/7567.yml | 2 ++ .../dataset_navigator/dataset_navigator.tsx | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 changelogs/fragments/7567.yml diff --git a/changelogs/fragments/7567.yml b/changelogs/fragments/7567.yml new file mode 100644 index 000000000000..70cfde199196 --- /dev/null +++ b/changelogs/fragments/7567.yml @@ -0,0 +1,2 @@ +fix: +- Fixes databases not being displayed upon success ([#7567](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7567)) \ No newline at end of file diff --git a/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx b/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx index eeb3f7085515..bfeaad00bd4e 100644 --- a/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx +++ b/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx @@ -286,6 +286,29 @@ export const DataSetNavigator: React.FC = ({ [selectedDataSetState?.dataSourceRef, tablesLoadStatus, startLoadingTables] ); + useEffect(() => { + const status = databasesLoadStatus.toLowerCase(); + if ( + selectedDataSetState?.dataSourceRef && + selectedDataSetState.dataSourceRef.type === SIMPLE_DATA_SOURCE_TYPES.EXTERNAL + ) { + const dataSourceCache = CatalogCacheManager.getOrCreateDataSource( + selectedDataSetState.dataSourceRef.name, + selectedDataSetState.dataSourceRef.id + ); + if (status === DirectQueryLoadingStatus.SUCCESS) { + setCachedDatabases( + dataSourceCache.databases.map((db) => ({ id: db.name, title: db.name })) + ); + } else if ( + status === DirectQueryLoadingStatus.CANCELED || + status === DirectQueryLoadingStatus.FAILED + ) { + notifications.toasts.addWarning('Error loading databases'); + } + } + }, [databasesLoadStatus, selectedDataSetState?.dataSourceRef, notifications.toasts]); + useEffect(() => { if ( selectedDataSetState?.dataSourceRef &&