Make update type forms to work with global bindings
This commit is contained in:
parent
f78cc26a68
commit
917e837ffc
|
@ -216,6 +216,7 @@
|
||||||
errorState,
|
errorState,
|
||||||
parent: id,
|
parent: id,
|
||||||
ancestors: [...($component?.ancestors ?? []), instance._component],
|
ancestors: [...($component?.ancestors ?? []), instance._component],
|
||||||
|
path: [...($component?.path ?? []), id],
|
||||||
})
|
})
|
||||||
|
|
||||||
const initialise = (instance, force = false) => {
|
const initialise = (instance, force = false) => {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
export let editAutoColumns = false
|
export let editAutoColumns = false
|
||||||
|
|
||||||
const context = getContext("context")
|
const context = getContext("context")
|
||||||
|
const component = getContext("component")
|
||||||
const { API, fetchDatasourceSchema } = getContext("sdk")
|
const { API, fetchDatasourceSchema } = getContext("sdk")
|
||||||
|
|
||||||
const getInitialFormStep = () => {
|
const getInitialFormStep = () => {
|
||||||
|
@ -37,28 +38,36 @@
|
||||||
|
|
||||||
$: fetchSchema(dataSource)
|
$: fetchSchema(dataSource)
|
||||||
$: schemaKey = generateSchemaKey(schema)
|
$: schemaKey = generateSchemaKey(schema)
|
||||||
$: initialValues = getInitialValues(actionType, dataSource, $context)
|
$: initialValues = getInitialValues(
|
||||||
|
actionType,
|
||||||
|
dataSource,
|
||||||
|
$component.path,
|
||||||
|
$context
|
||||||
|
)
|
||||||
$: resetKey = Helpers.hashString(
|
$: resetKey = Helpers.hashString(
|
||||||
schemaKey + JSON.stringify(initialValues) + disabled
|
schemaKey + JSON.stringify(initialValues) + disabled
|
||||||
)
|
)
|
||||||
|
|
||||||
// Returns the closes data context which isn't a built in context
|
// Returns the closes data context which isn't a built in context
|
||||||
const getInitialValues = (type, dataSource, context) => {
|
const getInitialValues = (type, dataSource, path, context) => {
|
||||||
// Only inherit values for update forms
|
// Only inherit values for update forms
|
||||||
if (type !== "Update") {
|
if (type !== "Update") {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
// Only inherit values for forms targeting internal tables
|
// Only inherit values for forms targeting internal tables
|
||||||
if (!dataSource?.tableId) {
|
const dsType = dataSource?.type
|
||||||
|
if (dsType !== "table" && dsType !== "viewV2") {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
// Don't inherit values representing built in contexts
|
// Look up the component tree and find something that is provided by an
|
||||||
if (["user", "url"].includes(context.closestComponentId)) {
|
// ancestor that matches our datasource. This is for backwards compatibility
|
||||||
return {}
|
// as previously we could use the "closest" context.
|
||||||
|
for (let id of path.reverse().slice(1)) {
|
||||||
|
if (context[id]?.tableId === dataSource.tableId) {
|
||||||
|
return context[id]
|
||||||
}
|
}
|
||||||
// Always inherit the closest datasource
|
}
|
||||||
const closestContext = context[`${context.closestComponentId}`] || {}
|
return {}
|
||||||
return closestContext || {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetches the form schema from this form's dataSource
|
// Fetches the form schema from this form's dataSource
|
||||||
|
|
Loading…
Reference in New Issue