1
0
Fork 0
mirror of synced 2024-09-11 06:56:23 +12:00

Default datasource behaviour with order of preference: DefaultDB, Internal then External

This commit is contained in:
Dean 2022-11-15 14:29:58 +00:00
parent 53027db66a
commit 63d9a5977b
3 changed files with 44 additions and 4 deletions

View file

@ -481,6 +481,40 @@ export const getFrontendStore = () => {
return null
}
const dataSourceField = definition.settings.find(
setting => setting.type == "dataSource"
)
let defaultDatasource
if (dataSourceField) {
const _tables = get(tables)
const filteredTables = _tables.list.filter(
table => table._id != "ta_users"
)
const internalTable = filteredTables.find(
table =>
table.sourceId === "bb_internal" && table.type == "internal"
)
const defaultSourceTable = filteredTables.find(
table =>
table.sourceId !== "bb_internal" && table.type == "internal"
)
const defaultExternalTable = filteredTables.find(
table => table.type == "external"
)
if (defaultSourceTable) {
defaultDatasource = defaultSourceTable
} else if (internalTable) {
defaultDatasource = internalTable
} else if (defaultExternalTable) {
defaultDatasource = defaultExternalTable
}
}
// Generate default props
const settings = getComponentSettings(componentName)
let props = { ...presetProps }
@ -490,6 +524,15 @@ export const getFrontendStore = () => {
}
})
// Set a default datasource
if (dataSourceField && defaultDatasource) {
props["dataSource"] = {
label: defaultDatasource.name,
tableId: defaultDatasource._id,
type: "table",
}
}
// Add any extra properties the component needs
let extras = {}
if (definition.hasChildren) {

View file

@ -1,7 +1,6 @@
<script>
import { store, automationStore } from "builderStore"
import { roles, flags } from "stores/backend"
import { apps } from "stores/portal"
import {
ActionMenu,
MenuItem,
@ -63,9 +62,6 @@
})
}
$: isPublished =
$apps.find(app => app.devId === application)?.status === "published"
onMount(async () => {
if (!hasSynced && application) {
try {

View file

@ -93,6 +93,7 @@ export function createDatasourcesStore() {
return { list: sources, selected: null }
})
await queries.fetch()
await tables.fetch()
},
removeSchemaError: () => {
update(state => {