Ensure datasource containing the currently selected table is always expanded
This commit is contained in:
parent
1ad2687f4f
commit
216a7c7a3f
|
@ -1,8 +1,9 @@
|
||||||
<script>
|
<script>
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
|
import { get } from "svelte/store"
|
||||||
import { goto } from "@roxi/routify"
|
import { goto } from "@roxi/routify"
|
||||||
import { BUDIBASE_INTERNAL_DB } from "constants"
|
import { BUDIBASE_INTERNAL_DB } from "constants"
|
||||||
import { database, datasources, queries } from "stores/backend"
|
import { database, datasources, queries, tables } from "stores/backend"
|
||||||
import EditDatasourcePopover from "./popovers/EditDatasourcePopover.svelte"
|
import EditDatasourcePopover from "./popovers/EditDatasourcePopover.svelte"
|
||||||
import EditQueryPopover from "./popovers/EditQueryPopover.svelte"
|
import EditQueryPopover from "./popovers/EditQueryPopover.svelte"
|
||||||
import NavItem from "components/common/NavItem.svelte"
|
import NavItem from "components/common/NavItem.svelte"
|
||||||
|
@ -10,6 +11,13 @@
|
||||||
import ICONS from "./icons"
|
import ICONS from "./icons"
|
||||||
|
|
||||||
let openDataSources = []
|
let openDataSources = []
|
||||||
|
$: enrichedDataSources = $datasources.list.map(datasource => ({
|
||||||
|
...datasource,
|
||||||
|
open:
|
||||||
|
openDataSources.includes(datasource._id) ||
|
||||||
|
containsActiveTable(datasource),
|
||||||
|
selected: $datasources.selected === datasource._id,
|
||||||
|
}))
|
||||||
|
|
||||||
function selectDatasource(datasource) {
|
function selectDatasource(datasource) {
|
||||||
toggleNode(datasource)
|
toggleNode(datasource)
|
||||||
|
@ -35,16 +43,28 @@
|
||||||
datasources.fetch()
|
datasources.fetch()
|
||||||
queries.fetch()
|
queries.fetch()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const containsActiveTable = datasource => {
|
||||||
|
const activeTableId = get(tables).selected?._id
|
||||||
|
if (!datasource.entities) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
let tableOptions = datasource.entities
|
||||||
|
if (!Array.isArray(tableOptions)) {
|
||||||
|
tableOptions = Object.values(tableOptions)
|
||||||
|
}
|
||||||
|
return tableOptions.find(x => x._id === activeTableId) != null
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $database?._id}
|
{#if $database?._id}
|
||||||
<div class="hierarchy-items-container">
|
<div class="hierarchy-items-container">
|
||||||
{#each $datasources.list as datasource, idx}
|
{#each enrichedDataSources as datasource, idx}
|
||||||
<NavItem
|
<NavItem
|
||||||
border={idx > 0}
|
border={idx > 0}
|
||||||
text={datasource.name}
|
text={datasource.name}
|
||||||
opened={openDataSources.includes(datasource._id)}
|
opened={datasource.open}
|
||||||
selected={$datasources.selected === datasource._id}
|
selected={datasource.selected}
|
||||||
withArrow={true}
|
withArrow={true}
|
||||||
on:click={() => selectDatasource(datasource)}
|
on:click={() => selectDatasource(datasource)}
|
||||||
on:iconClick={() => toggleNode(datasource)}
|
on:iconClick={() => toggleNode(datasource)}
|
||||||
|
@ -61,7 +81,7 @@
|
||||||
{/if}
|
{/if}
|
||||||
</NavItem>
|
</NavItem>
|
||||||
|
|
||||||
{#if openDataSources.includes(datasource._id)}
|
{#if datasource.open}
|
||||||
<TableNavigator sourceId={datasource._id} />
|
<TableNavigator sourceId={datasource._id} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<script>
|
||||||
|
import { datasources } from "stores/backend"
|
||||||
|
|
||||||
|
datasources.select("bb_internal")
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<slot />
|
|
@ -1,4 +1,4 @@
|
||||||
import { writable } from "svelte/store"
|
import { writable, get } from "svelte/store"
|
||||||
import { queries, tables, views } from "./"
|
import { queries, tables, views } from "./"
|
||||||
import api from "../../builderStore/api"
|
import api from "../../builderStore/api"
|
||||||
|
|
||||||
|
@ -8,7 +8,8 @@ export const INITIAL_DATASOURCE_VALUES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createDatasourcesStore() {
|
export function createDatasourcesStore() {
|
||||||
const { subscribe, update, set } = writable(INITIAL_DATASOURCE_VALUES)
|
const store = writable(INITIAL_DATASOURCE_VALUES)
|
||||||
|
const { subscribe, update, set } = store
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subscribe,
|
subscribe,
|
||||||
|
@ -21,7 +22,15 @@ export function createDatasourcesStore() {
|
||||||
fetch: async () => {
|
fetch: async () => {
|
||||||
const response = await api.get(`/api/datasources`)
|
const response = await api.get(`/api/datasources`)
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
update(state => ({ ...state, list: json, selected: null }))
|
|
||||||
|
// Clear selected if it no longer exists, otherwise keep it
|
||||||
|
const selected = get(store).selected
|
||||||
|
let nextSelected = null
|
||||||
|
if (selected && json.find(source => source._id === selected)) {
|
||||||
|
nextSelected = selected
|
||||||
|
}
|
||||||
|
|
||||||
|
update(state => ({ ...state, list: json, selected: nextSelected }))
|
||||||
return json
|
return json
|
||||||
},
|
},
|
||||||
select: async datasourceId => {
|
select: async datasourceId => {
|
||||||
|
|
Loading…
Reference in New Issue