Update schema generation to automatically include _id and _rev fields
This commit is contained in:
parent
aef82e29a6
commit
b9c43052f6
|
@ -74,7 +74,7 @@ export const getDatasourceForProvider = (asset, component) => {
|
||||||
})
|
})
|
||||||
if (dataProviderSetting) {
|
if (dataProviderSetting) {
|
||||||
const settingValue = component[dataProviderSetting.key]
|
const settingValue = component[dataProviderSetting.key]
|
||||||
const providerId = settingValue.match(/{{\s*literal\s+(\S+)\s*}}/)[1]
|
const providerId = settingValue?.match(/{{\s*literal\s+(\S+)\s*}}/)[1]
|
||||||
if (providerId) {
|
if (providerId) {
|
||||||
const provider = findComponent(asset.props, providerId)
|
const provider = findComponent(asset.props, providerId)
|
||||||
return getDatasourceForProvider(asset, provider)
|
return getDatasourceForProvider(asset, provider)
|
||||||
|
@ -148,12 +148,6 @@ const getContextBindings = (asset, componentId) => {
|
||||||
const info = getSchemaForDatasource(datasource)
|
const info = getSchemaForDatasource(datasource)
|
||||||
schema = info.schema
|
schema = info.schema
|
||||||
readablePrefix = info.table?.name
|
readablePrefix = info.table?.name
|
||||||
|
|
||||||
// Add _id and _rev fields for certain types
|
|
||||||
if (schema && ["table", "link"].includes(datasource.type)) {
|
|
||||||
schema["_id"] = { type: "string" }
|
|
||||||
schema["_rev"] = { type: "string" }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!schema) {
|
if (!schema) {
|
||||||
return
|
return
|
||||||
|
@ -205,13 +199,10 @@ const getContextBindings = (asset, componentId) => {
|
||||||
*/
|
*/
|
||||||
const getUserBindings = () => {
|
const getUserBindings = () => {
|
||||||
let bindings = []
|
let bindings = []
|
||||||
const tables = get(backendUiStore).tables
|
const schema = getSchemaForDatasource({
|
||||||
const userTable = tables.find(table => table._id === TableNames.USERS)
|
type: "table",
|
||||||
const schema = {
|
tableId: TableNames.USERS,
|
||||||
...userTable.schema,
|
})
|
||||||
_id: { type: "string" },
|
|
||||||
_rev: { type: "string" },
|
|
||||||
}
|
|
||||||
const keys = Object.keys(schema).sort()
|
const keys = Object.keys(schema).sort()
|
||||||
keys.forEach(key => {
|
keys.forEach(key => {
|
||||||
const fieldSchema = schema[key]
|
const fieldSchema = schema[key]
|
||||||
|
@ -273,15 +264,6 @@ export const getSchemaForDatasource = (datasource, isForm = false) => {
|
||||||
if (table) {
|
if (table) {
|
||||||
if (type === "view") {
|
if (type === "view") {
|
||||||
schema = cloneDeep(table.views?.[datasource.name]?.schema)
|
schema = cloneDeep(table.views?.[datasource.name]?.schema)
|
||||||
|
|
||||||
// Some calc views don't include a "name" property inside the schema
|
|
||||||
if (schema) {
|
|
||||||
Object.keys(schema).forEach(field => {
|
|
||||||
if (!schema[field].name) {
|
|
||||||
schema[field].name = field
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else if (type === "query" && isForm) {
|
} else if (type === "query" && isForm) {
|
||||||
schema = {}
|
schema = {}
|
||||||
const params = table.parameters || []
|
const params = table.parameters || []
|
||||||
|
@ -294,6 +276,21 @@ export const getSchemaForDatasource = (datasource, isForm = false) => {
|
||||||
schema = cloneDeep(table.schema)
|
schema = cloneDeep(table.schema)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add _id and _rev fields for certain types
|
||||||
|
if (schema && ["table", "link"].includes(datasource.type)) {
|
||||||
|
schema["_id"] = { type: "string" }
|
||||||
|
schema["_rev"] = { type: "string" }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure there are "name" properties for all fields
|
||||||
|
if (schema) {
|
||||||
|
Object.keys(schema).forEach(field => {
|
||||||
|
if (!schema[field].name) {
|
||||||
|
schema[field].name = field
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return { schema, table }
|
return { schema, table }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue