Support searching for multiple types
This commit is contained in:
parent
a860f050fc
commit
10a669e1d7
|
@ -1,7 +1,12 @@
|
||||||
import { Component, Screen, ScreenProps } from "@budibase/types"
|
import { Component, Screen, ScreenProps } from "@budibase/types"
|
||||||
import clientManifest from "@budibase/client/manifest.json"
|
import clientManifest from "@budibase/client/manifest.json"
|
||||||
|
|
||||||
export function findComponentsBySettingsType(screen: Screen, type: string) {
|
export function findComponentsBySettingsType(
|
||||||
|
screen: Screen,
|
||||||
|
type: string | string[]
|
||||||
|
) {
|
||||||
|
const typesArray = Array.isArray(type) ? type : [type]
|
||||||
|
|
||||||
const result: {
|
const result: {
|
||||||
component: Component
|
component: Component
|
||||||
setting: {
|
setting: {
|
||||||
|
@ -9,10 +14,7 @@ export function findComponentsBySettingsType(screen: Screen, type: string) {
|
||||||
key: string
|
key: string
|
||||||
}
|
}
|
||||||
}[] = []
|
}[] = []
|
||||||
function recurseFieldComponentsInChildren(
|
function recurseFieldComponentsInChildren(component: ScreenProps) {
|
||||||
component: ScreenProps,
|
|
||||||
type: string
|
|
||||||
) {
|
|
||||||
if (!component) {
|
if (!component) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -20,7 +22,7 @@ export function findComponentsBySettingsType(screen: Screen, type: string) {
|
||||||
const definition = getManifestDefinition(component)
|
const definition = getManifestDefinition(component)
|
||||||
const setting =
|
const setting =
|
||||||
"settings" in definition &&
|
"settings" in definition &&
|
||||||
definition.settings.find((s: any) => s.type === type)
|
definition.settings.find((s: any) => typesArray.includes(s.type))
|
||||||
if (setting && "type" in setting) {
|
if (setting && "type" in setting) {
|
||||||
result.push({
|
result.push({
|
||||||
component,
|
component,
|
||||||
|
@ -28,11 +30,11 @@ export function findComponentsBySettingsType(screen: Screen, type: string) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
component._children?.forEach(child => {
|
component._children?.forEach(child => {
|
||||||
recurseFieldComponentsInChildren(child, type)
|
recurseFieldComponentsInChildren(child)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
recurseFieldComponentsInChildren(screen?.props, type)
|
recurseFieldComponentsInChildren(screen?.props)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue