Merge pull request #15477 from Budibase/BUDI-9016/design-errors-popup
Design errors popover
This commit is contained in:
commit
18b296a850
|
@ -1,7 +1,7 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import "@spectrum-css/divider/dist/index-vars.css"
|
import "@spectrum-css/divider/dist/index-vars.css"
|
||||||
|
|
||||||
export let size = "M"
|
export let size: "S" | "M" | "L" = "M"
|
||||||
|
|
||||||
export let vertical = false
|
export let vertical = false
|
||||||
export let noMargin = false
|
export let noMargin = false
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import "@spectrum-css/link/dist/index-vars.css"
|
import "@spectrum-css/link/dist/index-vars.css"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
import Tooltip from "../Tooltip/Tooltip.svelte"
|
import Tooltip from "../Tooltip/Tooltip.svelte"
|
||||||
|
|
||||||
export let href = "#"
|
export let href: string | null = "#"
|
||||||
export let size = "M"
|
export let size: "S" | "M" | "L" = "M"
|
||||||
export let quiet = false
|
export let quiet: boolean = false
|
||||||
export let primary = false
|
export let primary: boolean = false
|
||||||
export let secondary = false
|
export let secondary: boolean = false
|
||||||
export let overBackground = false
|
export let overBackground: boolean = false
|
||||||
export let target = undefined
|
export let target: string | undefined = undefined
|
||||||
export let download = undefined
|
export let download: boolean | undefined = undefined
|
||||||
export let disabled = false
|
export let disabled: boolean = false
|
||||||
export let tooltip = null
|
export let tooltip: string | null = null
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,26 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8" width="8" height="8">
|
<script lang="ts">
|
||||||
<circle cx="4" cy="4" r="4" stroke-width="0" fill="currentColor" />
|
export let color = "currentColor"
|
||||||
|
export let size: "S" | "M" = "M"
|
||||||
|
|
||||||
|
const sizes = {
|
||||||
|
S: 6,
|
||||||
|
M: 8,
|
||||||
|
}
|
||||||
|
|
||||||
|
$: sizePx = sizes[size]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
viewBox={`0 0 ${sizePx} ${sizePx}`}
|
||||||
|
width={`${sizePx}`}
|
||||||
|
height={`${sizePx}`}
|
||||||
|
>
|
||||||
|
<circle
|
||||||
|
cx={sizePx / 2}
|
||||||
|
cy={sizePx / 2}
|
||||||
|
r={sizePx / 2}
|
||||||
|
stroke-width="0"
|
||||||
|
fill={color}
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|
Before Width: | Height: | Size: 157 B After Width: | Height: | Size: 417 B |
|
@ -25,16 +25,16 @@
|
||||||
export let wide
|
export let wide
|
||||||
|
|
||||||
let highlightType
|
let highlightType
|
||||||
|
let domElement
|
||||||
|
|
||||||
$: highlightedProp = $builderStore.highlightedSetting
|
$: highlightedProp = $builderStore.highlightedSetting
|
||||||
$: allBindings = getAllBindings(bindings, componentBindings, nested)
|
$: allBindings = getAllBindings(bindings, componentBindings, nested)
|
||||||
$: safeValue = getSafeValue(value, defaultValue, allBindings)
|
$: safeValue = getSafeValue(value, defaultValue, allBindings)
|
||||||
$: replaceBindings = val => readableToRuntimeBinding(allBindings, val)
|
$: replaceBindings = val => readableToRuntimeBinding(allBindings, val)
|
||||||
|
|
||||||
$: if (value) {
|
$: isHighlighted = highlightedProp?.key === key
|
||||||
highlightType =
|
|
||||||
highlightedProp?.key === key ? `highlighted-${highlightedProp?.type}` : ""
|
$: highlightType = isHighlighted ? `highlighted-${highlightedProp?.type}` : ""
|
||||||
}
|
|
||||||
|
|
||||||
const getAllBindings = (bindings, componentBindings, nested) => {
|
const getAllBindings = (bindings, componentBindings, nested) => {
|
||||||
if (!nested) {
|
if (!nested) {
|
||||||
|
@ -74,9 +74,19 @@
|
||||||
? defaultValue
|
? defaultValue
|
||||||
: enriched
|
: enriched
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function scrollToElement(element) {
|
||||||
|
element?.scrollIntoView({
|
||||||
|
behavior: "smooth",
|
||||||
|
block: "center",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
$: highlightedProp && isHighlighted && scrollToElement(domElement)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
bind:this={domElement}
|
||||||
id={`${key}-prop-control-wrap`}
|
id={`${key}-prop-control-wrap`}
|
||||||
class={`property-control ${highlightType}`}
|
class={`property-control ${highlightType}`}
|
||||||
class:wide={!label || labelHidden || wide === true}
|
class:wide={!label || labelHidden || wide === true}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
import AppPreview from "./AppPreview.svelte"
|
import AppPreview from "./AppPreview.svelte"
|
||||||
import { screenStore, appStore } from "@/stores/builder"
|
import { screenStore, appStore } from "@/stores/builder"
|
||||||
import UndoRedoControl from "@/components/common/UndoRedoControl.svelte"
|
import UndoRedoControl from "@/components/common/UndoRedoControl.svelte"
|
||||||
|
import ScreenErrorsButton from "./ScreenErrorsButton.svelte"
|
||||||
|
import { Divider } from "@budibase/bbui"
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="app-panel">
|
<div class="app-panel">
|
||||||
|
@ -15,6 +17,8 @@
|
||||||
{#if $appStore.clientFeatures.devicePreview}
|
{#if $appStore.clientFeatures.devicePreview}
|
||||||
<DevicePreviewSelect />
|
<DevicePreviewSelect />
|
||||||
{/if}
|
{/if}
|
||||||
|
<Divider vertical />
|
||||||
|
<ScreenErrorsButton />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
@ -62,7 +66,7 @@
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: var(--spacing-xl);
|
gap: var(--spacing-l);
|
||||||
}
|
}
|
||||||
.content {
|
.content {
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
|
|
|
@ -183,16 +183,6 @@
|
||||||
toggleAddComponent()
|
toggleAddComponent()
|
||||||
} else if (type === "highlight-setting") {
|
} else if (type === "highlight-setting") {
|
||||||
builderStore.highlightSetting(data.setting, "error")
|
builderStore.highlightSetting(data.setting, "error")
|
||||||
|
|
||||||
// Also scroll setting into view
|
|
||||||
const selector = `#${data.setting}-prop-control`
|
|
||||||
const element = document.querySelector(selector)?.parentElement
|
|
||||||
if (element) {
|
|
||||||
element.scrollIntoView({
|
|
||||||
behavior: "smooth",
|
|
||||||
block: "center",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else if (type === "eject-block") {
|
} else if (type === "eject-block") {
|
||||||
const { id, definition } = data
|
const { id, definition } = data
|
||||||
await componentStore.handleEjectBlock(id, definition)
|
await componentStore.handleEjectBlock(id, definition)
|
||||||
|
|
|
@ -0,0 +1,124 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import type { UIComponentError } from "@budibase/types"
|
||||||
|
import {
|
||||||
|
builderStore,
|
||||||
|
componentStore,
|
||||||
|
screenComponentErrorList,
|
||||||
|
screenComponentsList,
|
||||||
|
} from "@/stores/builder"
|
||||||
|
import {
|
||||||
|
AbsTooltip,
|
||||||
|
ActionButton,
|
||||||
|
Icon,
|
||||||
|
Link,
|
||||||
|
Popover,
|
||||||
|
PopoverAlignment,
|
||||||
|
TooltipPosition,
|
||||||
|
} from "@budibase/bbui"
|
||||||
|
import CircleIndicator from "@/components/common/Icons/CircleIndicator.svelte"
|
||||||
|
|
||||||
|
let button: any
|
||||||
|
let popover: any
|
||||||
|
|
||||||
|
$: hasErrors = !!$screenComponentErrorList.length
|
||||||
|
|
||||||
|
function getErrorTitle(error: UIComponentError) {
|
||||||
|
const titleParts = [
|
||||||
|
$screenComponentsList.find(c => c._id === error.componentId)!
|
||||||
|
._instanceName,
|
||||||
|
]
|
||||||
|
if (error.errorType === "setting" && error.cause === "invalid") {
|
||||||
|
titleParts.push(error.label)
|
||||||
|
}
|
||||||
|
return titleParts.join(" - ")
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onErrorClick(error: UIComponentError) {
|
||||||
|
componentStore.select(error.componentId)
|
||||||
|
if (error.errorType === "setting") {
|
||||||
|
builderStore.highlightSetting(error.key, "error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div bind:this={button} class="error-button">
|
||||||
|
<AbsTooltip
|
||||||
|
text={!hasErrors ? "No errors found!" : ""}
|
||||||
|
position={TooltipPosition.Top}
|
||||||
|
>
|
||||||
|
<ActionButton
|
||||||
|
quiet
|
||||||
|
disabled={!hasErrors}
|
||||||
|
on:click={() => popover.show()}
|
||||||
|
size="M"
|
||||||
|
icon="Alert"
|
||||||
|
/>
|
||||||
|
{#if hasErrors}
|
||||||
|
<div class="error-indicator">
|
||||||
|
<CircleIndicator
|
||||||
|
size="S"
|
||||||
|
color="var(--spectrum-global-color-static-red-600)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</AbsTooltip>
|
||||||
|
</div>
|
||||||
|
<Popover
|
||||||
|
bind:this={popover}
|
||||||
|
anchor={button}
|
||||||
|
align={PopoverAlignment.Right}
|
||||||
|
maxWidth={400}
|
||||||
|
showPopover={hasErrors}
|
||||||
|
>
|
||||||
|
<div class="error-popover">
|
||||||
|
{#each $screenComponentErrorList as error}
|
||||||
|
<div class="error">
|
||||||
|
<Icon
|
||||||
|
name="Alert"
|
||||||
|
color="var(--spectrum-global-color-static-red-600)"
|
||||||
|
size="S"
|
||||||
|
/>
|
||||||
|
<div>
|
||||||
|
<Link overBackground on:click={() => onErrorClick(error)}>
|
||||||
|
{getErrorTitle(error)}
|
||||||
|
</Link>:
|
||||||
|
<!-- eslint-disable-next-line svelte/no-at-html-tags-->
|
||||||
|
{@html error.message}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</Popover>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.error-button {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.error-indicator {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 8px;
|
||||||
|
}
|
||||||
|
.error-popover {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.error-popover .error {
|
||||||
|
display: inline-flex;
|
||||||
|
flex-direction: row;
|
||||||
|
padding: var(--spacing-m);
|
||||||
|
gap: var(--spacing-s);
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
.error-popover .error:not(:last-child) {
|
||||||
|
border-bottom: 1px solid var(--spectrum-global-color-gray-300);
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-popover .error :global(mark) {
|
||||||
|
background: unset;
|
||||||
|
color: unset;
|
||||||
|
}
|
||||||
|
.error-popover .error :global(.spectrum-Link) {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -21,7 +21,7 @@ import {
|
||||||
tables,
|
tables,
|
||||||
componentTreeNodesStore,
|
componentTreeNodesStore,
|
||||||
builderStore,
|
builderStore,
|
||||||
screenComponents,
|
screenComponentsList,
|
||||||
} from "@/stores/builder"
|
} from "@/stores/builder"
|
||||||
import { buildFormSchema, getSchemaForDatasource } from "@/dataBinding"
|
import { buildFormSchema, getSchemaForDatasource } from "@/dataBinding"
|
||||||
import {
|
import {
|
||||||
|
@ -450,7 +450,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const componentName = getSequentialName(
|
const componentName = getSequentialName(
|
||||||
get(screenComponents),
|
get(screenComponentsList),
|
||||||
`New ${definition.friendlyName || definition.name}`,
|
`New ${definition.friendlyName || definition.name}`,
|
||||||
{
|
{
|
||||||
getName: c => c._instanceName,
|
getName: c => c._instanceName,
|
||||||
|
|
|
@ -17,9 +17,9 @@ import { deploymentStore } from "./deployments.js"
|
||||||
import { contextMenuStore } from "./contextMenu.js"
|
import { contextMenuStore } from "./contextMenu.js"
|
||||||
import { snippets } from "./snippets"
|
import { snippets } from "./snippets"
|
||||||
import {
|
import {
|
||||||
screenComponents,
|
screenComponentsList,
|
||||||
screenComponentErrors,
|
screenComponentErrors,
|
||||||
findComponentsBySettingsType,
|
screenComponentErrorList,
|
||||||
} from "./screenComponent"
|
} from "./screenComponent"
|
||||||
|
|
||||||
// Backend
|
// Backend
|
||||||
|
@ -72,9 +72,9 @@ export {
|
||||||
snippets,
|
snippets,
|
||||||
rowActions,
|
rowActions,
|
||||||
appPublished,
|
appPublished,
|
||||||
screenComponents,
|
screenComponentsList,
|
||||||
screenComponentErrors,
|
screenComponentErrors,
|
||||||
findComponentsBySettingsType,
|
screenComponentErrorList,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const reset = () => {
|
export const reset = () => {
|
||||||
|
|
|
@ -4,11 +4,10 @@ import { selectedScreen } from "./screens"
|
||||||
import { viewsV2 } from "./viewsV2"
|
import { viewsV2 } from "./viewsV2"
|
||||||
import {
|
import {
|
||||||
UIDatasourceType,
|
UIDatasourceType,
|
||||||
Screen,
|
|
||||||
Component,
|
Component,
|
||||||
UIComponentError,
|
UIComponentError,
|
||||||
ScreenProps,
|
|
||||||
ComponentDefinition,
|
ComponentDefinition,
|
||||||
|
DependsOnComponentSetting,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { queries } from "./queries"
|
import { queries } from "./queries"
|
||||||
import { views } from "./views"
|
import { views } from "./views"
|
||||||
|
@ -21,14 +20,11 @@ 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,
|
||||||
list: TItem[]
|
list: TItem[]
|
||||||
): Record<string, any> {
|
): Record<string, TItem> {
|
||||||
return list.reduce(
|
return list.reduce<Record<string, TItem>>((result, item) => {
|
||||||
(result, item) => ({
|
result[item[key] as string] = item
|
||||||
...result,
|
return result
|
||||||
[item[key] as string]: item,
|
}, {})
|
||||||
}),
|
|
||||||
{}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const friendlyNameByType: Partial<Record<UIDatasourceType, string>> = {
|
const friendlyNameByType: Partial<Record<UIDatasourceType, string>> = {
|
||||||
|
@ -46,7 +42,18 @@ const validationKeyByType: Record<UIDatasourceType, string | null> = {
|
||||||
jsonarray: "value",
|
jsonarray: "value",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const screenComponentErrors = derived(
|
export const screenComponentsList = derived(
|
||||||
|
[selectedScreen],
|
||||||
|
([$selectedScreen]): Component[] => {
|
||||||
|
if (!$selectedScreen) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
return findAllComponents($selectedScreen.props)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
export const screenComponentErrorList = derived(
|
||||||
[selectedScreen, tables, views, viewsV2, queries, componentStore],
|
[selectedScreen, tables, views, viewsV2, queries, componentStore],
|
||||||
([
|
([
|
||||||
$selectedScreen,
|
$selectedScreen,
|
||||||
|
@ -55,9 +62,9 @@ export const screenComponentErrors = derived(
|
||||||
$viewsV2,
|
$viewsV2,
|
||||||
$queries,
|
$queries,
|
||||||
$componentStore,
|
$componentStore,
|
||||||
]): Record<string, UIComponentError[]> => {
|
]): UIComponentError[] => {
|
||||||
if (!$selectedScreen) {
|
if (!$selectedScreen) {
|
||||||
return {}
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
const datasources = {
|
const datasources = {
|
||||||
|
@ -69,116 +76,152 @@ export const screenComponentErrors = derived(
|
||||||
|
|
||||||
const { components: definitions } = $componentStore
|
const { components: definitions } = $componentStore
|
||||||
|
|
||||||
const errors = {
|
const errors: UIComponentError[] = []
|
||||||
...getInvalidDatasources($selectedScreen, datasources, definitions),
|
|
||||||
...getMissingAncestors($selectedScreen, definitions),
|
function checkComponentErrors(component: Component, ancestors: string[]) {
|
||||||
...getMissingRequiredSettings($selectedScreen, definitions),
|
errors.push(...getInvalidDatasources(component, datasources, definitions))
|
||||||
|
errors.push(...getMissingRequiredSettings(component, definitions))
|
||||||
|
errors.push(...getMissingAncestors(component, definitions, ancestors))
|
||||||
|
|
||||||
|
for (const child of component._children || []) {
|
||||||
|
checkComponentErrors(child, [...ancestors, component._component])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkComponentErrors($selectedScreen?.props, [])
|
||||||
|
|
||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
function getInvalidDatasources(
|
function getInvalidDatasources(
|
||||||
screen: Screen,
|
component: Component,
|
||||||
datasources: Record<string, any>,
|
datasources: Record<string, any>,
|
||||||
definitions: Record<string, ComponentDefinition>
|
definitions: Record<string, ComponentDefinition>
|
||||||
) {
|
) {
|
||||||
const result: Record<string, UIComponentError[]> = {}
|
const result: UIComponentError[] = []
|
||||||
for (const { component, setting } of findComponentsBySettingsType(
|
|
||||||
screen,
|
|
||||||
["table", "dataSource"],
|
|
||||||
definitions
|
|
||||||
)) {
|
|
||||||
const componentSettings = component[setting.key]
|
|
||||||
if (!componentSettings) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
const { label } = componentSettings
|
const datasourceTypes = ["table", "dataSource"]
|
||||||
const type = componentSettings.type as UIDatasourceType
|
|
||||||
|
|
||||||
const validationKey = validationKeyByType[type]
|
const possibleSettings = definitions[component._component]?.settings?.filter(
|
||||||
if (!validationKey) {
|
s => datasourceTypes.includes(s.type)
|
||||||
continue
|
)
|
||||||
}
|
if (possibleSettings) {
|
||||||
|
for (const setting of possibleSettings) {
|
||||||
|
const componentSettings = component[setting.key]
|
||||||
|
if (!componentSettings) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
const componentBindings = getBindableProperties(screen, component._id)
|
const { label } = componentSettings
|
||||||
|
const type = componentSettings.type as UIDatasourceType
|
||||||
|
|
||||||
const componentDatasources = {
|
const validationKey = validationKeyByType[type]
|
||||||
...reduceBy("rowId", bindings.extractRelationships(componentBindings)),
|
if (!validationKey) {
|
||||||
...reduceBy("value", bindings.extractFields(componentBindings)),
|
continue
|
||||||
...reduceBy("value", bindings.extractJSONArrayFields(componentBindings)),
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const resourceId = componentSettings[validationKey]
|
const componentBindings = getBindableProperties(screen, component._id)
|
||||||
if (!{ ...datasources, ...componentDatasources }[resourceId]) {
|
|
||||||
const friendlyTypeName = friendlyNameByType[type] ?? type
|
const componentDatasources = {
|
||||||
result[component._id!] = [
|
...reduceBy("rowId", bindings.extractRelationships(componentBindings)),
|
||||||
{
|
...reduceBy("value", bindings.extractFields(componentBindings)),
|
||||||
|
...reduceBy(
|
||||||
|
"value",
|
||||||
|
bindings.extractJSONArrayFields(componentBindings)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
const resourceId = componentSettings[validationKey]
|
||||||
|
if (!{ ...datasources, ...componentDatasources }[resourceId]) {
|
||||||
|
const friendlyTypeName = friendlyNameByType[type] ?? type
|
||||||
|
result.push({
|
||||||
|
componentId: component._id!,
|
||||||
key: setting.key,
|
key: setting.key,
|
||||||
|
label: setting.label || setting.key,
|
||||||
message: `The ${friendlyTypeName} named "${label}" could not be found`,
|
message: `The ${friendlyTypeName} named "${label}" could not be found`,
|
||||||
|
|
||||||
errorType: "setting",
|
errorType: "setting",
|
||||||
},
|
cause: "invalid",
|
||||||
]
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseDependsOn(dependsOn: DependsOnComponentSetting | undefined): {
|
||||||
|
key?: string
|
||||||
|
value?: string
|
||||||
|
} {
|
||||||
|
if (dependsOn === undefined) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof dependsOn === "string") {
|
||||||
|
return { key: dependsOn }
|
||||||
|
}
|
||||||
|
|
||||||
|
return { key: dependsOn.setting, value: dependsOn.value }
|
||||||
|
}
|
||||||
|
|
||||||
function getMissingRequiredSettings(
|
function getMissingRequiredSettings(
|
||||||
screen: Screen,
|
component: Component,
|
||||||
definitions: Record<string, ComponentDefinition>
|
definitions: Record<string, ComponentDefinition>
|
||||||
) {
|
) {
|
||||||
const allComponents = findAllComponents(screen.props) as Component[]
|
const result: UIComponentError[] = []
|
||||||
|
|
||||||
const result: Record<string, UIComponentError[]> = {}
|
const definition = definitions[component._component]
|
||||||
for (const component of allComponents) {
|
|
||||||
const definition = definitions[component._component]
|
|
||||||
|
|
||||||
const settings = getSettingsDefinition(definition)
|
const settings = getSettingsDefinition(definition)
|
||||||
|
|
||||||
const missingRequiredSettings = settings.filter((setting: any) => {
|
const missingRequiredSettings = settings.filter(setting => {
|
||||||
let empty =
|
let empty = component[setting.key] == null || component[setting.key] === ""
|
||||||
component[setting.key] == null || component[setting.key] === ""
|
let missing = setting.required && empty
|
||||||
let missing = setting.required && empty
|
|
||||||
|
|
||||||
// Check if this setting depends on another, as it may not be required
|
// Check if this setting depends on another, as it may not be required
|
||||||
if (setting.dependsOn) {
|
if (setting.dependsOn) {
|
||||||
const dependsOnKey = setting.dependsOn.setting || setting.dependsOn
|
const { key: dependsOnKey, value: dependsOnValue } = parseDependsOn(
|
||||||
const dependsOnValue = setting.dependsOn.value
|
setting.dependsOn
|
||||||
const realDependentValue = component[dependsOnKey]
|
)
|
||||||
|
const realDependentValue =
|
||||||
|
component[dependsOnKey as keyof typeof component]
|
||||||
|
|
||||||
const sectionDependsOnKey =
|
const { key: sectionDependsOnKey, value: sectionDependsOnValue } =
|
||||||
setting.sectionDependsOn?.setting || setting.sectionDependsOn
|
parseDependsOn(setting.sectionDependsOn)
|
||||||
const sectionDependsOnValue = setting.sectionDependsOn?.value
|
const sectionRealDependentValue =
|
||||||
const sectionRealDependentValue = component[sectionDependsOnKey]
|
component[sectionDependsOnKey as keyof typeof component]
|
||||||
|
|
||||||
if (dependsOnValue == null && realDependentValue == null) {
|
if (dependsOnValue == null && realDependentValue == null) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (dependsOnValue != null && dependsOnValue !== realDependentValue) {
|
if (dependsOnValue != null && dependsOnValue !== realDependentValue) {
|
||||||
return false
|
return false
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
sectionDependsOnValue != null &&
|
|
||||||
sectionDependsOnValue !== sectionRealDependentValue
|
|
||||||
) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return missing
|
if (
|
||||||
})
|
sectionDependsOnValue != null &&
|
||||||
|
sectionDependsOnValue !== sectionRealDependentValue
|
||||||
|
) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (missingRequiredSettings?.length) {
|
return missing
|
||||||
result[component._id!] = missingRequiredSettings.map((s: any) => ({
|
})
|
||||||
|
|
||||||
|
if (missingRequiredSettings?.length) {
|
||||||
|
result.push(
|
||||||
|
...missingRequiredSettings.map<UIComponentError>(s => ({
|
||||||
|
componentId: component._id!,
|
||||||
key: s.key,
|
key: s.key,
|
||||||
|
label: s.label || s.key,
|
||||||
message: `Add the <mark>${s.label}</mark> setting to start using your component`,
|
message: `Add the <mark>${s.label}</mark> setting to start using your component`,
|
||||||
errorType: "setting",
|
errorType: "setting",
|
||||||
|
cause: "missing",
|
||||||
}))
|
}))
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -186,34 +229,31 @@ function getMissingRequiredSettings(
|
||||||
|
|
||||||
const BudibasePrefix = "@budibase/standard-components/"
|
const BudibasePrefix = "@budibase/standard-components/"
|
||||||
function getMissingAncestors(
|
function getMissingAncestors(
|
||||||
screen: Screen,
|
component: Component,
|
||||||
definitions: Record<string, ComponentDefinition>
|
definitions: Record<string, ComponentDefinition>,
|
||||||
) {
|
ancestors: string[]
|
||||||
const result: Record<string, UIComponentError[]> = {}
|
): UIComponentError[] {
|
||||||
|
const definition = definitions[component._component]
|
||||||
|
|
||||||
function checkMissingAncestors(component: Component, ancestors: string[]) {
|
if (!definition?.requiredAncestors?.length) {
|
||||||
for (const child of component._children || []) {
|
return []
|
||||||
checkMissingAncestors(child, [...ancestors, component._component])
|
}
|
||||||
|
|
||||||
|
const result: UIComponentError[] = []
|
||||||
|
const missingAncestors = definition.requiredAncestors.filter(
|
||||||
|
ancestor => !ancestors.includes(`${BudibasePrefix}${ancestor}`)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (missingAncestors.length) {
|
||||||
|
const pluralise = (name: string) => {
|
||||||
|
return name.endsWith("s") ? `${name}'` : `${name}s`
|
||||||
}
|
}
|
||||||
|
|
||||||
const definition = definitions[component._component]
|
result.push(
|
||||||
|
...missingAncestors.map<UIComponentError>(ancestor => {
|
||||||
if (!definition?.requiredAncestors?.length) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const missingAncestors = definition.requiredAncestors.filter(
|
|
||||||
ancestor => !ancestors.includes(`${BudibasePrefix}${ancestor}`)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (missingAncestors.length) {
|
|
||||||
const pluralise = (name: string) => {
|
|
||||||
return name.endsWith("s") ? `${name}'` : `${name}s`
|
|
||||||
}
|
|
||||||
|
|
||||||
result[component._id!] = missingAncestors.map(ancestor => {
|
|
||||||
const ancestorDefinition = definitions[`${BudibasePrefix}${ancestor}`]
|
const ancestorDefinition = definitions[`${BudibasePrefix}${ancestor}`]
|
||||||
return {
|
return {
|
||||||
|
componentId: component._id!,
|
||||||
message: `${pluralise(definition.name)} need to be inside a
|
message: `${pluralise(definition.name)} need to be inside a
|
||||||
<mark>${ancestorDefinition.name}</mark>`,
|
<mark>${ancestorDefinition.name}</mark>`,
|
||||||
errorType: "ancestor-setting",
|
errorType: "ancestor-setting",
|
||||||
|
@ -223,59 +263,19 @@ function getMissingAncestors(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
checkMissingAncestors(screen.props, [])
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
export 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) {
|
|
||||||
result.push({
|
|
||||||
component,
|
|
||||||
setting: { type: setting.type, key: setting.key },
|
|
||||||
})
|
|
||||||
}
|
|
||||||
component._children?.forEach(child => {
|
|
||||||
recurseFieldComponentsInChildren(child)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
recurseFieldComponentsInChildren(screen?.props)
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export const screenComponents = derived(
|
export const screenComponentErrors = derived(
|
||||||
[selectedScreen],
|
[screenComponentErrorList],
|
||||||
([$selectedScreen]) => {
|
([$list]): Record<string, UIComponentError[]> => {
|
||||||
if (!$selectedScreen) {
|
return $list.reduce<Record<string, UIComponentError[]>>((obj, error) => {
|
||||||
return []
|
obj[error.componentId] ??= []
|
||||||
}
|
obj[error.componentId].push(error)
|
||||||
return findAllComponents($selectedScreen.props) as Component[]
|
return obj
|
||||||
|
}, {})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
interface BaseUIComponentError {
|
interface BaseUIComponentError {
|
||||||
|
componentId: string
|
||||||
message: string
|
message: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UISettingComponentError extends BaseUIComponentError {
|
interface UISettingComponentError extends BaseUIComponentError {
|
||||||
errorType: "setting"
|
errorType: "setting"
|
||||||
key: string
|
key: string
|
||||||
|
label: string
|
||||||
|
cause: "missing" | "invalid"
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UIAncestorComponentError extends BaseUIComponentError {
|
interface UIAncestorComponentError extends BaseUIComponentError {
|
||||||
|
|
|
@ -15,20 +15,24 @@ export interface ComponentDefinition {
|
||||||
illegalChildren: string[]
|
illegalChildren: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DependsOnComponentSetting =
|
||||||
|
| string
|
||||||
|
| {
|
||||||
|
setting: string
|
||||||
|
value: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface ComponentSetting {
|
export interface ComponentSetting {
|
||||||
key: string
|
key: string
|
||||||
type: string
|
type: string
|
||||||
label?: string
|
label?: string
|
||||||
section?: string
|
section?: string
|
||||||
name?: string
|
name?: string
|
||||||
|
required?: boolean
|
||||||
defaultValue?: any
|
defaultValue?: any
|
||||||
selectAllFields?: boolean
|
selectAllFields?: boolean
|
||||||
resetOn?: string | string[]
|
resetOn?: string | string[]
|
||||||
settings?: ComponentSetting[]
|
settings?: ComponentSetting[]
|
||||||
dependsOn?:
|
dependsOn?: DependsOnComponentSetting
|
||||||
| string
|
sectionDependsOn?: DependsOnComponentSetting
|
||||||
| {
|
|
||||||
setting: string
|
|
||||||
value: string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue