Handle sections properly

This commit is contained in:
Adria Navarro 2025-01-31 13:55:27 +01:00
parent ea2b7b8791
commit 9976bcf125
1 changed files with 31 additions and 29 deletions

View File

@ -8,13 +8,15 @@ import {
Component, Component,
UIComponentError, UIComponentError,
ScreenProps, ScreenProps,
ComponentDefinition,
} from "@budibase/types" } from "@budibase/types"
import { queries } from "./queries" import { queries } from "./queries"
import { views } from "./views" import { views } from "./views"
import { findAllComponents } from "@/helpers/components" import { findAllComponents } from "@/helpers/components"
import { bindings, featureFlag } from "@/helpers" import { bindings, featureFlag } from "@/helpers"
import { getBindableProperties } from "@/dataBinding" import { getBindableProperties } from "@/dataBinding"
import { componentStore, ComponentDefinition } from "./components" import { componentStore } from "./components"
import { getSettingsDefinition } from "@budibase/frontend-core"
function reduceBy<TItem extends {}, TKey extends keyof TItem>( function reduceBy<TItem extends {}, TKey extends keyof TItem>(
key: TKey, key: TKey,
@ -137,41 +139,41 @@ function getMissingRequiredSettings(
for (const component of allComponents) { for (const component of allComponents) {
const definition = definitions[component._component] const definition = definitions[component._component]
const missingRequiredSettings = definition?.settings?.filter( const settings = getSettingsDefinition(definition)
(setting: any) => {
let empty =
component[setting.key] == null || component[setting.key] === ""
let missing = setting.required && empty
// Check if this setting depends on another, as it may not be required const missingRequiredSettings = settings.filter((setting: any) => {
if (setting.dependsOn) { let empty =
const dependsOnKey = setting.dependsOn.setting || setting.dependsOn component[setting.key] == null || component[setting.key] === ""
const dependsOnValue = setting.dependsOn.value let missing = setting.required && empty
const realDependentValue = component[dependsOnKey]
const sectionDependsOnKey = // Check if this setting depends on another, as it may not be required
setting.sectionDependsOn?.setting || setting.sectionDependsOn if (setting.dependsOn) {
const sectionDependsOnValue = setting.sectionDependsOn?.value const dependsOnKey = setting.dependsOn.setting || setting.dependsOn
const sectionRealDependentValue = component[sectionDependsOnKey] const dependsOnValue = setting.dependsOn.value
const realDependentValue = component[dependsOnKey]
if (dependsOnValue == null && realDependentValue == null) { const sectionDependsOnKey =
return false setting.sectionDependsOn?.setting || setting.sectionDependsOn
} const sectionDependsOnValue = setting.sectionDependsOn?.value
if (dependsOnValue != null && dependsOnValue !== realDependentValue) { const sectionRealDependentValue = component[sectionDependsOnKey]
return false
}
if ( if (dependsOnValue == null && realDependentValue == null) {
sectionDependsOnValue != null && return false
sectionDependsOnValue !== sectionRealDependentValue }
) { if (dependsOnValue != null && dependsOnValue !== realDependentValue) {
return false return false
}
} }
return missing if (
sectionDependsOnValue != null &&
sectionDependsOnValue !== sectionRealDependentValue
) {
return false
}
} }
)
return missing
})
if (missingRequiredSettings?.length) { if (missingRequiredSettings?.length) {
result[component._id!] = missingRequiredSettings.map((s: any) => ({ result[component._id!] = missingRequiredSettings.map((s: any) => ({