diff --git a/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte b/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte index 18143c2071..af345ddcdf 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte @@ -137,7 +137,7 @@ selected={$queries.selected === query._id} on:click={() => onClickQuery(query)} > - + {/each} {/if} diff --git a/packages/builder/src/components/backend/DatasourceNavigator/popovers/EditQueryPopover.svelte b/packages/builder/src/components/backend/DatasourceNavigator/popovers/EditQueryPopover.svelte index 4e38dba11d..b15746735b 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/popovers/EditQueryPopover.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/popovers/EditQueryPopover.svelte @@ -5,22 +5,29 @@ import { datasources, queries } from "stores/backend" export let query + export let onClickQuery let confirmDeleteDialog async function deleteQuery() { const wasSelectedQuery = $queries.selected - const selectedDatasource = $datasources.selected + // need to calculate this before the query is deleted + const navigateToDatasource = wasSelectedQuery === query._id + await queries.delete(query) - if (wasSelectedQuery === query._id) { - $goto(`./datasource/${selectedDatasource}`) + await datasources.fetch() + + if (navigateToDatasource) { + await datasources.select(query.datasourceId) + $goto(`./datasource/${query.datasourceId}`) } notifications.success("Query deleted") } async function duplicateQuery() { try { - await queries.duplicate(query) + const newQuery = await queries.duplicate(query) + onClickQuery(newQuery) } catch (e) { notifications.error(e.message) } diff --git a/packages/builder/src/stores/backend/queries.js b/packages/builder/src/stores/backend/queries.js index 0e767fa5c0..2018933ffc 100644 --- a/packages/builder/src/stores/backend/queries.js +++ b/packages/builder/src/stores/backend/queries.js @@ -134,7 +134,7 @@ export function createQueriesStore() { list.map(q => q.name) ) - actions.save(datasourceId, newQuery) + return actions.save(datasourceId, newQuery) }, }