Merge branch 'master' into revert-15323-revert-15215-chore/aws-v2-to-v3
This commit is contained in:
commit
4534c3f83a
|
@ -199,6 +199,12 @@ class InMemoryQueue implements Partial<Queue> {
|
||||||
return this as unknown as Queue
|
return this as unknown as Queue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
off(event: string, callback: (...args: any[]) => void): Queue {
|
||||||
|
// @ts-expect-error - this callback can be one of many types
|
||||||
|
this._emitter.off(event, callback)
|
||||||
|
return this as unknown as Queue
|
||||||
|
}
|
||||||
|
|
||||||
async count() {
|
async count() {
|
||||||
return this._messages.length
|
return this._messages.length
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import "@spectrum-css/actionbutton/dist/index-vars.css"
|
import "@spectrum-css/actionbutton/dist/index-vars.css"
|
||||||
import Tooltip from "../Tooltip/Tooltip.svelte"
|
import Tooltip from "../Tooltip/Tooltip.svelte"
|
||||||
import { fade } from "svelte/transition"
|
import { fade } from "svelte/transition"
|
||||||
import { hexToRGBA } from "../helpers"
|
import { hexToRGBA } from "../helpers"
|
||||||
|
|
||||||
export let quiet = false
|
export let quiet: boolean = false
|
||||||
export let selected = false
|
export let selected: boolean = false
|
||||||
export let disabled = false
|
export let disabled: boolean = false
|
||||||
export let icon = ""
|
export let icon: string = ""
|
||||||
export let size = "M"
|
export let size: "S" | "M" | "L" = "M"
|
||||||
export let active = false
|
export let active: boolean = false
|
||||||
export let fullWidth = false
|
export let fullWidth: boolean = false
|
||||||
export let noPadding = false
|
export let noPadding: boolean = false
|
||||||
export let tooltip = ""
|
export let tooltip: string = ""
|
||||||
export let accentColor = null
|
export let accentColor: string | null = null
|
||||||
|
|
||||||
let showTooltip = false
|
let showTooltip = false
|
||||||
|
|
||||||
$: accentStyle = getAccentStyle(accentColor)
|
$: accentStyle = getAccentStyle(accentColor)
|
||||||
|
|
||||||
const getAccentStyle = color => {
|
const getAccentStyle = (color: string | null) => {
|
||||||
if (!color) {
|
if (!color) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,15 +1,15 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import Icon from "../Icon/Icon.svelte"
|
import Icon from "../Icon/Icon.svelte"
|
||||||
import StatusLight from "../StatusLight/StatusLight.svelte"
|
import StatusLight from "../StatusLight/StatusLight.svelte"
|
||||||
|
|
||||||
export let icon = null
|
export let icon: string | undefined = undefined
|
||||||
export let iconColor = null
|
export let iconColor: string | undefined = undefined
|
||||||
export let title = null
|
export let title: string | undefined = undefined
|
||||||
export let subtitle = null
|
export let subtitle: string | undefined = undefined
|
||||||
export let url = null
|
export let url: string | undefined = undefined
|
||||||
export let hoverable = false
|
export let hoverable: boolean = false
|
||||||
export let showArrow = false
|
export let showArrow: boolean = false
|
||||||
export let selected = false
|
export let selected: boolean = false
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<a
|
<a
|
||||||
|
|
|
@ -1,20 +1,29 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { ActionButton, List, ListItem, Button } from "@budibase/bbui"
|
import { Button } from "@budibase/bbui"
|
||||||
import DetailPopover from "@/components/common/DetailPopover.svelte"
|
import ScreensPopover from "@/components/common/ScreensPopover.svelte"
|
||||||
import { screenStore, appStore } from "@/stores/builder"
|
import { screenStore } from "@/stores/builder"
|
||||||
import { getContext, createEventDispatcher } from "svelte"
|
import { getContext, createEventDispatcher } from "svelte"
|
||||||
|
import type { Screen, ScreenUsage } from "@budibase/types"
|
||||||
const { datasource } = getContext("grid")
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
let popover
|
const { datasource }: { datasource: any } = getContext("grid")
|
||||||
|
|
||||||
|
let popover: any
|
||||||
|
|
||||||
$: ds = $datasource
|
$: ds = $datasource
|
||||||
$: resourceId = ds?.type === "table" ? ds.tableId : ds?.id
|
$: resourceId = ds?.type === "table" ? ds.tableId : ds?.id
|
||||||
$: connectedScreens = findConnectedScreens($screenStore.screens, resourceId)
|
$: connectedScreens = findConnectedScreens($screenStore.screens, resourceId)
|
||||||
$: screenCount = connectedScreens.length
|
$: screenUsage = connectedScreens.map(
|
||||||
|
(screen: Screen): ScreenUsage => ({
|
||||||
|
url: screen.routing?.route,
|
||||||
|
_id: screen._id!,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
const findConnectedScreens = (screens, resourceId) => {
|
const findConnectedScreens = (
|
||||||
|
screens: Screen[],
|
||||||
|
resourceId: string
|
||||||
|
): Screen[] => {
|
||||||
return screens.filter(screen => {
|
return screens.filter(screen => {
|
||||||
return JSON.stringify(screen).includes(`"${resourceId}"`)
|
return JSON.stringify(screen).includes(`"${resourceId}"`)
|
||||||
})
|
})
|
||||||
|
@ -26,34 +35,16 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<DetailPopover title="Screens" bind:this={popover}>
|
<ScreensPopover
|
||||||
<svelte:fragment slot="anchor" let:open>
|
bind:this={popover}
|
||||||
<ActionButton
|
screens={screenUsage}
|
||||||
icon="WebPage"
|
icon="WebPage"
|
||||||
selected={open || screenCount}
|
|
||||||
quiet
|
|
||||||
accentColor="#364800"
|
accentColor="#364800"
|
||||||
>
|
showCount
|
||||||
Screens{screenCount ? `: ${screenCount}` : ""}
|
>
|
||||||
</ActionButton>
|
<svelte:fragment slot="footer">
|
||||||
</svelte:fragment>
|
|
||||||
{#if !connectedScreens.length}
|
|
||||||
There aren't any screens connected to this data.
|
|
||||||
{:else}
|
|
||||||
The following screens are connected to this data.
|
|
||||||
<List>
|
|
||||||
{#each connectedScreens as screen}
|
|
||||||
<ListItem
|
|
||||||
title={screen.routing.route}
|
|
||||||
url={`/builder/app/${$appStore.appId}/design/${screen._id}`}
|
|
||||||
showArrow
|
|
||||||
/>
|
|
||||||
{/each}
|
|
||||||
</List>
|
|
||||||
{/if}
|
|
||||||
<div>
|
|
||||||
<Button secondary icon="WebPage" on:click={generateScreen}>
|
<Button secondary icon="WebPage" on:click={generateScreen}>
|
||||||
Generate app screen
|
Generate app screen
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</svelte:fragment>
|
||||||
</DetailPopover>
|
</ScreensPopover>
|
||||||
|
|
|
@ -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 |
|
@ -0,0 +1,58 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import {
|
||||||
|
List,
|
||||||
|
ListItem,
|
||||||
|
ActionButton,
|
||||||
|
PopoverAlignment,
|
||||||
|
} from "@budibase/bbui"
|
||||||
|
import DetailPopover from "@/components/common/DetailPopover.svelte"
|
||||||
|
import { appStore } from "@/stores/builder"
|
||||||
|
import type { ScreenUsage } from "@budibase/types"
|
||||||
|
|
||||||
|
export let screens: ScreenUsage[] = []
|
||||||
|
export let icon = "DeviceDesktop"
|
||||||
|
export let accentColor: string | null | undefined = null
|
||||||
|
export let showCount = false
|
||||||
|
export let align = PopoverAlignment.Left
|
||||||
|
|
||||||
|
let popover: any
|
||||||
|
|
||||||
|
export function show() {
|
||||||
|
popover?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hide() {
|
||||||
|
popover?.hide()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DetailPopover title="Screens" bind:this={popover} {align}>
|
||||||
|
<svelte:fragment slot="anchor" let:open>
|
||||||
|
<ActionButton
|
||||||
|
{icon}
|
||||||
|
quiet
|
||||||
|
selected={open || !!(showCount && screens.length)}
|
||||||
|
{accentColor}
|
||||||
|
on:click={show}
|
||||||
|
>
|
||||||
|
Screens{showCount && screens.length ? `: ${screens.length}` : ""}
|
||||||
|
</ActionButton>
|
||||||
|
</svelte:fragment>
|
||||||
|
|
||||||
|
{#if !screens.length}
|
||||||
|
There aren't any screens connected to this data.
|
||||||
|
{:else}
|
||||||
|
The following screens are connected to this data.
|
||||||
|
<List>
|
||||||
|
{#each screens as screen}
|
||||||
|
<ListItem
|
||||||
|
title={screen.url}
|
||||||
|
url={`/builder/app/${$appStore.appId}/design/${screen._id}`}
|
||||||
|
showArrow
|
||||||
|
/>
|
||||||
|
{/each}
|
||||||
|
</List>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<slot name="footer" />
|
||||||
|
</DetailPopover>
|
|
@ -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}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import { onMount } from "svelte"
|
||||||
|
|
||||||
|
import { screenStore } from "@/stores/builder"
|
||||||
|
import ScreensPopover from "@/components/common/ScreensPopover.svelte"
|
||||||
|
import type { ScreenUsage } from "@budibase/types"
|
||||||
|
|
||||||
|
export let sourceId: string
|
||||||
|
|
||||||
|
let screens: ScreenUsage[] = []
|
||||||
|
let popover: any
|
||||||
|
|
||||||
|
export function show() {
|
||||||
|
popover?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hide() {
|
||||||
|
popover?.hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
let response = await screenStore.usageInScreens(sourceId)
|
||||||
|
screens = response?.screens
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<ScreensPopover
|
||||||
|
bind:this={popover}
|
||||||
|
{screens}
|
||||||
|
icon="WebPage"
|
||||||
|
accentColor="#364800"
|
||||||
|
showCount
|
||||||
|
/>
|
|
@ -23,6 +23,7 @@
|
||||||
import ExtraQueryConfig from "./ExtraQueryConfig.svelte"
|
import ExtraQueryConfig from "./ExtraQueryConfig.svelte"
|
||||||
import QueryViewerSavePromptModal from "./QueryViewerSavePromptModal.svelte"
|
import QueryViewerSavePromptModal from "./QueryViewerSavePromptModal.svelte"
|
||||||
import { Utils } from "@budibase/frontend-core"
|
import { Utils } from "@budibase/frontend-core"
|
||||||
|
import ConnectedQueryScreens from "./ConnectedQueryScreens.svelte"
|
||||||
|
|
||||||
export let query
|
export let query
|
||||||
let queryHash
|
let queryHash
|
||||||
|
@ -170,6 +171,7 @@
|
||||||
</Body>
|
</Body>
|
||||||
</div>
|
</div>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
<ConnectedQueryScreens sourceId={query._id} />
|
||||||
<Button disabled={loading} on:click={runQuery} overBackground>
|
<Button disabled={loading} on:click={runQuery} overBackground>
|
||||||
<Icon size="S" name="Play" />
|
<Icon size="S" name="Play" />
|
||||||
Run query</Button
|
Run query</Button
|
||||||
|
@ -384,6 +386,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.controls {
|
.controls {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
runtimeToReadableMap,
|
runtimeToReadableMap,
|
||||||
toBindingsArray,
|
toBindingsArray,
|
||||||
} from "@/dataBinding"
|
} from "@/dataBinding"
|
||||||
|
import ConnectedQueryScreens from "./ConnectedQueryScreens.svelte"
|
||||||
|
|
||||||
export let queryId
|
export let queryId
|
||||||
|
|
||||||
|
@ -502,11 +503,14 @@
|
||||||
on:change={() => (query.flags.urlName = false)}
|
on:change={() => (query.flags.urlName = false)}
|
||||||
on:save={saveQuery}
|
on:save={saveQuery}
|
||||||
/>
|
/>
|
||||||
|
<div class="controls">
|
||||||
|
<ConnectedQueryScreens sourceId={query._id} />
|
||||||
<div class="access">
|
<div class="access">
|
||||||
<Label>Access</Label>
|
<Label>Access</Label>
|
||||||
<AccessLevelSelect {query} {saveId} />
|
<AccessLevelSelect {query} {saveId} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div class="url-block">
|
<div class="url-block">
|
||||||
<div class="verb">
|
<div class="verb">
|
||||||
<Select
|
<Select
|
||||||
|
@ -825,6 +829,12 @@
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.controls {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--spacing-m);
|
||||||
|
}
|
||||||
|
|
||||||
.access {
|
.access {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: var(--spacing-m);
|
gap: var(--spacing-m);
|
||||||
|
|
|
@ -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,26 +76,38 @@ 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,
|
const datasourceTypes = ["table", "dataSource"]
|
||||||
["table", "dataSource"],
|
|
||||||
definitions
|
const possibleSettings = definitions[component._component]?.settings?.filter(
|
||||||
)) {
|
s => datasourceTypes.includes(s.type)
|
||||||
|
)
|
||||||
|
if (possibleSettings) {
|
||||||
|
for (const setting of possibleSettings) {
|
||||||
const componentSettings = component[setting.key]
|
const componentSettings = component[setting.key]
|
||||||
if (!componentSettings) {
|
if (!componentSettings) {
|
||||||
continue
|
continue
|
||||||
|
@ -107,52 +126,72 @@ function getInvalidDatasources(
|
||||||
const componentDatasources = {
|
const componentDatasources = {
|
||||||
...reduceBy("rowId", bindings.extractRelationships(componentBindings)),
|
...reduceBy("rowId", bindings.extractRelationships(componentBindings)),
|
||||||
...reduceBy("value", bindings.extractFields(componentBindings)),
|
...reduceBy("value", bindings.extractFields(componentBindings)),
|
||||||
...reduceBy("value", bindings.extractJSONArrayFields(componentBindings)),
|
...reduceBy(
|
||||||
|
"value",
|
||||||
|
bindings.extractJSONArrayFields(componentBindings)
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
const resourceId = componentSettings[validationKey]
|
const resourceId = componentSettings[validationKey]
|
||||||
if (!{ ...datasources, ...componentDatasources }[resourceId]) {
|
if (!{ ...datasources, ...componentDatasources }[resourceId]) {
|
||||||
const friendlyTypeName = friendlyNameByType[type] ?? type
|
const friendlyTypeName = friendlyNameByType[type] ?? type
|
||||||
result[component._id!] = [
|
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[]> = {}
|
|
||||||
for (const component of allComponents) {
|
|
||||||
const definition = definitions[component._component]
|
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
|
||||||
|
@ -173,12 +212,16 @@ function getMissingRequiredSettings(
|
||||||
})
|
})
|
||||||
|
|
||||||
if (missingRequiredSettings?.length) {
|
if (missingRequiredSettings?.length) {
|
||||||
result[component._id!] = missingRequiredSettings.map((s: any) => ({
|
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,22 +229,17 @@ 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[] {
|
||||||
|
|
||||||
function checkMissingAncestors(component: Component, ancestors: string[]) {
|
|
||||||
for (const child of component._children || []) {
|
|
||||||
checkMissingAncestors(child, [...ancestors, component._component])
|
|
||||||
}
|
|
||||||
|
|
||||||
const definition = definitions[component._component]
|
const definition = definitions[component._component]
|
||||||
|
|
||||||
if (!definition?.requiredAncestors?.length) {
|
if (!definition?.requiredAncestors?.length) {
|
||||||
return
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const result: UIComponentError[] = []
|
||||||
const missingAncestors = definition.requiredAncestors.filter(
|
const missingAncestors = definition.requiredAncestors.filter(
|
||||||
ancestor => !ancestors.includes(`${BudibasePrefix}${ancestor}`)
|
ancestor => !ancestors.includes(`${BudibasePrefix}${ancestor}`)
|
||||||
)
|
)
|
||||||
|
@ -211,9 +249,11 @@ function getMissingAncestors(
|
||||||
return name.endsWith("s") ? `${name}'` : `${name}s`
|
return name.endsWith("s") ? `${name}'` : `${name}s`
|
||||||
}
|
}
|
||||||
|
|
||||||
result[component._id!] = missingAncestors.map(ancestor => {
|
result.push(
|
||||||
|
...missingAncestors.map<UIComponentError>(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
|
||||||
|
}, {})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -182,7 +182,7 @@ if (descriptions.length) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
await config.api.application.publish(config.getAppId())
|
await config.api.application.publish()
|
||||||
const prodQuery = await config.api.query.getProd(query._id!)
|
const prodQuery = await config.api.query.getProd(query._id!)
|
||||||
|
|
||||||
expect(prodQuery._id).toEqual(query._id)
|
expect(prodQuery._id).toEqual(query._id)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
||||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
import { getQueue } from "../.."
|
import { captureAutomationRuns } from "../utilities"
|
||||||
import { Job } from "bull"
|
|
||||||
|
|
||||||
describe("cron trigger", () => {
|
describe("cron trigger", () => {
|
||||||
const config = new TestConfiguration()
|
const config = new TestConfiguration()
|
||||||
|
@ -15,15 +14,6 @@ describe("cron trigger", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should queue a Bull cron job", async () => {
|
it("should queue a Bull cron job", async () => {
|
||||||
const queue = getQueue()
|
|
||||||
expect(await queue.getCompletedCount()).toEqual(0)
|
|
||||||
|
|
||||||
const jobPromise = new Promise<Job>(resolve => {
|
|
||||||
queue.on("completed", async job => {
|
|
||||||
resolve(job)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
await createAutomationBuilder(config)
|
await createAutomationBuilder(config)
|
||||||
.onCron({ cron: "* * * * *" })
|
.onCron({ cron: "* * * * *" })
|
||||||
.serverLog({
|
.serverLog({
|
||||||
|
@ -31,12 +21,12 @@ describe("cron trigger", () => {
|
||||||
})
|
})
|
||||||
.save()
|
.save()
|
||||||
|
|
||||||
await config.api.application.publish(config.getAppId())
|
const jobs = await captureAutomationRuns(() =>
|
||||||
|
config.api.application.publish()
|
||||||
|
)
|
||||||
|
expect(jobs).toHaveLength(1)
|
||||||
|
|
||||||
expect(await queue.getCompletedCount()).toEqual(1)
|
const repeat = jobs[0].opts?.repeat
|
||||||
|
|
||||||
const job = await jobPromise
|
|
||||||
const repeat = job.opts?.repeat
|
|
||||||
if (!repeat || !("cron" in repeat)) {
|
if (!repeat || !("cron" in repeat)) {
|
||||||
throw new Error("Expected cron repeat")
|
throw new Error("Expected cron repeat")
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
||||||
|
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
|
import { Table } from "@budibase/types"
|
||||||
|
import { basicTable } from "../../../tests/utilities/structures"
|
||||||
|
import { captureAutomationRuns } from "../utilities"
|
||||||
|
|
||||||
|
describe("row saved trigger", () => {
|
||||||
|
const config = new TestConfiguration()
|
||||||
|
let table: Table
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await config.init()
|
||||||
|
table = await config.api.table.save(basicTable())
|
||||||
|
await createAutomationBuilder(config)
|
||||||
|
.onRowSaved({ tableId: table._id! })
|
||||||
|
.serverLog({ text: "Row created!" })
|
||||||
|
.save()
|
||||||
|
|
||||||
|
await config.api.application.publish()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
config.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should queue a Bull job when a row is created", async () => {
|
||||||
|
const jobs = await captureAutomationRuns(() =>
|
||||||
|
config.withProdApp(() => config.api.row.save(table._id!, { name: "foo" }))
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(jobs).toHaveLength(1)
|
||||||
|
expect(jobs[0].data.event).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
tableId: table._id!,
|
||||||
|
row: expect.objectContaining({ name: "foo" }),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should not fire for rows created in other tables", async () => {
|
||||||
|
const otherTable = await config.api.table.save(basicTable())
|
||||||
|
await config.api.application.publish()
|
||||||
|
|
||||||
|
const jobs = await captureAutomationRuns(() =>
|
||||||
|
config.withProdApp(() =>
|
||||||
|
config.api.row.save(otherTable._id!, { name: "foo" })
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(jobs).toBeEmpty()
|
||||||
|
})
|
||||||
|
})
|
|
@ -3,8 +3,15 @@ import { context } from "@budibase/backend-core"
|
||||||
import { BUILTIN_ACTION_DEFINITIONS, getAction } from "../../actions"
|
import { BUILTIN_ACTION_DEFINITIONS, getAction } from "../../actions"
|
||||||
import emitter from "../../../events/index"
|
import emitter from "../../../events/index"
|
||||||
import env from "../../../environment"
|
import env from "../../../environment"
|
||||||
import { AutomationActionStepId, Datasource } from "@budibase/types"
|
import {
|
||||||
|
AutomationActionStepId,
|
||||||
|
AutomationData,
|
||||||
|
Datasource,
|
||||||
|
} from "@budibase/types"
|
||||||
import { Knex } from "knex"
|
import { Knex } from "knex"
|
||||||
|
import { getQueue } from "../.."
|
||||||
|
import { Job } from "bull"
|
||||||
|
import { helpers } from "@budibase/shared-core"
|
||||||
|
|
||||||
let config: TestConfiguration
|
let config: TestConfiguration
|
||||||
|
|
||||||
|
@ -63,6 +70,44 @@ export async function runStep(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Capture all automation runs that occur during the execution of a function.
|
||||||
|
* This function will wait for all messages to be processed before returning.
|
||||||
|
*/
|
||||||
|
export async function captureAutomationRuns(
|
||||||
|
f: () => Promise<unknown>
|
||||||
|
): Promise<Job<AutomationData>[]> {
|
||||||
|
const runs: Job<AutomationData>[] = []
|
||||||
|
const queue = getQueue()
|
||||||
|
let messagesReceived = 0
|
||||||
|
|
||||||
|
const completedListener = async (job: Job<AutomationData>) => {
|
||||||
|
runs.push(job)
|
||||||
|
messagesReceived--
|
||||||
|
}
|
||||||
|
const messageListener = async () => {
|
||||||
|
messagesReceived++
|
||||||
|
}
|
||||||
|
queue.on("message", messageListener)
|
||||||
|
queue.on("completed", completedListener)
|
||||||
|
try {
|
||||||
|
await f()
|
||||||
|
// Queue messages tend to be send asynchronously in API handlers, so there's
|
||||||
|
// no guarantee that awaiting this function will have queued anything yet.
|
||||||
|
// We wait here to make sure we're queued _after_ any existing async work.
|
||||||
|
await helpers.wait(100)
|
||||||
|
} finally {
|
||||||
|
// eslint-disable-next-line no-unmodified-loop-condition
|
||||||
|
while (messagesReceived > 0) {
|
||||||
|
await helpers.wait(50)
|
||||||
|
}
|
||||||
|
queue.off("completed", completedListener)
|
||||||
|
queue.off("message", messageListener)
|
||||||
|
}
|
||||||
|
|
||||||
|
return runs
|
||||||
|
}
|
||||||
|
|
||||||
export async function saveTestQuery(
|
export async function saveTestQuery(
|
||||||
config: TestConfiguration,
|
config: TestConfiguration,
|
||||||
client: Knex,
|
client: Knex,
|
||||||
|
|
|
@ -34,9 +34,12 @@ export class ApplicationAPI extends TestAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
publish = async (
|
publish = async (
|
||||||
appId: string,
|
appId?: string,
|
||||||
expectations?: Expectations
|
expectations?: Expectations
|
||||||
): Promise<PublishResponse> => {
|
): Promise<PublishResponse> => {
|
||||||
|
if (!appId) {
|
||||||
|
appId = this.config.getAppId()
|
||||||
|
}
|
||||||
return await this._post<PublishResponse>(
|
return await this._post<PublishResponse>(
|
||||||
`/api/applications/${appId}/publish`,
|
`/api/applications/${appId}/publish`,
|
||||||
{
|
{
|
||||||
|
|
|
@ -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