From b7a969280f442729493b0d21662a389ec118d575 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 19 Jul 2024 13:35:50 +0200 Subject: [PATCH] Display data --- .../FlowChart/FlowItem.svelte | 10 +++---- .../AutomationPanel/AutomationPanel.svelte | 6 ++++ .../builder/src/stores/builder/automations.js | 20 ++++++++++--- packages/builder/src/stores/builder/index.js | 2 ++ .../server/src/api/controllers/automation.ts | 8 ++--- .../server/src/sdk/app/automations/crud.ts | 29 ++++++++++++++----- packages/types/src/api/web/automation.ts | 14 +++++++++ 7 files changed, 67 insertions(+), 22 deletions(-) diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte index 503cc39187..99cf382585 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte @@ -3,6 +3,7 @@ automationStore, selectedAutomation, permissions, + selectedAutomationDisplayData, } from "stores/builder" import { Icon, @@ -16,7 +17,6 @@ AbsTooltip, InlineAlert, } from "@budibase/bbui" - import { AutomationTriggerStepId } from "@budibase/types" import AutomationBlockSetup from "../../SetupPanel/AutomationBlockSetup.svelte" import CreateWebhookModal from "components/automation/Shared/CreateWebhookModal.svelte" import ActionModal from "./ActionModal.svelte" @@ -51,8 +51,6 @@ $: isAppAction && setPermissions(role) $: isAppAction && getPermissions(automationId) - $: isRowAction = block?.stepId === AutomationTriggerStepId.ROW_ACTION - async function setPermissions(role) { if (!role || !automationId) { return @@ -187,10 +185,10 @@ {block} {webhookModal} /> - {#if isRowAction && isTrigger} + {#if isTrigger && $selectedAutomationDisplayData?.triggerInfo} {/if} {#if lastStep} diff --git a/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte b/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte index c3ef3157bd..718a0dbcb5 100644 --- a/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte @@ -17,6 +17,12 @@ automation.name.toLowerCase().includes(searchString.toLowerCase()) ) }) + .map(automation => ({ + ...automation, + name: + $automationStore.automationDisplayData[automation._id].displayName || + automation.name, + })) .sort((a, b) => { const lowerA = a.name.toLowerCase() const lowerB = b.name.toLowerCase() diff --git a/packages/builder/src/stores/builder/automations.js b/packages/builder/src/stores/builder/automations.js index b6af177442..c1cb963ac4 100644 --- a/packages/builder/src/stores/builder/automations.js +++ b/packages/builder/src/stores/builder/automations.js @@ -15,6 +15,7 @@ const initialAutomationState = { ACTION: [], }, selectedAutomationId: null, + automationDisplayData: {}, } // If this functions, remove the actions elements @@ -58,18 +59,19 @@ const automationActions = store => ({ return response }, fetch: async () => { - const responses = await Promise.all([ + const [automationResponse, definitions] = await Promise.all([ API.getAutomations({ enrich: true }), API.getAutomationDefinitions(), ]) store.update(state => { - state.automations = responses[0] + state.automations = automationResponse.automations state.automations.sort((a, b) => { return a.name < b.name ? -1 : 1 }) + state.automationDisplayData = automationResponse.builderData state.blockDefinitions = { - TRIGGER: responses[1].trigger, - ACTION: responses[1].action, + TRIGGER: definitions.trigger, + ACTION: definitions.action, } return state }) @@ -386,3 +388,13 @@ export const selectedAutomation = derived(automationStore, $automationStore => { x => x._id === $automationStore.selectedAutomationId ) }) + +export const selectedAutomationDisplayData = derived( + [automationStore, selectedAutomation], + ([$automationStore, $selectedAutomation]) => { + if (!$selectedAutomation._id) { + return null + } + return $automationStore.automationDisplayData[$selectedAutomation._id] + } +) diff --git a/packages/builder/src/stores/builder/index.js b/packages/builder/src/stores/builder/index.js index c47782c0f5..aa0062dd7d 100644 --- a/packages/builder/src/stores/builder/index.js +++ b/packages/builder/src/stores/builder/index.js @@ -11,6 +11,7 @@ import { automationStore, selectedAutomation, automationHistoryStore, + selectedAutomationDisplayData, } from "./automations.js" import { userStore, userSelectedResourceMap, isOnlyUser } from "./users.js" import { deploymentStore } from "./deployments.js" @@ -44,6 +45,7 @@ export { previewStore, automationStore, selectedAutomation, + selectedAutomationDisplayData, automationHistoryStore, sortedScreens, userStore, diff --git a/packages/server/src/api/controllers/automation.ts b/packages/server/src/api/controllers/automation.ts index b9b1793425..4495125e7f 100644 --- a/packages/server/src/api/controllers/automation.ts +++ b/packages/server/src/api/controllers/automation.ts @@ -11,6 +11,7 @@ import { AutomationResults, UserCtx, DeleteAutomationResponse, + FetchAutomationResponse, } from "@budibase/types" import { getActionDefinitions as actionDefs } from "../../automations/actions" import sdk from "../../sdk" @@ -73,14 +74,13 @@ export async function update(ctx: UserCtx) { builderSocket?.emitAutomationUpdate(ctx, automation) } -export async function fetch(ctx: UserCtx) { +export async function fetch(ctx: UserCtx) { const enrich = ctx.request.query["enrich"] === "true" const automations = await sdk.automations.fetch() + ctx.body = { automations } if (enrich) { - ctx.body = await sdk.automations.enrichDisplayData(automations) - } else { - ctx.body = automations + ctx.body.builderData = await sdk.automations.getBuilderData(automations) } } diff --git a/packages/server/src/sdk/app/automations/crud.ts b/packages/server/src/sdk/app/automations/crud.ts index 95b9d5895f..8836677039 100644 --- a/packages/server/src/sdk/app/automations/crud.ts +++ b/packages/server/src/sdk/app/automations/crud.ts @@ -1,5 +1,6 @@ import { Automation, + AutomationBuilderData, AutomationTriggerStepId, Webhook, WebhookActionType, @@ -288,14 +289,26 @@ function guardInvalidUpdatesAndThrow( } } -export async function enrichDisplayData(automations: Automation[]) { - const rowActionAutomations = automations.filter( - ({ definition }) => - definition.trigger.stepId === AutomationTriggerStepId.ROW_ACTION - ) +export async function getBuilderData( + automations: Automation[] +): Promise> { + const result: Record = {} + for (const automation of automations) { + const isRowAction = + automation.definition.trigger.stepId === + AutomationTriggerStepId.ROW_ACTION + if (!isRowAction) { + result[automation._id!] = { displayName: automation.name } + continue + } - for (const automation of rowActionAutomations) { - automation.name = `TODO: ${automation.name}` + result[automation._id!] = { + displayName: `TODO: ${automation.name}`, + triggerInfo: { + title: "Automation trigger", + description: "This trigger is tied to the row action TODO on your TODO", + }, + } } - return automations + return result } diff --git a/packages/types/src/api/web/automation.ts b/packages/types/src/api/web/automation.ts index c1f3d01b2f..58faf55a41 100644 --- a/packages/types/src/api/web/automation.ts +++ b/packages/types/src/api/web/automation.ts @@ -1,3 +1,17 @@ import { DocumentDestroyResponse } from "@budibase/nano" +import { Automation } from "../../documents" export interface DeleteAutomationResponse extends DocumentDestroyResponse {} + +export interface AutomationBuilderData { + displayName: string + triggerInfo?: { + title: string + description: string + } +} + +export interface FetchAutomationResponse { + automations: Automation[] + builderData?: Record // The key will be the automationId +}