Remove magic string for settings
This commit is contained in:
parent
51614d61d5
commit
5c9cc915ff
|
@ -2,7 +2,13 @@ import { Component, Screen, ScreenProps } from "@budibase/types"
|
|||
import clientManifest from "@budibase/client/manifest.json"
|
||||
|
||||
export function findComponentsBySettingsType(screen: Screen, type: string) {
|
||||
const result: Component[] = []
|
||||
const result: {
|
||||
component: Component
|
||||
setting: {
|
||||
type: string
|
||||
key: string
|
||||
}
|
||||
}[] = []
|
||||
function recurseFieldComponentsInChildren(
|
||||
component: ScreenProps,
|
||||
type: string
|
||||
|
@ -11,14 +17,15 @@ export function findComponentsBySettingsType(screen: Screen, type: string) {
|
|||
return
|
||||
}
|
||||
|
||||
const componentType = component._component.split("/").slice(-1)[0]
|
||||
const definition =
|
||||
clientManifest[componentType as keyof typeof clientManifest]
|
||||
if (
|
||||
const definition = getManifestDefinition(component)
|
||||
const setting =
|
||||
"settings" in definition &&
|
||||
definition.settings.some((s: any) => s.type === type)
|
||||
) {
|
||||
result.push(component)
|
||||
definition.settings.find((s: any) => s.type === type)
|
||||
if (setting && "type" in setting) {
|
||||
result.push({
|
||||
component,
|
||||
setting: { type: setting.type!, key: setting.key! },
|
||||
})
|
||||
}
|
||||
component._children?.forEach(child => {
|
||||
recurseFieldComponentsInChildren(child, type)
|
||||
|
@ -28,3 +35,10 @@ export function findComponentsBySettingsType(screen: Screen, type: string) {
|
|||
recurseFieldComponentsInChildren(screen?.props, type)
|
||||
return result
|
||||
}
|
||||
|
||||
function getManifestDefinition(component: Component) {
|
||||
const componentType = component._component.split("/").slice(-1)[0]
|
||||
const definition =
|
||||
clientManifest[componentType as keyof typeof clientManifest]
|
||||
return definition
|
||||
}
|
||||
|
|
|
@ -38,8 +38,11 @@ export const screenComponentErrors = derived(
|
|||
}
|
||||
|
||||
const result: Record<string, string[]> = {}
|
||||
for (const component of findComponentsBySettingsType(screen, "table")) {
|
||||
const { resourceId, type, label } = component.dataSource
|
||||
for (const { component, setting } of findComponentsBySettingsType(
|
||||
screen,
|
||||
"table"
|
||||
)) {
|
||||
const { resourceId, type, label } = component[setting.key]
|
||||
if (!datasources[resourceId]) {
|
||||
const friendlyTypeName =
|
||||
friendlyNameByType[type as keyof typeof friendlyNameByType]
|
||||
|
|
Loading…
Reference in New Issue