Merge pull request #8695 from Budibase/feature/auto-select-dataprovider-source

Feature/auto select dataprovider source
This commit is contained in:
deanhannigan 2022-11-28 09:07:49 +00:00 committed by GitHub
commit 21b2831fbf
4 changed files with 51 additions and 5 deletions

View File

@ -20,6 +20,11 @@ import {
} from "../componentUtils"
import { Helpers } from "@budibase/bbui"
import { Utils } from "@budibase/frontend-core"
import {
BUDIBASE_INTERNAL_DB_ID,
DB_TYPE_INTERNAL,
DB_TYPE_EXTERNAL,
} from "constants/backend"
const INITIAL_FRONTEND_STATE = {
apps: [],
@ -481,8 +486,41 @@ export const getFrontendStore = () => {
return null
}
// Generate default props
// Flattened settings
const settings = getComponentSettings(componentName)
let dataSourceField = settings.find(
setting => setting.type == "dataSource" || setting.type == "table"
)
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 === BUDIBASE_INTERNAL_DB_ID &&
table.type == DB_TYPE_INTERNAL
)
const defaultSourceTable = filteredTables.find(
table =>
table.sourceId !== BUDIBASE_INTERNAL_DB_ID &&
table.type == DB_TYPE_INTERNAL
)
const defaultExternalTable = filteredTables.find(
table => table.type == DB_TYPE_EXTERNAL
)
defaultDatasource =
defaultSourceTable || internalTable || defaultExternalTable
}
// Generate default props
let props = { ...presetProps }
settings.forEach(setting => {
if (setting.defaultValue !== undefined) {
@ -490,6 +528,15 @@ export const getFrontendStore = () => {
}
})
// Set a default datasource
if (dataSourceField && defaultDatasource) {
props[dataSourceField.key] = {
label: defaultDatasource.name,
tableId: defaultDatasource._id,
type: "table",
}
}
// Add any extra properties the component needs
let extras = {}
if (definition.hasChildren) {

View File

@ -175,6 +175,8 @@ export const SWITCHABLE_TYPES = [
export const BUDIBASE_INTERNAL_DB_ID = "bb_internal"
export const BUDIBASE_DATASOURCE_TYPE = "budibase"
export const DB_TYPE_INTERNAL = "internal"
export const DB_TYPE_EXTERNAL = "external"
export const IntegrationTypes = {
POSTGRES: "POSTGRES",

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 => {