From 92606c6129458bd499320d6994b7ddae7f72cabc Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 27 Jan 2025 10:28:54 +0100 Subject: [PATCH] Validate in all screen --- .../src/stores/builder/screenComponent.ts | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/packages/builder/src/stores/builder/screenComponent.ts b/packages/builder/src/stores/builder/screenComponent.ts index 1af10e8a80..3afb96994f 100644 --- a/packages/builder/src/stores/builder/screenComponent.ts +++ b/packages/builder/src/stores/builder/screenComponent.ts @@ -7,12 +7,12 @@ import { UIDatasourceType, Screen } from "@budibase/types" import { queries } from "./queries" import { views } from "./views" import { bindings, featureFlag } from "@/helpers" -import { screenComponentBindableProperties } from "./bindings" +import { getBindableProperties } from "@/dataBinding" function reduceBy( key: TKey, list: TItem[] -) { +): Record { return list.reduce( (result, item) => ({ ...result, @@ -36,22 +36,11 @@ const validationKeyByType: Record = { } export const screenComponentErrors = derived( - [ - selectedScreen, - tables, - views, - viewsV2, - queries, - screenComponentBindableProperties, - ], - ([ - $selectedScreen, - $tables, - $views, - $viewsV2, - $queries, - $screenComponentBindableProperties, - ]): Record => { + [selectedScreen, tables, views, viewsV2, queries], + ([$selectedScreen, $tables, $views, $viewsV2, $queries]): Record< + string, + string[] + > => { if (!featureFlag.isEnabled("CHECK_SCREEN_COMPONENT_SETTINGS_ERRORS")) { return {} } @@ -72,8 +61,21 @@ export const screenComponentErrors = derived( if (!validationKey) { continue } + + const componentBindings = getBindableProperties( + $selectedScreen, + component._id + ) + + const componentDatasources = { + ...reduceBy( + "rowId", + bindings.extractRelationships(componentBindings) + ), + } + const resourceId = componentSettings[validationKey] - if (!datasources[resourceId]) { + if (!{ ...datasources, ...componentDatasources }[resourceId]) { const friendlyTypeName = friendlyNameByType[type] ?? type result[component._id!] = [ `The ${friendlyTypeName} named "${label}" could not be found`, @@ -89,10 +91,6 @@ export const screenComponentErrors = derived( ...reduceBy("name", $views.list), ...reduceBy("id", $viewsV2.list), ...reduceBy("_id", $queries.list), - ...reduceBy( - "rowId", - bindings.extractRelationships($screenComponentBindableProperties) - ), } return getInvalidDatasources($selectedScreen, datasources)