Validate in all screen

This commit is contained in:
Adria Navarro 2025-01-27 10:28:54 +01:00
parent 52330a30b8
commit 92606c6129
1 changed files with 21 additions and 23 deletions

View File

@ -7,12 +7,12 @@ import { UIDatasourceType, Screen } from "@budibase/types"
import { queries } from "./queries" import { queries } from "./queries"
import { views } from "./views" import { views } from "./views"
import { bindings, featureFlag } from "@/helpers" import { bindings, featureFlag } from "@/helpers"
import { screenComponentBindableProperties } from "./bindings" import { getBindableProperties } from "@/dataBinding"
function reduceBy<TItem extends {}, TKey extends keyof TItem>( function reduceBy<TItem extends {}, TKey extends keyof TItem>(
key: TKey, key: TKey,
list: TItem[] list: TItem[]
) { ): Record<string, any> {
return list.reduce( return list.reduce(
(result, item) => ({ (result, item) => ({
...result, ...result,
@ -36,22 +36,11 @@ const validationKeyByType: Record<UIDatasourceType, string | null> = {
} }
export const screenComponentErrors = derived( export const screenComponentErrors = derived(
[ [selectedScreen, tables, views, viewsV2, queries],
selectedScreen, ([$selectedScreen, $tables, $views, $viewsV2, $queries]): Record<
tables, string,
views, string[]
viewsV2, > => {
queries,
screenComponentBindableProperties,
],
([
$selectedScreen,
$tables,
$views,
$viewsV2,
$queries,
$screenComponentBindableProperties,
]): Record<string, string[]> => {
if (!featureFlag.isEnabled("CHECK_SCREEN_COMPONENT_SETTINGS_ERRORS")) { if (!featureFlag.isEnabled("CHECK_SCREEN_COMPONENT_SETTINGS_ERRORS")) {
return {} return {}
} }
@ -72,8 +61,21 @@ export const screenComponentErrors = derived(
if (!validationKey) { if (!validationKey) {
continue continue
} }
const componentBindings = getBindableProperties(
$selectedScreen,
component._id
)
const componentDatasources = {
...reduceBy(
"rowId",
bindings.extractRelationships(componentBindings)
),
}
const resourceId = componentSettings[validationKey] const resourceId = componentSettings[validationKey]
if (!datasources[resourceId]) { if (!{ ...datasources, ...componentDatasources }[resourceId]) {
const friendlyTypeName = friendlyNameByType[type] ?? type const friendlyTypeName = friendlyNameByType[type] ?? type
result[component._id!] = [ result[component._id!] = [
`The ${friendlyTypeName} named "${label}" could not be found`, `The ${friendlyTypeName} named "${label}" could not be found`,
@ -89,10 +91,6 @@ export const screenComponentErrors = derived(
...reduceBy("name", $views.list), ...reduceBy("name", $views.list),
...reduceBy("id", $viewsV2.list), ...reduceBy("id", $viewsV2.list),
...reduceBy("_id", $queries.list), ...reduceBy("_id", $queries.list),
...reduceBy(
"rowId",
bindings.extractRelationships($screenComponentBindableProperties)
),
} }
return getInvalidDatasources($selectedScreen, datasources) return getInvalidDatasources($selectedScreen, datasources)