Screen helpers, findComponentsBySettingsType

This commit is contained in:
Adria Navarro 2025-01-20 15:55:17 +01:00
parent ba2a61841f
commit 7e02938619
1 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,30 @@
import { Component, Screen, ScreenProps } from "@budibase/types"
import clientManifest from "@budibase/client/manifest.json"
export function findComponentsBySettingsType(screen: Screen, type: string) {
const result: Component[] = []
function recurseFieldComponentsInChildren(
component: ScreenProps,
type: string
) {
if (!component) {
return
}
const componentType = component._component.split("/").slice(-1)[0]
const definition =
clientManifest[componentType as keyof typeof clientManifest]
if (
"settings" in definition &&
definition.settings.some((s: any) => s.type === type)
) {
result.push(component)
}
component._children?.forEach(child => {
recurseFieldComponentsInChildren(child, type)
})
}
recurseFieldComponentsInChildren(screen?.props, type)
return result
}