fix some navigation issues when removing tables/datasources

This commit is contained in:
Keviin Åberg Kultalahti 2021-03-19 11:03:44 +01:00
parent b12b6b39b5
commit a3750a2c5b
3 changed files with 17 additions and 3 deletions

View File

@ -105,7 +105,9 @@ export const getBackendUiStore = () => {
state.datasources = state.datasources.filter( state.datasources = state.datasources.filter(
existing => existing._id !== datasource._id existing => existing._id !== datasource._id
) )
state.selectedDatasourceId = null if (datasource._id === state.selectedDatasourceId) {
state.selectedDatasourceId = null
}
return state return state
}) })
}, },
@ -233,7 +235,9 @@ export const getBackendUiStore = () => {
state.tables = state.tables.filter( state.tables = state.tables.filter(
existing => existing._id !== table._id existing => existing._id !== table._id
) )
state.selectedTable = {} if (table._id === state.selectedTable._id) {
state.selectedTable = {}
}
return state return state
}) })
}, },

View File

@ -22,9 +22,14 @@
} }
async function deleteDatasource() { async function deleteDatasource() {
const wasSelectedSource = $backendUiStore.selectedDatasourceId
await backendUiStore.actions.datasources.delete(datasource) await backendUiStore.actions.datasources.delete(datasource)
notifier.success("Datasource deleted") notifier.success("Datasource deleted")
$goto('./datasource') // navigate to first index page if the source you are deleting is selected
console.log('Is the same? ', wasSelectedSource === datasource._id)
if (wasSelectedSource === datasource._id) {
$goto('./datasource')
}
hideEditor() hideEditor()
} }
</script> </script>

View File

@ -1,4 +1,5 @@
<script> <script>
import { goto } from "@sveltech/routify"
import { backendUiStore, store, allScreens } from "builderStore" import { backendUiStore, store, allScreens } from "builderStore"
import { notifier } from "builderStore/store/notifications" import { notifier } from "builderStore/store/notifications"
import { DropdownMenu, Button, Input } from "@budibase/bbui" import { DropdownMenu, Button, Input } from "@budibase/bbui"
@ -36,10 +37,14 @@
} }
async function deleteTable() { async function deleteTable() {
const wasSelectedTable = $backendUiStore.selectedTable
await backendUiStore.actions.tables.delete(table) await backendUiStore.actions.tables.delete(table)
store.actions.screens.delete(templateScreens) store.actions.screens.delete(templateScreens)
await backendUiStore.actions.tables.fetch() await backendUiStore.actions.tables.fetch()
notifier.success("Table deleted") notifier.success("Table deleted")
if (wasSelectedTable._id === table._id) {
$goto('./table')
}
hideEditor() hideEditor()
} }