Fix checking ancestors

This commit is contained in:
Adria Navarro 2025-01-28 09:59:53 +01:00
parent 684cf27f0e
commit 582854cc2e
1 changed files with 12 additions and 11 deletions

View File

@ -122,13 +122,7 @@ function getInvalidDatasources(
} }
function getAllComponentsInScreen(screen: Screen) { function getAllComponentsInScreen(screen: Screen) {
const result: Component[] = [] return findAllComponents(screen.props) as Component[]
function recursiveCheck(component: Component) {
result.push(...findAllComponents(component))
component._children?.forEach(recursiveCheck)
}
recursiveCheck(screen.props)
return result
} }
function getMissingRequiredSettings(screen: Screen) { function getMissingRequiredSettings(screen: Screen) {
@ -191,16 +185,21 @@ function getMissingRequiredSettings(screen: Screen) {
const BudibasePrefix = "@budibase/standard-components/" const BudibasePrefix = "@budibase/standard-components/"
function getMissingAncestors(screen: Screen) { function getMissingAncestors(screen: Screen) {
const allComponents = getAllComponentsInScreen(screen)
const result: Record<string, UIComponentError[]> = {} const result: Record<string, UIComponentError[]> = {}
for (const component of allComponents) {
function checkMissingAncestors(component: Component, ancestors: string[]) {
for (const child of component._children || []) {
checkMissingAncestors(child, [...ancestors, component._component])
}
const definition = getManifestDefinition(component) const definition = getManifestDefinition(component)
if (!("requiredAncestors" in definition)) { if (!("requiredAncestors" in definition)) {
continue return
} }
const missingAncestors = definition.requiredAncestors.filter( const missingAncestors = definition.requiredAncestors.filter(
ancestor => !component.ancestors?.includes(`${BudibasePrefix}${ancestor}`) ancestor => !ancestors.includes(`${BudibasePrefix}${ancestor}`)
) )
if (missingAncestors.length) { if (missingAncestors.length) {
@ -223,5 +222,7 @@ function getMissingAncestors(screen: Screen) {
}) })
} }
} }
checkMissingAncestors(screen.props, [])
return result return result
} }