update binding generation to only find bindings from passed screen
This commit is contained in:
parent
7b13b54b52
commit
fe8200a1f1
|
@ -54,7 +54,7 @@ export const getBindableProperties = (asset, componentId) => {
|
||||||
const userBindings = getUserBindings()
|
const userBindings = getUserBindings()
|
||||||
const urlBindings = getUrlBindings(asset)
|
const urlBindings = getUrlBindings(asset)
|
||||||
const deviceBindings = getDeviceBindings()
|
const deviceBindings = getDeviceBindings()
|
||||||
const stateBindings = getStateBindings()
|
const stateBindings = getStateBindings(asset)
|
||||||
const selectedRowsBindings = getSelectedRowsBindings(asset)
|
const selectedRowsBindings = getSelectedRowsBindings(asset)
|
||||||
const roleBindings = getRoleBindings()
|
const roleBindings = getRoleBindings()
|
||||||
const embedBindings = getEmbedBindings()
|
const embedBindings = getEmbedBindings()
|
||||||
|
@ -711,10 +711,10 @@ export const makeStateBinding = key => {
|
||||||
/**
|
/**
|
||||||
* Gets all state bindings that are globally available.
|
* Gets all state bindings that are globally available.
|
||||||
*/
|
*/
|
||||||
const getStateBindings = () => {
|
const getStateBindings = asset => {
|
||||||
let bindings = []
|
let bindings = []
|
||||||
if (get(appStore).clientFeatures?.state) {
|
if (get(appStore).clientFeatures?.state) {
|
||||||
bindings = getAllStateVariables().map(makeStateBinding)
|
bindings = getAllStateVariables(asset).map(makeStateBinding)
|
||||||
}
|
}
|
||||||
return bindings
|
return bindings
|
||||||
}
|
}
|
||||||
|
@ -1160,28 +1160,39 @@ export const buildFormSchema = (component, asset) => {
|
||||||
* in the app.
|
* in the app.
|
||||||
*/
|
*/
|
||||||
export const getAllStateVariables = screen => {
|
export const getAllStateVariables = screen => {
|
||||||
let assets = []
|
let stateVars = new Set()
|
||||||
if (screen) {
|
|
||||||
// only include state variables from a specific screen
|
// Helper function to extract state variables with their persist status from actions
|
||||||
assets.push(screen)
|
const extractStateVariablesFromActions = actions => {
|
||||||
} else {
|
if (!Array.isArray(actions)) {
|
||||||
// otherwise include state variables from all screens
|
return []
|
||||||
assets = getAllAssets()
|
|
||||||
}
|
}
|
||||||
let eventSettings = []
|
return actions.reduce((vars, action) => {
|
||||||
assets.forEach(asset => {
|
if (
|
||||||
findAllMatchingComponents(asset.props, component => {
|
action["##eventHandlerType"] === "Update State" &&
|
||||||
const settings = componentStore.getComponentSettings(component._component)
|
action.parameters?.type === "set" &&
|
||||||
|
action.parameters?.key &&
|
||||||
|
action.parameters?.value
|
||||||
|
) {
|
||||||
|
vars.push({
|
||||||
|
key: action.parameters.key,
|
||||||
|
persisted: !!action.parameters.persist,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return vars
|
||||||
|
}, [])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extracts all event settings from a component instance.
|
||||||
|
// Recurses into nested types to find all event-like settings at any
|
||||||
|
// depth.
|
||||||
|
const parseEventSettings = (settings, comp, actions) => {
|
||||||
const nestedTypes = [
|
const nestedTypes = [
|
||||||
"buttonConfiguration",
|
"buttonConfiguration",
|
||||||
"fieldConfiguration",
|
"fieldConfiguration",
|
||||||
"stepConfiguration",
|
"stepConfiguration",
|
||||||
]
|
]
|
||||||
|
|
||||||
// Extracts all event settings from a component instance.
|
|
||||||
// Recurses into nested types to find all event-like settings at any
|
|
||||||
// depth.
|
|
||||||
const parseEventSettings = (settings, comp) => {
|
|
||||||
if (!settings?.length) {
|
if (!settings?.length) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1190,7 +1201,7 @@ export const getAllStateVariables = screen => {
|
||||||
settings
|
settings
|
||||||
.filter(setting => setting.type === "event")
|
.filter(setting => setting.type === "event")
|
||||||
.forEach(setting => {
|
.forEach(setting => {
|
||||||
eventSettings.push(comp[setting.key])
|
actions.push(...(comp[setting.key] || []))
|
||||||
})
|
})
|
||||||
|
|
||||||
// Recurse into any nested instance types
|
// Recurse into any nested instance types
|
||||||
|
@ -1210,47 +1221,46 @@ export const getAllStateVariables = screen => {
|
||||||
|
|
||||||
// Parsed nested component instances inside this setting
|
// Parsed nested component instances inside this setting
|
||||||
const nestedSettings = componentStore.getComponentSettings(type)
|
const nestedSettings = componentStore.getComponentSettings(type)
|
||||||
parseEventSettings(nestedSettings, instance)
|
parseEventSettings(nestedSettings, instance, actions)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
parseEventSettings(settings, component)
|
const collectScreenActions = screen => {
|
||||||
})
|
let actions = []
|
||||||
|
if (screen.onLoad) {
|
||||||
|
actions.push(...screen.onLoad)
|
||||||
|
}
|
||||||
|
findAllMatchingComponents(screen.props, component => {
|
||||||
|
const settings = componentStore.getComponentSettings(component._component)
|
||||||
|
parseEventSettings(settings, component, actions)
|
||||||
})
|
})
|
||||||
|
return actions
|
||||||
|
}
|
||||||
|
|
||||||
// Add on load settings from screens
|
// Get state variables from the specific screen
|
||||||
if (screen) {
|
if (screen) {
|
||||||
if (screen.onLoad) {
|
const screenActions = collectScreenActions(screen)
|
||||||
eventSettings.push(screen.onLoad)
|
extractStateVariablesFromActions(screenActions).forEach(
|
||||||
|
({ key, persisted }) => {
|
||||||
|
if (!persisted) stateVars.add(key)
|
||||||
}
|
}
|
||||||
} else {
|
)
|
||||||
get(screenStore).screens.forEach(screen => {
|
|
||||||
if (screen.onLoad) {
|
|
||||||
eventSettings.push(screen.onLoad)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract all state keys from any "update state" actions in each setting
|
// Now get all other state variables for the purpose of finding persisted ones
|
||||||
let bindingSet = new Set()
|
const allScreens = get(screenStore).screens
|
||||||
eventSettings.forEach(setting => {
|
allScreens.forEach(currentScreen => {
|
||||||
if (!Array.isArray(setting)) {
|
const screenActions = collectScreenActions(currentScreen)
|
||||||
return
|
extractStateVariablesFromActions(screenActions).forEach(
|
||||||
}
|
({ key, persisted }) => {
|
||||||
setting.forEach(action => {
|
if (persisted) stateVars.add(key)
|
||||||
if (
|
|
||||||
action["##eventHandlerType"] === "Update State" &&
|
|
||||||
action.parameters?.type === "set" &&
|
|
||||||
action.parameters?.key &&
|
|
||||||
action.parameters?.value
|
|
||||||
) {
|
|
||||||
bindingSet.add(action.parameters.key)
|
|
||||||
}
|
}
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
return Array.from(bindingSet)
|
return Array.from(stateVars)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getAllAssets = () => {
|
export const getAllAssets = () => {
|
||||||
|
|
Loading…
Reference in New Issue