Navigation fixes for duplicate and delete query

This commit is contained in:
Rory Powell 2022-01-05 13:27:15 -05:00
parent 6f53b25116
commit e45ee07192
3 changed files with 13 additions and 6 deletions

View File

@ -137,7 +137,7 @@
selected={$queries.selected === query._id} selected={$queries.selected === query._id}
on:click={() => onClickQuery(query)} on:click={() => onClickQuery(query)}
> >
<EditQueryPopover {query} /> <EditQueryPopover {query} {onClickQuery} />
</NavItem> </NavItem>
{/each} {/each}
{/if} {/if}

View File

@ -5,22 +5,29 @@
import { datasources, queries } from "stores/backend" import { datasources, queries } from "stores/backend"
export let query export let query
export let onClickQuery
let confirmDeleteDialog let confirmDeleteDialog
async function deleteQuery() { async function deleteQuery() {
const wasSelectedQuery = $queries.selected 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) await queries.delete(query)
if (wasSelectedQuery === query._id) { await datasources.fetch()
$goto(`./datasource/${selectedDatasource}`)
if (navigateToDatasource) {
await datasources.select(query.datasourceId)
$goto(`./datasource/${query.datasourceId}`)
} }
notifications.success("Query deleted") notifications.success("Query deleted")
} }
async function duplicateQuery() { async function duplicateQuery() {
try { try {
await queries.duplicate(query) const newQuery = await queries.duplicate(query)
onClickQuery(newQuery)
} catch (e) { } catch (e) {
notifications.error(e.message) notifications.error(e.message)
} }

View File

@ -134,7 +134,7 @@ export function createQueriesStore() {
list.map(q => q.name) list.map(q => q.name)
) )
actions.save(datasourceId, newQuery) return actions.save(datasourceId, newQuery)
}, },
} }