Add better support for generic DS+ into databindings and update save row to work with view V2s
This commit is contained in:
parent
c78fcb2ba6
commit
fd71ad57da
|
@ -418,7 +418,7 @@ const getProviderContextBindings = (asset, dataProviders) => {
|
||||||
*/
|
*/
|
||||||
export const getUserBindings = () => {
|
export const getUserBindings = () => {
|
||||||
let bindings = []
|
let bindings = []
|
||||||
const { schema } = getSchemaForTable(TableNames.USERS)
|
const { schema } = getSchemaForDatasourcePlus(TableNames.USERS)
|
||||||
const keys = Object.keys(schema).sort()
|
const keys = Object.keys(schema).sort()
|
||||||
const safeUser = makePropSafe("user")
|
const safeUser = makePropSafe("user")
|
||||||
|
|
||||||
|
@ -647,17 +647,25 @@ export const getEventContextBindings = (
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the schema for a certain table ID.
|
* Gets the schema for a certain datasource plus.
|
||||||
* The options which can be passed in are:
|
* The options which can be passed in are:
|
||||||
* formSchema: whether the schema is for a form
|
* formSchema: whether the schema is for a form
|
||||||
* searchableSchema: whether to generate a searchable schema, which may have
|
* searchableSchema: whether to generate a searchable schema, which may have
|
||||||
* fewer fields than a readable schema
|
* fewer fields than a readable schema
|
||||||
* @param tableId the table ID to get the schema for
|
* @param resourceId the DS+ resource ID
|
||||||
* @param options options for generating the schema
|
* @param options options for generating the schema
|
||||||
* @return {{schema: Object, table: Object}}
|
* @return {{schema: Object, table: Object}}
|
||||||
*/
|
*/
|
||||||
export const getSchemaForTable = (tableId, options) => {
|
export const getSchemaForDatasourcePlus = (resourceId, options) => {
|
||||||
return getSchemaForDatasource(null, { type: "table", tableId }, options)
|
const isViewV2 = resourceId?.includes("view_ta_")
|
||||||
|
const datasource = isViewV2
|
||||||
|
? {
|
||||||
|
type: "viewV2",
|
||||||
|
id: resourceId,
|
||||||
|
tableId: resourceId.split("_").slice(1, 3).join("_"),
|
||||||
|
}
|
||||||
|
: { type: "table", tableId: resourceId }
|
||||||
|
return getSchemaForDatasource(null, datasource, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -738,7 +746,9 @@ export const getSchemaForDatasource = (asset, datasource, options) => {
|
||||||
schema = cloneDeep(table.views?.[datasource.name]?.schema)
|
schema = cloneDeep(table.views?.[datasource.name]?.schema)
|
||||||
} else if (type === "viewV2") {
|
} else if (type === "viewV2") {
|
||||||
// New views which are DS+
|
// New views which are DS+
|
||||||
const view = table.views?.[datasource.name]
|
const view = Object.values(table.views || {}).find(
|
||||||
|
view => view.id === datasource.id
|
||||||
|
)
|
||||||
schema = cloneDeep(view?.schema)
|
schema = cloneDeep(view?.schema)
|
||||||
|
|
||||||
// Strip hidden fields
|
// Strip hidden fields
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
import FilterDrawer from "components/design/settings/controls/FilterEditor/FilterDrawer.svelte"
|
import FilterDrawer from "components/design/settings/controls/FilterEditor/FilterDrawer.svelte"
|
||||||
import { LuceneUtils } from "@budibase/frontend-core"
|
import { LuceneUtils } from "@budibase/frontend-core"
|
||||||
import {
|
import {
|
||||||
getSchemaForTable,
|
getSchemaForDatasourcePlus,
|
||||||
getEnvironmentBindings,
|
getEnvironmentBindings,
|
||||||
} from "builderStore/dataBinding"
|
} from "builderStore/dataBinding"
|
||||||
import { Utils } from "@budibase/frontend-core"
|
import { Utils } from "@budibase/frontend-core"
|
||||||
|
@ -158,7 +158,7 @@
|
||||||
// instead fetch the schema in the backend at runtime.
|
// instead fetch the schema in the backend at runtime.
|
||||||
let schema
|
let schema
|
||||||
if (e.detail?.tableId) {
|
if (e.detail?.tableId) {
|
||||||
schema = getSchemaForTable(e.detail.tableId, {
|
schema = getSchemaForDatasourcePlus(e.detail.tableId, {
|
||||||
searchableSchema: true,
|
searchableSchema: true,
|
||||||
}).schema
|
}).schema
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
<script>
|
<script>
|
||||||
import { Select, Label, Checkbox, Input, Body } from "@budibase/bbui"
|
import { Select, Label, Checkbox, Input, Body } from "@budibase/bbui"
|
||||||
import { tables as tablesStore, viewsV2 } from "stores/backend"
|
import { tables, viewsV2 } from "stores/backend"
|
||||||
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
||||||
|
|
||||||
export let parameters
|
export let parameters
|
||||||
export let bindings = []
|
export let bindings = []
|
||||||
|
|
||||||
$: tables = $tablesStore.list.map(table => ({
|
$: tableOptions = $tables.list.map(table => ({
|
||||||
label: table.name,
|
label: table.name,
|
||||||
resourceId: table._id,
|
resourceId: table._id,
|
||||||
}))
|
}))
|
||||||
$: views = $viewsV2.list.map(view => ({
|
$: viewOptions = $viewsV2.list.map(view => ({
|
||||||
label: view.name,
|
label: view.name,
|
||||||
resourceId: view.id,
|
resourceId: view.id,
|
||||||
}))
|
}))
|
||||||
$: options = [...(tables || []), ...(views || [])]
|
$: options = [...(tableOptions || []), ...(viewOptions || [])]
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="root">
|
<div class="root">
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import { tables } from "stores/backend"
|
import { tables } from "stores/backend"
|
||||||
import {
|
import {
|
||||||
getContextProviderComponents,
|
getContextProviderComponents,
|
||||||
getSchemaForTable,
|
getSchemaForDatasourcePlus,
|
||||||
} from "builderStore/dataBinding"
|
} from "builderStore/dataBinding"
|
||||||
import SaveFields from "./SaveFields.svelte"
|
import SaveFields from "./SaveFields.svelte"
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSchemaFields = (asset, tableId) => {
|
const getSchemaFields = (asset, tableId) => {
|
||||||
const { schema } = getSchemaForTable(tableId)
|
const { schema } = getSchemaForDatasourcePlus(tableId)
|
||||||
delete schema._id
|
delete schema._id
|
||||||
delete schema._rev
|
delete schema._rev
|
||||||
return Object.values(schema || {})
|
return Object.values(schema || {})
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<script>
|
<script>
|
||||||
import { Select, Label, Body, Checkbox, Input } from "@budibase/bbui"
|
import { Select, Label, Body, Checkbox, Input } from "@budibase/bbui"
|
||||||
import { store, currentAsset } from "builderStore"
|
import { store, currentAsset } from "builderStore"
|
||||||
import { tables } from "stores/backend"
|
import { tables, viewsV2 } from "stores/backend"
|
||||||
import {
|
import {
|
||||||
getContextProviderComponents,
|
getContextProviderComponents,
|
||||||
getSchemaForTable,
|
getSchemaForDatasourcePlus,
|
||||||
} from "builderStore/dataBinding"
|
} from "builderStore/dataBinding"
|
||||||
import SaveFields from "./SaveFields.svelte"
|
import SaveFields from "./SaveFields.svelte"
|
||||||
|
|
||||||
|
@ -24,8 +24,16 @@
|
||||||
"schema"
|
"schema"
|
||||||
)
|
)
|
||||||
$: providerOptions = getProviderOptions(formComponents, schemaComponents)
|
$: providerOptions = getProviderOptions(formComponents, schemaComponents)
|
||||||
$: schemaFields = getSchemaFields($currentAsset, parameters?.tableId)
|
$: schemaFields = getSchemaFields(parameters?.tableId)
|
||||||
$: tableOptions = $tables.list || []
|
$: tableOptions = $tables.list.map(table => ({
|
||||||
|
label: table.name,
|
||||||
|
resourceId: table._id,
|
||||||
|
}))
|
||||||
|
$: viewOptions = $viewsV2.list.map(view => ({
|
||||||
|
label: view.name,
|
||||||
|
resourceId: view.id,
|
||||||
|
}))
|
||||||
|
$: options = [...(tableOptions || []), ...(viewOptions || [])]
|
||||||
|
|
||||||
// Gets a context definition of a certain type from a component definition
|
// Gets a context definition of a certain type from a component definition
|
||||||
const extractComponentContext = (component, contextType) => {
|
const extractComponentContext = (component, contextType) => {
|
||||||
|
@ -61,8 +69,8 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSchemaFields = (asset, tableId) => {
|
const getSchemaFields = resourceId => {
|
||||||
const { schema } = getSchemaForTable(tableId)
|
const { schema } = getSchemaForDatasourcePlus(resourceId)
|
||||||
return Object.values(schema || {})
|
return Object.values(schema || {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,9 +97,9 @@
|
||||||
<Label small>Table</Label>
|
<Label small>Table</Label>
|
||||||
<Select
|
<Select
|
||||||
bind:value={parameters.tableId}
|
bind:value={parameters.tableId}
|
||||||
options={tableOptions}
|
{options}
|
||||||
getOptionLabel={option => option.name}
|
getOptionLabel={option => option.label}
|
||||||
getOptionValue={option => option._id}
|
getOptionValue={option => option.resourceId}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Label small />
|
<Label small />
|
||||||
|
|
Loading…
Reference in New Issue