Validate ancestors
This commit is contained in:
parent
a0fb2c8e59
commit
224e12f7f3
|
@ -38,8 +38,11 @@ export function findComponentsBySettingsType(
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getManifestDefinition(component: Component) {
|
export function getManifestDefinition(component: Component | string) {
|
||||||
const componentType = component._component.split("/").slice(-1)[0]
|
const componentType =
|
||||||
|
typeof component === "string"
|
||||||
|
? component
|
||||||
|
: component._component.split("/").slice(-1)[0]
|
||||||
const definition =
|
const definition =
|
||||||
clientManifest[componentType as keyof typeof clientManifest]
|
clientManifest[componentType as keyof typeof clientManifest]
|
||||||
return definition
|
return definition
|
||||||
|
|
|
@ -65,6 +65,7 @@ export const screenComponentErrors = derived(
|
||||||
|
|
||||||
const errors = {
|
const errors = {
|
||||||
...getInvalidDatasources($selectedScreen, datasources),
|
...getInvalidDatasources($selectedScreen, datasources),
|
||||||
|
...getMissingAncestors($selectedScreen),
|
||||||
...getMissingRequiredSettings($selectedScreen),
|
...getMissingRequiredSettings($selectedScreen),
|
||||||
}
|
}
|
||||||
return errors
|
return errors
|
||||||
|
@ -182,3 +183,37 @@ function getMissingRequiredSettings(screen: Screen) {
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const BudibasePrefix = "@budibase/standard-components/"
|
||||||
|
function getMissingAncestors(screen: Screen) {
|
||||||
|
const allComponents = getAllComponentsInScreen(screen)
|
||||||
|
const result: Record<string, UIComponentError[]> = {}
|
||||||
|
for (const component of allComponents) {
|
||||||
|
const definition = getManifestDefinition(component)
|
||||||
|
if (!("requiredAncestors" in definition)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
const missingAncestors = definition.requiredAncestors.filter(
|
||||||
|
ancestor => !component.ancestors?.includes(`${BudibasePrefix}${ancestor}`)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (missingAncestors.length) {
|
||||||
|
const pluralise = (name: string) => {
|
||||||
|
return name.endsWith("s") ? `${name}'` : `${name}s`
|
||||||
|
}
|
||||||
|
|
||||||
|
const getAncestorName = (name: string) => {
|
||||||
|
const definition: any = getManifestDefinition(name)
|
||||||
|
return definition.name
|
||||||
|
}
|
||||||
|
|
||||||
|
result[component._id!] = missingAncestors.map((s: any) => ({
|
||||||
|
key: s.key,
|
||||||
|
message: `${pluralise(component._instanceName)} need to be inside a
|
||||||
|
<mark>${getAncestorName(s)}</mark>`,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue