Add CTA on component error
This commit is contained in:
parent
2537ee6980
commit
9f92f3414a
|
@ -6,7 +6,12 @@ import {
|
||||||
findComponentsBySettingsType,
|
findComponentsBySettingsType,
|
||||||
getManifestDefinition,
|
getManifestDefinition,
|
||||||
} from "@/helpers/screen"
|
} from "@/helpers/screen"
|
||||||
import { UIDatasourceType, Screen, Component } from "@budibase/types"
|
import {
|
||||||
|
UIDatasourceType,
|
||||||
|
Screen,
|
||||||
|
Component,
|
||||||
|
UIComponentError,
|
||||||
|
} from "@budibase/types"
|
||||||
import { queries } from "./queries"
|
import { queries } from "./queries"
|
||||||
import { views } from "./views"
|
import { views } from "./views"
|
||||||
import { featureFlag } from "@/helpers"
|
import { featureFlag } from "@/helpers"
|
||||||
|
@ -41,7 +46,7 @@ export const screenComponentErrors = derived(
|
||||||
[selectedScreen, tables, views, viewsV2, queries],
|
[selectedScreen, tables, views, viewsV2, queries],
|
||||||
([$selectedScreen, $tables, $views, $viewsV2, $queries]): Record<
|
([$selectedScreen, $tables, $views, $viewsV2, $queries]): Record<
|
||||||
string,
|
string,
|
||||||
string[]
|
UIComponentError[]
|
||||||
> => {
|
> => {
|
||||||
if (!featureFlag.isEnabled("CHECK_SCREEN_COMPONENT_SETTINGS_ERRORS")) {
|
if (!featureFlag.isEnabled("CHECK_SCREEN_COMPONENT_SETTINGS_ERRORS")) {
|
||||||
return {}
|
return {}
|
||||||
|
@ -66,7 +71,7 @@ function getInvalidDatasources(
|
||||||
screen: Screen,
|
screen: Screen,
|
||||||
datasources: Record<string, any>
|
datasources: Record<string, any>
|
||||||
) {
|
) {
|
||||||
const result: Record<string, string[]> = {}
|
const result: Record<string, UIComponentError[]> = {}
|
||||||
for (const { component, setting } of findComponentsBySettingsType(screen, [
|
for (const { component, setting } of findComponentsBySettingsType(screen, [
|
||||||
"table",
|
"table",
|
||||||
"dataSource",
|
"dataSource",
|
||||||
|
@ -87,7 +92,10 @@ function getInvalidDatasources(
|
||||||
if (!datasources[resourceId]) {
|
if (!datasources[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`,
|
{
|
||||||
|
key: setting.key,
|
||||||
|
message: `The ${friendlyTypeName} named "${label}" could not be found`,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +116,7 @@ function getAllComponentsInScreen(screen: Screen) {
|
||||||
function getMissingRequiredSettings(screen: Screen) {
|
function getMissingRequiredSettings(screen: Screen) {
|
||||||
const allComponents = getAllComponentsInScreen(screen)
|
const allComponents = getAllComponentsInScreen(screen)
|
||||||
|
|
||||||
const result: Record<string, string[]> = {}
|
const result: Record<string, UIComponentError[]> = {}
|
||||||
for (const component of allComponents) {
|
for (const component of allComponents) {
|
||||||
const definition = getManifestDefinition(component)
|
const definition = getManifestDefinition(component)
|
||||||
if (!("settings" in definition)) {
|
if (!("settings" in definition)) {
|
||||||
|
@ -152,10 +160,10 @@ function getMissingRequiredSettings(screen: Screen) {
|
||||||
)
|
)
|
||||||
|
|
||||||
if (missingRequiredSettings.length) {
|
if (missingRequiredSettings.length) {
|
||||||
result[component._id!] = missingRequiredSettings.map(
|
result[component._id!] = missingRequiredSettings.map((s: any) => ({
|
||||||
(s: any) =>
|
key: s.key,
|
||||||
`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`,
|
||||||
)
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,13 @@
|
||||||
import { Icon } from "@budibase/bbui"
|
import { Icon } from "@budibase/bbui"
|
||||||
import MissingRequiredSetting from "./MissingRequiredSetting.svelte"
|
import MissingRequiredSetting from "./MissingRequiredSetting.svelte"
|
||||||
import MissingRequiredAncestor from "./MissingRequiredAncestor.svelte"
|
import MissingRequiredAncestor from "./MissingRequiredAncestor.svelte"
|
||||||
|
import { UIComponentError } from "@budibase/types"
|
||||||
|
|
||||||
export let missingRequiredSettings:
|
export let missingRequiredSettings:
|
||||||
| { key: string; label: string }[]
|
| { key: string; label: string }[]
|
||||||
| undefined
|
| undefined
|
||||||
export let missingRequiredAncestors: string[] | undefined
|
export let missingRequiredAncestors: string[] | undefined
|
||||||
export let componentErrors: string[] | undefined
|
export let componentErrors: UIComponentError[] | undefined
|
||||||
|
|
||||||
const component = getContext("component")
|
const component = getContext("component")
|
||||||
const { styleable, builderStore } = getContext("sdk")
|
const { styleable, builderStore } = getContext("sdk")
|
||||||
|
@ -26,7 +27,20 @@
|
||||||
{#if requiredAncestor}
|
{#if requiredAncestor}
|
||||||
<MissingRequiredAncestor {requiredAncestor} />
|
<MissingRequiredAncestor {requiredAncestor} />
|
||||||
{:else if errorMessage}
|
{:else if errorMessage}
|
||||||
{@html errorMessage}
|
{@html errorMessage.message}
|
||||||
|
{#if errorMessage.key}
|
||||||
|
<span>-</span>
|
||||||
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
|
<span
|
||||||
|
class="spectrum-Link"
|
||||||
|
on:click={() => {
|
||||||
|
builderStore.actions.highlightSetting(errorMessage.key)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Show me
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
{:else if requiredSetting}
|
{:else if requiredSetting}
|
||||||
<MissingRequiredSetting {requiredSetting} />
|
<MissingRequiredSetting {requiredSetting} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -11,7 +11,11 @@ export interface SDK {
|
||||||
generateGoldenSample: any
|
generateGoldenSample: any
|
||||||
builderStore: Readable<{
|
builderStore: Readable<{
|
||||||
inBuilder: boolean
|
inBuilder: boolean
|
||||||
}>
|
}> & {
|
||||||
|
actions: {
|
||||||
|
highlightSetting: (key: string) => void
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Component = Readable<{
|
export type Component = Readable<{
|
||||||
|
|
|
@ -1,2 +1,7 @@
|
||||||
export * from "./sidepanel"
|
export * from "./sidepanel"
|
||||||
export * from "./codeEditor"
|
export * from "./codeEditor"
|
||||||
|
|
||||||
|
export interface UIComponentError {
|
||||||
|
key: string
|
||||||
|
message: string
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue