Add ID and rev data bindings back in

This commit is contained in:
Andrew Kingston 2021-01-15 14:47:36 +00:00
parent fba2f27638
commit dbbe76951d
1 changed files with 14 additions and 5 deletions

View File

@ -36,12 +36,14 @@ export const getBindableContexts = (rootComponent, componentId) => {
return return
} }
const { schema, table } = getSchemaForDatasource(provider.datasource) const { schema, table } = getSchemaForDatasource(provider.datasource)
Object.entries(schema).forEach(([key, schema]) => { const keys = Object.keys(schema).sort()
keys.forEach(key => {
const fieldSchema = schema[key]
// Replace certain bindings with a new property to help display components // Replace certain bindings with a new property to help display components
let runtimeBoundKey = key let runtimeBoundKey = key
if (schema.type === "link") { if (fieldSchema.type === "link") {
runtimeBoundKey = `${key}_count` runtimeBoundKey = `${key}_count`
} else if (schema.type === "attachment") { } else if (fieldSchema.type === "attachment") {
runtimeBoundKey = `${key}_first` runtimeBoundKey = `${key}_first`
} }
@ -49,7 +51,7 @@ export const getBindableContexts = (rootComponent, componentId) => {
type: "context", type: "context",
runtimeBinding: `${provider._id}.${runtimeBoundKey}`, runtimeBinding: `${provider._id}.${runtimeBoundKey}`,
readableBinding: `${provider._instanceName}.${table.name}.${key}`, readableBinding: `${provider._instanceName}.${table.name}.${key}`,
fieldSchema: schema, fieldSchema,
providerId: provider._id, providerId: provider._id,
}) })
}) })
@ -88,7 +90,7 @@ const getSchemaForDatasource = datasource => {
const tables = get(backendUiStore).tables const tables = get(backendUiStore).tables
const { type } = datasource const { type } = datasource
const table = tables.find(table => table._id === datasource.tableId) const table = tables.find(table => table._id === datasource.tableId)
let schema = {} let schema
if (table) { if (table) {
if (type === "table") { if (type === "table") {
schema = table.schema ?? {} schema = table.schema ?? {}
@ -98,5 +100,12 @@ const getSchemaForDatasource = datasource => {
schema = table.schema ?? {} schema = table.schema ?? {}
} }
} }
if (schema) {
// Add ID and rev fields for any valid datasources
schema["_id"] = { type: "string" }
schema["_rev"] = { type: "string " }
} else {
schema = {}
}
return { schema, table } return { schema, table }
} }