1
0
Fork 0
mirror of synced 2024-07-09 00:06:05 +12:00

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 c7f2a989ad
commit 4d9f4cc211

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 isForm = component._component.endsWith("/form")
const datasource = getDatasourceForProvider(component) const datasource = getDatasourceForProvider(component)
let tableName, schema
// Forms are an edge case which do not need table schemas
if (isForm) {
schema = buildFormSchema(component)
tableName = "Schema"
} else {
if (!datasource) { if (!datasource) {
return return
} }
// Get schema and table for the datasource // Get schema and table for the datasource
const isForm = component._component.endsWith("/form") const info = getSchemaForDatasource(datasource, isForm)
let { schema, table } = getSchemaForDatasource(datasource, isForm) schema = info.schema
if (!schema || !table) { tableName = info.table?.name
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 // Add _id and _rev fields for certain types
if (datasource.type === "table" || datasource.type === "link") { if (datasource.type === "table" || datasource.type === "link") {
schema["_id"] = { type: "string" } schema["_id"] = { type: "string" }
schema["_rev"] = { type: "string " } schema["_rev"] = { type: "string " }
} }
}
if (!schema || !tableName) {
return
}
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,
}) })
}) })