From d5b821e30a22224fe62d265cd08af07754c5e931 Mon Sep 17 00:00:00 2001 From: Will Lachance Date: Sat, 15 Jul 2023 13:56:39 -0400 Subject: [PATCH] Fix persisting datasource selection choice (#6181) * Fix persisting datasource selection choice Closes getredash/redash#5646. We were already storing this in localStorage, however we weren't accounting for the fact that it was stored as a string, rather than an integer. * Restyled by prettier (#6182) Co-authored-by: Restyled.io --------- Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com> Co-authored-by: Restyled.io --- client/app/pages/queries/QuerySource.jsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/client/app/pages/queries/QuerySource.jsx b/client/app/pages/queries/QuerySource.jsx index 774b720963..f492b99324 100644 --- a/client/app/pages/queries/QuerySource.jsx +++ b/client/app/pages/queries/QuerySource.jsx @@ -134,11 +134,10 @@ function QuerySource(props) { // choose data source id for new queries if (dataSourcesLoaded && queryFlags.isNew) { const firstDataSourceId = dataSources.length > 0 ? dataSources[0].id : null; + const selectedDataSourceId = parseInt(localStorage.getItem("lastSelectedDataSourceId")) || null; + handleDataSourceChange( - chooseDataSourceId( - [query.data_source_id, localStorage.getItem("lastSelectedDataSourceId"), firstDataSourceId], - dataSources - ) + chooseDataSourceId([query.data_source_id, selectedDataSourceId, firstDataSourceId], dataSources) ); } }, [query.data_source_id, queryFlags.isNew, dataSourcesLoaded, dataSources, handleDataSourceChange]);