From 3f814c6a9bc28c7a70d4f0add9ff2e64a4546365 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 10 Nov 2023 10:39:48 +0100 Subject: [PATCH] Handle open/close correctly --- .../DatasourceNavigator.svelte | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte b/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte index 7e98861b8a..c8eb946dd3 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte @@ -23,7 +23,7 @@ import { userSelectedResourceMap } from "builderStore" export let searchTerm - let openDataSources = [] + let dataSourcesVisibility = {} $: enrichedDataSources = enrichDatasources( $datasources, @@ -33,10 +33,27 @@ $queries, $views, $viewsV2, - openDataSources, + dataSourcesVisibility, searchTerm ) + const showDatasourceOpen = ({ + selected, + containsSelected, + dataSourceVisibility, + searchTerm, + }) => { + if (searchTerm) { + return true + } + + if (dataSourceVisibility !== undefined) { + return dataSourceVisibility + } + + return selected || containsSelected + } + const enrichDatasources = ( datasources, params, @@ -45,7 +62,7 @@ queries, views, viewsV2, - openDataSources, + dataSourcesVisibility, searchTerm ) => { if (!datasources?.list?.length) { @@ -56,7 +73,6 @@ const selected = isActive("./datasource") && datasources.selectedDatasourceId === datasource._id - const open = openDataSources.includes(datasource._id) const containsSelected = containsActiveEntity( datasource, params, @@ -80,11 +96,18 @@ (!searchTerm || query.name?.toLowerCase()?.indexOf(searchTerm.toLowerCase()) > -1) ) + + const open = showDatasourceOpen({ + selected, + containsSelected, + dataSourceVisibility: dataSourcesVisibility[datasource._id], + searchTerm, + }) return { ...datasource, selected, containsSelected, - open: containsSelected || open || onlySource || !!searchTerm, + open, queries: dsQueries, tables: dsTables, } @@ -103,23 +126,13 @@ } } - function closeNode(datasource) { - openDataSources = openDataSources.filter(id => datasource._id !== id) - } - function openNode(datasource) { - if (!openDataSources.includes(datasource._id)) { - openDataSources = [...openDataSources, datasource._id] - } + dataSourcesVisibility[datasource._id] = true } function toggleNode(datasource) { - const isOpen = openDataSources.includes(datasource._id) - if (isOpen) { - closeNode(datasource) - } else { - openNode(datasource) - } + dataSourcesVisibility[datasource._id] = + !dataSourcesVisibility[datasource._id] } const containsActiveEntity = (