find components that are updating state
This commit is contained in:
parent
e14bf007db
commit
7cb422f806
|
@ -31,7 +31,7 @@
|
||||||
$: safeValue = getSafeValue(value, defaultValue, allBindings)
|
$: safeValue = getSafeValue(value, defaultValue, allBindings)
|
||||||
$: replaceBindings = val => readableToRuntimeBinding(allBindings, val)
|
$: replaceBindings = val => readableToRuntimeBinding(allBindings, val)
|
||||||
|
|
||||||
$: if (!Array.isArray(value)) {
|
$: if (value) {
|
||||||
const highlightedSetting = highlightedSettings?.find(
|
const highlightedSetting = highlightedSettings?.find(
|
||||||
setting => setting.key === key
|
setting => setting.key === key
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,15 +12,57 @@
|
||||||
isJSBinding,
|
isJSBinding,
|
||||||
} from "@budibase/string-templates"
|
} from "@budibase/string-templates"
|
||||||
|
|
||||||
let modal: Modal
|
type ComponentUsingState = {
|
||||||
let selectedKey: string | null = null
|
|
||||||
let componentsUsingState: Array<{
|
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
settings: string[]
|
settings: string[]
|
||||||
}> = []
|
}[]
|
||||||
|
|
||||||
|
let modal: Modal
|
||||||
|
let selectedKey: string | null = null
|
||||||
|
let componentsUsingState: ComponentUsingState = []
|
||||||
|
let componentsUpdatingState: ComponentUsingState = []
|
||||||
|
|
||||||
const keyOptions = getAllStateVariables()
|
const keyOptions = getAllStateVariables()
|
||||||
|
|
||||||
|
function findComponentsUpdatingState(
|
||||||
|
component: any,
|
||||||
|
stateKey: string
|
||||||
|
): ComponentUsingState {
|
||||||
|
let foundComponents: ComponentUsingState = []
|
||||||
|
|
||||||
|
const eventHandlerProps = ["onClick", "onChange"]
|
||||||
|
|
||||||
|
eventHandlerProps.forEach(eventType => {
|
||||||
|
const handlers = component[eventType]
|
||||||
|
if (Array.isArray(handlers)) {
|
||||||
|
handlers.forEach(handler => {
|
||||||
|
if (
|
||||||
|
handler["##eventHandlerType"] === "Update State" &&
|
||||||
|
handler.parameters?.key === stateKey
|
||||||
|
) {
|
||||||
|
foundComponents.push({
|
||||||
|
id: component._id,
|
||||||
|
name: component._instanceName,
|
||||||
|
settings: [eventType],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (component._children) {
|
||||||
|
for (let child of component._children) {
|
||||||
|
foundComponents = [
|
||||||
|
...foundComponents,
|
||||||
|
...findComponentsUpdatingState(child, stateKey),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return foundComponents
|
||||||
|
}
|
||||||
|
|
||||||
function findComponentsUsingState(
|
function findComponentsUsingState(
|
||||||
component: any,
|
component: any,
|
||||||
stateKey: string
|
stateKey: string
|
||||||
|
@ -32,7 +74,6 @@
|
||||||
}> = []
|
}> = []
|
||||||
|
|
||||||
const { _children, ...componentSettings } = component
|
const { _children, ...componentSettings } = component
|
||||||
|
|
||||||
let settingsWithState: string[] = []
|
let settingsWithState: string[] = []
|
||||||
|
|
||||||
for (const [setting, value] of Object.entries(componentSettings)) {
|
for (const [setting, value] of Object.entries(componentSettings)) {
|
||||||
|
@ -83,6 +124,10 @@
|
||||||
$selectedScreen.props,
|
$selectedScreen.props,
|
||||||
selectedKey
|
selectedKey
|
||||||
)
|
)
|
||||||
|
componentsUpdatingState = findComponentsUpdatingState(
|
||||||
|
$selectedScreen.props,
|
||||||
|
selectedKey
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +137,6 @@
|
||||||
settings: string[]
|
settings: string[]
|
||||||
}) {
|
}) {
|
||||||
componentStore.select(component.id)
|
componentStore.select(component.id)
|
||||||
|
|
||||||
component.settings.forEach(setting => {
|
component.settings.forEach(setting => {
|
||||||
builderStore.highlightSetting(setting)
|
builderStore.highlightSetting(setting)
|
||||||
})
|
})
|
||||||
|
@ -121,6 +165,24 @@
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if componentsUpdatingState.length > 0}
|
||||||
|
<div class="components-list">
|
||||||
|
<h4>Components updating this state:</h4>
|
||||||
|
{#each componentsUpdatingState as component}
|
||||||
|
<button
|
||||||
|
class="component-link"
|
||||||
|
on:click={() =>
|
||||||
|
onClickComponentLink({
|
||||||
|
id: component.id,
|
||||||
|
name: component.name,
|
||||||
|
settings: component.settings,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{component.name} (via {component.settings.join(", ")})
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue