Update data section routing to properly handle datasource entities/table sync and handle having no data
This commit is contained in:
parent
6d38bdcd64
commit
a3204ad17a
|
@ -2,8 +2,17 @@
|
|||
import { Button, Layout } from "@budibase/bbui"
|
||||
import DatasourceNavigator from "components/backend/DatasourceNavigator/DatasourceNavigator.svelte"
|
||||
import Panel from "components/design/Panel.svelte"
|
||||
import { isActive, goto } from "@roxi/routify"
|
||||
import { isActive, goto, redirect } from "@roxi/routify"
|
||||
import BetaButton from "./_components/BetaButton.svelte"
|
||||
import { datasources } from "stores/backend"
|
||||
|
||||
$: {
|
||||
// If we ever don't have any data other than the users table, prompt the
|
||||
// user to add some
|
||||
if (!$datasources.hasData) {
|
||||
$redirect("./new")
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- routify:options index=1 -->
|
||||
|
|
|
@ -4,11 +4,13 @@
|
|||
import { onMount } from "svelte"
|
||||
|
||||
onMount(async () => {
|
||||
const { list, selected } = $datasources
|
||||
const { list, selected, hasData } = $datasources
|
||||
if (selected) {
|
||||
$redirect(`./${selected?._id}`)
|
||||
} else {
|
||||
} else if (hasData && list?.length) {
|
||||
$redirect(`./${list[0]._id}`)
|
||||
} else {
|
||||
$redirect("../new")
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
<script>
|
||||
import { redirect } from "@roxi/routify"
|
||||
import { onMount } from "svelte"
|
||||
import { TableNames } from "constants"
|
||||
import { datasources } from "stores/backend"
|
||||
|
||||
$: hasData =
|
||||
$datasources.list.find(x => (x._id = "bb_internal"))?.entities?.length >
|
||||
1 || $datasources.list.length > 1
|
||||
|
||||
onMount(() => {
|
||||
if (!hasData) {
|
||||
$redirect("./new")
|
||||
$: {
|
||||
if ($datasources.hasData) {
|
||||
$redirect(`./table/${TableNames.USERS}`)
|
||||
} else {
|
||||
$redirect("./table")
|
||||
$redirect("./new")
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
<script>
|
||||
import { onMount } from "svelte"
|
||||
import { tables } from "stores/backend"
|
||||
import { datasources, tables } from "stores/backend"
|
||||
import { redirect } from "@roxi/routify"
|
||||
import { TableNames } from "constants"
|
||||
|
||||
onMount(async () => {
|
||||
const { list, selected } = $tables
|
||||
if (selected) {
|
||||
$redirect(`./${selected?._id}`)
|
||||
} else if (list?.length) {
|
||||
$redirect(`./${list[0]._id}`)
|
||||
onMount(() => {
|
||||
if ($tables.selected) {
|
||||
$redirect(`./${$tables.selected._id}`)
|
||||
} else if ($datasources.hasData) {
|
||||
$redirect(`./${TableNames.USERS}`)
|
||||
} else {
|
||||
$redirect("../new")
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
import { writable, derived, get } from "svelte/store"
|
||||
import { IntegrationTypes, DEFAULT_BB_DATASOURCE_ID } from "constants/backend"
|
||||
import {
|
||||
IntegrationTypes,
|
||||
DEFAULT_BB_DATASOURCE_ID,
|
||||
BUDIBASE_INTERNAL_DB_ID,
|
||||
} from "constants/backend"
|
||||
import { queries, tables } from "./"
|
||||
import { API } from "api"
|
||||
import { DatasourceFeature } from "@budibase/types"
|
||||
import { notifications } from "@budibase/bbui"
|
||||
import { TableNames } from "constants"
|
||||
|
||||
export class ImportTableError extends Error {
|
||||
constructor(message) {
|
||||
|
@ -24,13 +29,42 @@ export function createDatasourcesStore() {
|
|||
schemaError: null,
|
||||
})
|
||||
|
||||
const derivedStore = derived(store, $store => ({
|
||||
...$store,
|
||||
selected: $store.list?.find(ds => ds._id === $store.selectedDatasourceId),
|
||||
hasDefaultData: $store.list.some(
|
||||
datasource => datasource._id === DEFAULT_BB_DATASOURCE_ID
|
||||
),
|
||||
}))
|
||||
const derivedStore = derived([store, tables], ([$store, $tables]) => {
|
||||
// Set the internal datasource entities from the table list, which we're
|
||||
// able to keep updated unlike the egress generated definition of the
|
||||
// internal datasource
|
||||
let internalDS = $store.list?.find(ds => ds._id === BUDIBASE_INTERNAL_DB_ID)
|
||||
let otherDS = $store.list?.find(ds => ds._id !== BUDIBASE_INTERNAL_DB_ID)
|
||||
if (internalDS) {
|
||||
internalDS = {
|
||||
...internalDS,
|
||||
entities: $tables.list?.filter(table => {
|
||||
return (
|
||||
table.sourceId === BUDIBASE_INTERNAL_DB_ID &&
|
||||
table._id !== TableNames.USERS
|
||||
)
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// Build up enriched DS list
|
||||
// Only add the internal DS if we have at least one non-users table
|
||||
let list = []
|
||||
if (internalDS?.entities?.length) {
|
||||
list.push(internalDS)
|
||||
}
|
||||
list = list.concat(otherDS || [])
|
||||
|
||||
return {
|
||||
...$store,
|
||||
list,
|
||||
selected: list?.find(ds => ds._id === $store.selectedDatasourceId),
|
||||
hasDefaultData: list?.some(
|
||||
datasource => datasource._id === DEFAULT_BB_DATASOURCE_ID
|
||||
),
|
||||
hasData: !!internalDS?.entities?.length || list?.length > 1,
|
||||
}
|
||||
})
|
||||
|
||||
const fetch = async () => {
|
||||
const datasources = await API.getDatasources()
|
||||
|
|
Loading…
Reference in New Issue