pr feedback
This commit is contained in:
parent
e9bf78abe0
commit
233112e30f
|
@ -87,7 +87,7 @@
|
||||||
if (isStateUpdateHandler(handler)) {
|
if (isStateUpdateHandler(handler)) {
|
||||||
foundComponents.push({
|
foundComponents.push({
|
||||||
id: componentId,
|
id: componentId,
|
||||||
name: instanceName,
|
name: instanceName + " - " + setting,
|
||||||
settings: [setting],
|
settings: [setting],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -103,20 +103,22 @@
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
Object.entries(component).forEach(([propName, propValue]) => {
|
Object.entries(component)
|
||||||
if (Array.isArray(propValue)) {
|
.filter(([key]) => key !== "_children")
|
||||||
propValue.forEach(item => {
|
.forEach(([propName, propValue]) => {
|
||||||
eventHandlerProps.forEach(eventType => {
|
if (Array.isArray(propValue)) {
|
||||||
checkEventHandlers(
|
propValue.forEach(item => {
|
||||||
item[eventType],
|
eventHandlerProps.forEach(eventType => {
|
||||||
component._id!,
|
checkEventHandlers(
|
||||||
component._instanceName,
|
item[eventType],
|
||||||
propName
|
component._id!,
|
||||||
)
|
component._instanceName,
|
||||||
|
propName
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
}
|
})
|
||||||
})
|
|
||||||
|
|
||||||
if (component._children) {
|
if (component._children) {
|
||||||
for (let child of component._children) {
|
for (let child of component._children) {
|
||||||
|
@ -140,84 +142,41 @@
|
||||||
return bindings.join(" ").includes(stateKey)
|
return bindings.join(" ").includes(stateKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSettingsWithState = (component: any, stateKey: string): string[] => {
|
const getSettingsWithState = (
|
||||||
const settingsWithState: string[] = []
|
component: Component,
|
||||||
|
stateKey: string
|
||||||
const searchForStateBinding = (value: any, path: string[]) => {
|
): string[] => {
|
||||||
if (typeof value === "string") {
|
return Object.entries(component)
|
||||||
if (hasStateBinding(value, stateKey)) {
|
.filter(([key]) => key !== "_children")
|
||||||
const topLevelProperty = path[0]
|
.filter(([_, value]) => hasStateBinding(JSON.stringify(value), stateKey))
|
||||||
if (!settingsWithState.includes(topLevelProperty)) {
|
.map(([key]) => key)
|
||||||
settingsWithState.push(topLevelProperty)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (Array.isArray(value)) {
|
|
||||||
value.forEach((item, index) => {
|
|
||||||
searchForStateBinding(item, [...path, `${index}`])
|
|
||||||
})
|
|
||||||
} else if (typeof value === "object" && value !== null) {
|
|
||||||
Object.entries(value).forEach(([key, val]) => {
|
|
||||||
searchForStateBinding(val, [...path, key])
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.entries(component).forEach(([key, value]) => {
|
|
||||||
if (["_children", "_styles", "_conditions"].includes(key)) return
|
|
||||||
|
|
||||||
searchForStateBinding(value, [key])
|
|
||||||
})
|
|
||||||
|
|
||||||
return settingsWithState
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkConditions = (conditions: any[], stateKey: string): boolean => {
|
|
||||||
return conditions.some(condition =>
|
|
||||||
[condition.referenceValue, condition.newValue].some(
|
|
||||||
value => typeof value === "string" && hasStateBinding(value, stateKey)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const checkStyles = (styles: any, stateKey: string): boolean => {
|
|
||||||
return (
|
|
||||||
typeof styles?.custom === "string" &&
|
|
||||||
hasStateBinding(styles.custom, stateKey)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const findComponentsUsingState = (
|
const findComponentsUsingState = (
|
||||||
component: any,
|
component: Component,
|
||||||
stateKey: string
|
stateKey: string
|
||||||
): ComponentUsingState[] => {
|
): ComponentUsingState[] => {
|
||||||
let componentsUsingState: ComponentUsingState[] = []
|
let componentsUsingState: ComponentUsingState[] = []
|
||||||
const { _children, _styles, _conditions, ...componentSettings } = component
|
const { _children } = component
|
||||||
|
|
||||||
const settingsWithState = getSettingsWithState(componentSettings, stateKey)
|
const settingsWithState = getSettingsWithState(component, stateKey)
|
||||||
settingsWithState.forEach(setting => {
|
settingsWithState.forEach(setting => {
|
||||||
|
if (setting === "_conditions") {
|
||||||
|
setting = "Conditions"
|
||||||
|
} else if (setting === "_styles") {
|
||||||
|
setting = "Styles"
|
||||||
|
}
|
||||||
|
const label =
|
||||||
|
componentStore
|
||||||
|
.getDefinition(component._component)
|
||||||
|
?.settings?.find(t => t.key === setting)?.label || setting
|
||||||
|
|
||||||
componentsUsingState.push({
|
componentsUsingState.push({
|
||||||
id: component._id,
|
id: component._id!,
|
||||||
name: `${component._instanceName} - ${setting}`,
|
name: `${component._instanceName} - ${label}`,
|
||||||
settings: [setting],
|
settings: [setting],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
if (_conditions?.length > 0 && checkConditions(_conditions, stateKey)) {
|
|
||||||
componentsUsingState.push({
|
|
||||||
id: component._id,
|
|
||||||
name: `${component._instanceName} - conditions`,
|
|
||||||
settings: ["_conditions"],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_styles && checkStyles(_styles, stateKey)) {
|
|
||||||
componentsUsingState.push({
|
|
||||||
id: component._id,
|
|
||||||
name: `${component._instanceName} - styles`,
|
|
||||||
settings: ["_styles"],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_children) {
|
if (_children) {
|
||||||
for (let child of _children) {
|
for (let child of _children) {
|
||||||
componentsUsingState = [
|
componentsUsingState = [
|
||||||
|
@ -234,7 +193,6 @@
|
||||||
if (!stateKey || !$selectedScreen?.props) {
|
if (!stateKey || !$selectedScreen?.props) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const componentStateUpdates = findComponentsUpdatingState(
|
const componentStateUpdates = findComponentsUpdatingState(
|
||||||
$selectedScreen.props,
|
$selectedScreen.props,
|
||||||
stateKey
|
stateKey
|
||||||
|
@ -254,7 +212,7 @@
|
||||||
)
|
)
|
||||||
.map(() => ({
|
.map(() => ({
|
||||||
id: $selectedScreen._id!,
|
id: $selectedScreen._id!,
|
||||||
name: "Screen onLoad",
|
name: "Screen - onLoad",
|
||||||
settings: ["onLoad"],
|
settings: ["onLoad"],
|
||||||
})) || []
|
})) || []
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,7 @@ export interface ComponentDefinition {
|
||||||
export interface ComponentSetting {
|
export interface ComponentSetting {
|
||||||
key: string
|
key: string
|
||||||
type: string
|
type: string
|
||||||
|
label?: string
|
||||||
section?: string
|
section?: string
|
||||||
name?: string
|
name?: string
|
||||||
defaultValue?: any
|
defaultValue?: any
|
||||||
|
|
Loading…
Reference in New Issue