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