Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate custom components #15469

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions eslint-local-rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ module.exports = {
if (
/^@budibase\/[^/]+\/.*$/.test(importPath) &&
importPath !== "@budibase/backend-core/tests" &&
importPath !== "@budibase/string-templates/test/utils" &&
importPath !== "@budibase/client/manifest.json"
importPath !== "@budibase/string-templates/test/utils"
) {
context.report({
node,
message: `Importing from @budibase is not allowed, except for @budibase/backend-core/tests, @budibase/string-templates/test/utils and @budibase/client/manifest.json.`,
message: `Importing from @budibase is not allowed, except for @budibase/backend-core/tests and @budibase/string-templates/test/utils.`,
})
}
},
Expand Down
46 changes: 0 additions & 46 deletions packages/builder/src/helpers/screen.ts

This file was deleted.

72 changes: 60 additions & 12 deletions packages/builder/src/stores/builder/screenComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import { derived } from "svelte/store"
import { tables } from "./tables"
import { selectedScreen } from "./screens"
import { viewsV2 } from "./viewsV2"
import { findComponentsBySettingsType } from "@/helpers/screen"
import { UIDatasourceType, Screen, Component } from "@budibase/types"
import {
UIDatasourceType,
Screen,
Component,
ScreenProps,
} from "@budibase/types"
import { queries } from "./queries"
import { views } from "./views"
import { bindings, featureFlag } from "@/helpers"
import { getBindableProperties } from "@/dataBinding"
import { componentStore, ComponentDefinition } from "./components"
import { findAllComponents } from "@/helpers/components"

function reduceBy<TItem extends {}, TKey extends keyof TItem>(
Expand Down Expand Up @@ -39,11 +44,15 @@ const validationKeyByType: Record<UIDatasourceType, string | null> = {
}

export const screenComponentErrors = derived(
[selectedScreen, tables, views, viewsV2, queries],
([$selectedScreen, $tables, $views, $viewsV2, $queries]): Record<
string,
string[]
> => {
[selectedScreen, tables, views, viewsV2, queries, componentStore],
([
$selectedScreen,
$tables,
$views,
$viewsV2,
$queries,
$componentStore,
]): Record<string, string[]> => {
if (!featureFlag.isEnabled("CHECK_SCREEN_COMPONENT_SETTINGS_ERRORS")) {
return {}
}
Expand All @@ -52,9 +61,11 @@ export const screenComponentErrors = derived(
datasources: Record<string, any>
) {
const result: Record<string, string[]> = {}

for (const { component, setting } of findComponentsBySettingsType(
screen,
["table", "dataSource"]
["table", "dataSource"],
$componentStore.components
)) {
const componentSettings = component[setting.key]
if (!componentSettings) {
Expand Down Expand Up @@ -113,15 +124,52 @@ export const screenComponentErrors = derived(
}
)

function findComponentsBySettingsType(
screen: Screen,
type: string | string[],
definitions: Record<string, ComponentDefinition>
) {
const typesArray = Array.isArray(type) ? type : [type]

const result: {
component: Component
setting: {
type: string
key: string
}
}[] = []

function recurseFieldComponentsInChildren(component: ScreenProps) {
if (!component) {
return
}

const definition = definitions[component._component]

const setting = definition?.settings?.find((s: any) =>
typesArray.includes(s.type)
)
if (setting && "type" in setting) {
result.push({
component,
setting: { type: setting.type!, key: setting.key! },
})
}
component._children?.forEach(child => {
recurseFieldComponentsInChildren(child)
})
}

recurseFieldComponentsInChildren(screen?.props)
return result
}

export const screenComponents = derived(
[selectedScreen],
([$selectedScreen]) => {
if (!$selectedScreen) {
return []
}
const allComponents = findAllComponents(
$selectedScreen.props
) as Component[]
return allComponents
return findAllComponents($selectedScreen.props) as Component[]
}
)
Loading