Skip to content

Commit

Permalink
fix initial load
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Jul 29, 2024
1 parent e47af9c commit 335978d
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,27 +328,32 @@ export const DataSetNavigator: React.FC<DataSetNavigatorProps> = ({
async (source: SimpleDataSource) => {
if (source) {
setIsLoading(true);
const indices = await fetchIndices(searchService, source.id);
setSelectedDataSetState((prevState) => {
if (!prevState) return;

return {
...prevState,
dataSourceRef: {
...source,
indices: indices.map((indexName: string) => ({
id: indexName,
title: indexName,
dataSourceRef: {
id: source.id,
name: source.name,
type: source.type,
},
})),
},
try {
const indices = await fetchIndices(searchService, source.id);
const updatedSource = {
...source,
indices: indices.map((indexName: string) => ({
id: indexName,
title: indexName,
dataSourceRef: {
id: source.id,
name: source.name,
type: source.type,
},
})),
};
});
setIsLoading(false);

setDataSources((prevDataSources) =>
prevDataSources.map((ds) => (ds.id === source.id ? updatedSource : ds))
);

setSelectedDataSetState((prevState) => ({
...prevState!,
dataSourceRef: updatedSource,
}));
} finally {
setIsLoading(false);
}
}
},
[searchService]
Expand Down Expand Up @@ -485,7 +490,8 @@ export const DataSetNavigator: React.FC<DataSetNavigatorProps> = ({
panel: 7,
onClick: () => handleSelectedObject(object),
})),
content: isLoading && !selectedDataSetState?.dataSourceRef && createLoadingSpinner(),
content:
isLoading && !selectedDataSetState?.dataSourceRef?.indices && createLoadingSpinner(),
},
{
id: 4,
Expand Down

0 comments on commit 335978d

Please sign in to comment.