PR feedback and refactoring

This commit is contained in:
Dean 2023-11-30 10:42:21 +00:00
parent 782f37590f
commit 848fea0621
5 changed files with 32 additions and 16 deletions

View File

@ -69,7 +69,14 @@ export const selectedComponent = derived(
if (!$selectedScreen || !$store.selectedComponentId) { if (!$selectedScreen || !$store.selectedComponentId) {
return null return null
} }
return findComponent($selectedScreen?.props, $store.selectedComponentId) const selected = findComponent(
$selectedScreen?.props,
$store.selectedComponentId
)
const clone = selected ? Object.assign({}, selected) : selected
store.actions.components.migrateSettings(clone)
return clone
} }
) )

View File

@ -601,17 +601,16 @@ export const getFrontendStore = () => {
// Finally try an external table // Finally try an external table
return validTables.find(table => table.sourceType === DB_TYPE_EXTERNAL) return validTables.find(table => table.sourceType === DB_TYPE_EXTERNAL)
}, },
processNestedSettings: enrichedComponent => { migrateSettings: enrichedComponent => {
const componentPrefix = "@budibase/standard-components" const componentPrefix = "@budibase/standard-components"
let migrated = false
if (enrichedComponent?._component == `${componentPrefix}/formblock`) { if (enrichedComponent?._component == `${componentPrefix}/formblock`) {
// Use default config if the 'buttons' prop has never been initialised // Use default config if the 'buttons' prop has never been initialised
if (!("buttons" in enrichedComponent)) { if (!("buttons" in enrichedComponent)) {
enrichedComponent["buttons"] = enrichedComponent["buttons"] =
Utils.buildDynamicButtonConfig(enrichedComponent) Utils.buildDynamicButtonConfig(enrichedComponent)
//Ensure existing Formblocks position their buttons at the top. migrated = true
enrichedComponent["buttonPosition"] =
enrichedComponent["buttonPosition"] || "top"
} else if (enrichedComponent["buttons"] == null) { } else if (enrichedComponent["buttons"] == null) {
// Ignore legacy config if 'buttons' has been reset by 'resetOn' // Ignore legacy config if 'buttons' has been reset by 'resetOn'
const { _id, actionType, dataSource } = enrichedComponent const { _id, actionType, dataSource } = enrichedComponent
@ -620,8 +619,17 @@ export const getFrontendStore = () => {
actionType, actionType,
dataSource, dataSource,
}) })
migrated = true
}
// Ensure existing Formblocks position their buttons at the top.
if (!("buttonPosition" in enrichedComponent)) {
enrichedComponent["buttonPosition"] = "top"
migrated = true
} }
} }
return migrated
}, },
enrichEmptySettings: (component, opts) => { enrichEmptySettings: (component, opts) => {
if (!component?._component) { if (!component?._component) {
@ -743,8 +751,8 @@ export const getFrontendStore = () => {
useDefaultValues: true, useDefaultValues: true,
}) })
// Process nested component settings // Migrate nested component settings
store.actions.components.processNestedSettings(instance) store.actions.components.migrateSettings(instance)
// Add any extra properties the component needs // Add any extra properties the component needs
let extras = {} let extras = {}
@ -869,7 +877,13 @@ export const getFrontendStore = () => {
if (!component) { if (!component) {
return false return false
} }
return patchFn(component, screen)
// Mutates the fetched component with updates
const updated = patchFn(component, screen)
// Mutates the component with any required settings updates
const migrated = store.actions.components.migrateSettings(component)
return updated || migrated
} }
await store.actions.screens.patch(patchScreen, screenId) await store.actions.screens.patch(patchScreen, screenId)
}, },
@ -1299,9 +1313,7 @@ export const getFrontendStore = () => {
}) })
} }
component[name] = value component[name] = value
return true
// Process nested component settings
store.actions.components.processNestedSettings(component)
} }
}, },
requestEjectBlock: componentId => { requestEjectBlock: componentId => {
@ -1309,7 +1321,6 @@ export const getFrontendStore = () => {
}, },
handleEjectBlock: async (componentId, ejectedDefinition) => { handleEjectBlock: async (componentId, ejectedDefinition) => {
let nextSelectedComponentId let nextSelectedComponentId
console.log("EJECTING")
await store.actions.screens.patch(screen => { await store.actions.screens.patch(screen => {
const block = findComponent(screen.props, componentId) const block = findComponent(screen.props, componentId)
const parent = findComponentParent(screen.props, componentId) const parent = findComponentParent(screen.props, componentId)

View File

@ -19,8 +19,6 @@
export let includeHidden = false export let includeHidden = false
export let tag export let tag
$: store.actions.components.processNestedSettings(componentInstance)
$: sections = getSections( $: sections = getSections(
componentInstance, componentInstance,
componentDefinition, componentDefinition,

View File

@ -117,7 +117,7 @@
actionUrl, actionUrl,
dataSource, dataSource,
}), }),
buttonPosition, buttonPosition: buttons ? buttonPosition : "top",
} }
const fetchSchema = async () => { const fetchSchema = async () => {
schema = (await fetchDatasourceSchema(dataSource)) || {} schema = (await fetchDatasourceSchema(dataSource)) || {}

View File

@ -10,7 +10,7 @@
export let fields export let fields
export let title export let title
export let description export let description
export let buttons = [] export let buttons
export let buttonPosition = "bottom" export let buttonPosition = "bottom"
export let schema export let schema