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" } from "../componentUtils"
import { Helpers } from "@budibase/bbui" import { Helpers } from "@budibase/bbui"
import { Utils } from "@budibase/frontend-core" import { Utils } from "@budibase/frontend-core"
import {
BUDIBASE_INTERNAL_DB_ID,
DB_TYPE_INTERNAL,
DB_TYPE_EXTERNAL,
} from "constants/backend"
const INITIAL_FRONTEND_STATE = { const INITIAL_FRONTEND_STATE = {
apps: [], apps: [],
@ -481,8 +486,41 @@ export const getFrontendStore = () => {
return null return null
} }
// Generate default props // Flattened settings
const settings = getComponentSettings(componentName) 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 } let props = { ...presetProps }
settings.forEach(setting => { settings.forEach(setting => {
if (setting.defaultValue !== undefined) { 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 // Add any extra properties the component needs
let extras = {} let extras = {}
if (definition.hasChildren) { if (definition.hasChildren) {

View File

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

View File

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

View File

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