Update bindable properties to pull directly from form children

This commit is contained in:
Andrew Kingston 2021-02-04 15:11:05 +00:00
parent 4a7e05aa67
commit 71da755b30
1 changed files with 35 additions and 31 deletions

View File

@ -99,37 +99,37 @@ export const getContextBindings = (rootComponent, componentId) => {
// Extract any components which provide data contexts // Extract any components which provide data contexts
const dataProviders = getDataProviderComponents(rootComponent, componentId) const dataProviders = getDataProviderComponents(rootComponent, componentId)
let contextBindings = [] let contextBindings = []
// Create bindings for each data provider
dataProviders.forEach(component => { dataProviders.forEach(component => {
const datasource = getDatasourceForProvider(component)
if (!datasource) {
return
}
// Get schema and table for the datasource
const isForm = component._component.endsWith("/form") const isForm = component._component.endsWith("/form")
let { schema, table } = getSchemaForDatasource(datasource, isForm) const datasource = getDatasourceForProvider(component)
if (!schema || !table) { let tableName, schema
// Forms are an edge case which do not need table schemas
if (isForm) {
schema = buildFormSchema(component)
tableName = "Schema"
} else {
if (!datasource) {
return
}
// Get schema and table for the datasource
const info = getSchemaForDatasource(datasource, isForm)
schema = info.schema
tableName = info.table?.name
// Add _id and _rev fields for certain types
if (datasource.type === "table" || datasource.type === "link") {
schema["_id"] = { type: "string" }
schema["_rev"] = { type: "string " }
}
}
if (!schema || !tableName) {
return return
} }
// Forms are an edge case. They can have a schema which will be exposed as
// bindable properties, but they can also have custom fields which we need
// to find and provide.
if (isForm) {
const formSchema = buildFormSchema(component)
console.log(formSchema)
Object.keys(formSchema).forEach(field => {
if (!schema[field]) {
schema[field] = formSchema[field]
}
})
}
// Add _id and _rev fields for certain types
if (datasource.type === "table" || datasource.type === "link") {
schema["_id"] = { type: "string" }
schema["_rev"] = { type: "string " }
}
const keys = Object.keys(schema).sort() const keys = Object.keys(schema).sort()
// Create bindable properties for each schema field // Create bindable properties for each schema field
@ -148,11 +148,13 @@ export const getContextBindings = (rootComponent, componentId) => {
runtimeBinding: `${makePropSafe(component._id)}.${makePropSafe( runtimeBinding: `${makePropSafe(component._id)}.${makePropSafe(
runtimeBoundKey runtimeBoundKey
)}`, )}`,
readableBinding: `${component._instanceName}.${table.name}.${key}`, readableBinding: `${component._instanceName}.${tableName}.${key}`,
// Field schema and provider are required to construct relationship
// datasource options, based on bindable properties
fieldSchema, fieldSchema,
providerId: component._id, providerId: component._id,
tableId: datasource.tableId, // tableId: table._id,
field: key, // field: key,
}) })
}) })
}) })
@ -180,10 +182,12 @@ export const getContextBindings = (rootComponent, componentId) => {
type: "context", type: "context",
runtimeBinding: `user.${runtimeBoundKey}`, runtimeBinding: `user.${runtimeBoundKey}`,
readableBinding: `Current User.${key}`, readableBinding: `Current User.${key}`,
// Field schema and provider are required to construct relationship
// datasource options, based on bindable properties
fieldSchema, fieldSchema,
providerId: "user", providerId: "user",
tableId: TableNames.USERS, // tableId: TableNames.USERS,
field: key, // field: key,
}) })
}) })