Display data

This commit is contained in:
Adria Navarro 2024-07-19 13:35:50 +02:00
parent 6221b9320e
commit b7a969280f
7 changed files with 67 additions and 22 deletions

View File

@ -3,6 +3,7 @@
automationStore, automationStore,
selectedAutomation, selectedAutomation,
permissions, permissions,
selectedAutomationDisplayData,
} from "stores/builder" } from "stores/builder"
import { import {
Icon, Icon,
@ -16,7 +17,6 @@
AbsTooltip, AbsTooltip,
InlineAlert, InlineAlert,
} from "@budibase/bbui" } from "@budibase/bbui"
import { AutomationTriggerStepId } from "@budibase/types"
import AutomationBlockSetup from "../../SetupPanel/AutomationBlockSetup.svelte" import AutomationBlockSetup from "../../SetupPanel/AutomationBlockSetup.svelte"
import CreateWebhookModal from "components/automation/Shared/CreateWebhookModal.svelte" import CreateWebhookModal from "components/automation/Shared/CreateWebhookModal.svelte"
import ActionModal from "./ActionModal.svelte" import ActionModal from "./ActionModal.svelte"
@ -51,8 +51,6 @@
$: isAppAction && setPermissions(role) $: isAppAction && setPermissions(role)
$: isAppAction && getPermissions(automationId) $: isAppAction && getPermissions(automationId)
$: isRowAction = block?.stepId === AutomationTriggerStepId.ROW_ACTION
async function setPermissions(role) { async function setPermissions(role) {
if (!role || !automationId) { if (!role || !automationId) {
return return
@ -187,10 +185,10 @@
{block} {block}
{webhookModal} {webhookModal}
/> />
{#if isRowAction && isTrigger} {#if isTrigger && $selectedAutomationDisplayData?.triggerInfo}
<InlineAlert <InlineAlert
header="Automation trigger" header={$selectedAutomationDisplayData.triggerInfo.title}
message="This trigger is tied to the row action TODO on your TODO" message={$selectedAutomationDisplayData.triggerInfo.description}
/> />
{/if} {/if}
{#if lastStep} {#if lastStep}

View File

@ -17,6 +17,12 @@
automation.name.toLowerCase().includes(searchString.toLowerCase()) automation.name.toLowerCase().includes(searchString.toLowerCase())
) )
}) })
.map(automation => ({
...automation,
name:
$automationStore.automationDisplayData[automation._id].displayName ||
automation.name,
}))
.sort((a, b) => { .sort((a, b) => {
const lowerA = a.name.toLowerCase() const lowerA = a.name.toLowerCase()
const lowerB = b.name.toLowerCase() const lowerB = b.name.toLowerCase()

View File

@ -15,6 +15,7 @@ const initialAutomationState = {
ACTION: [], ACTION: [],
}, },
selectedAutomationId: null, selectedAutomationId: null,
automationDisplayData: {},
} }
// If this functions, remove the actions elements // If this functions, remove the actions elements
@ -58,18 +59,19 @@ const automationActions = store => ({
return response return response
}, },
fetch: async () => { fetch: async () => {
const responses = await Promise.all([ const [automationResponse, definitions] = await Promise.all([
API.getAutomations({ enrich: true }), API.getAutomations({ enrich: true }),
API.getAutomationDefinitions(), API.getAutomationDefinitions(),
]) ])
store.update(state => { store.update(state => {
state.automations = responses[0] state.automations = automationResponse.automations
state.automations.sort((a, b) => { state.automations.sort((a, b) => {
return a.name < b.name ? -1 : 1 return a.name < b.name ? -1 : 1
}) })
state.automationDisplayData = automationResponse.builderData
state.blockDefinitions = { state.blockDefinitions = {
TRIGGER: responses[1].trigger, TRIGGER: definitions.trigger,
ACTION: responses[1].action, ACTION: definitions.action,
} }
return state return state
}) })
@ -386,3 +388,13 @@ export const selectedAutomation = derived(automationStore, $automationStore => {
x => x._id === $automationStore.selectedAutomationId x => x._id === $automationStore.selectedAutomationId
) )
}) })
export const selectedAutomationDisplayData = derived(
[automationStore, selectedAutomation],
([$automationStore, $selectedAutomation]) => {
if (!$selectedAutomation._id) {
return null
}
return $automationStore.automationDisplayData[$selectedAutomation._id]
}
)

View File

@ -11,6 +11,7 @@ import {
automationStore, automationStore,
selectedAutomation, selectedAutomation,
automationHistoryStore, automationHistoryStore,
selectedAutomationDisplayData,
} from "./automations.js" } from "./automations.js"
import { userStore, userSelectedResourceMap, isOnlyUser } from "./users.js" import { userStore, userSelectedResourceMap, isOnlyUser } from "./users.js"
import { deploymentStore } from "./deployments.js" import { deploymentStore } from "./deployments.js"
@ -44,6 +45,7 @@ export {
previewStore, previewStore,
automationStore, automationStore,
selectedAutomation, selectedAutomation,
selectedAutomationDisplayData,
automationHistoryStore, automationHistoryStore,
sortedScreens, sortedScreens,
userStore, userStore,

View File

@ -11,6 +11,7 @@ import {
AutomationResults, AutomationResults,
UserCtx, UserCtx,
DeleteAutomationResponse, DeleteAutomationResponse,
FetchAutomationResponse,
} from "@budibase/types" } from "@budibase/types"
import { getActionDefinitions as actionDefs } from "../../automations/actions" import { getActionDefinitions as actionDefs } from "../../automations/actions"
import sdk from "../../sdk" import sdk from "../../sdk"
@ -73,14 +74,13 @@ export async function update(ctx: UserCtx) {
builderSocket?.emitAutomationUpdate(ctx, automation) builderSocket?.emitAutomationUpdate(ctx, automation)
} }
export async function fetch(ctx: UserCtx) { export async function fetch(ctx: UserCtx<void, FetchAutomationResponse>) {
const enrich = ctx.request.query["enrich"] === "true" const enrich = ctx.request.query["enrich"] === "true"
const automations = await sdk.automations.fetch() const automations = await sdk.automations.fetch()
ctx.body = { automations }
if (enrich) { if (enrich) {
ctx.body = await sdk.automations.enrichDisplayData(automations) ctx.body.builderData = await sdk.automations.getBuilderData(automations)
} else {
ctx.body = automations
} }
} }

View File

@ -1,5 +1,6 @@
import { import {
Automation, Automation,
AutomationBuilderData,
AutomationTriggerStepId, AutomationTriggerStepId,
Webhook, Webhook,
WebhookActionType, WebhookActionType,
@ -288,14 +289,26 @@ function guardInvalidUpdatesAndThrow(
} }
} }
export async function enrichDisplayData(automations: Automation[]) { export async function getBuilderData(
const rowActionAutomations = automations.filter( automations: Automation[]
({ definition }) => ): Promise<Record<string, AutomationBuilderData>> {
definition.trigger.stepId === AutomationTriggerStepId.ROW_ACTION const result: Record<string, AutomationBuilderData> = {}
) 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) { result[automation._id!] = {
automation.name = `TODO: ${automation.name}` 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
} }

View File

@ -1,3 +1,17 @@
import { DocumentDestroyResponse } from "@budibase/nano" import { DocumentDestroyResponse } from "@budibase/nano"
import { Automation } from "../../documents"
export interface DeleteAutomationResponse extends DocumentDestroyResponse {} export interface DeleteAutomationResponse extends DocumentDestroyResponse {}
export interface AutomationBuilderData {
displayName: string
triggerInfo?: {
title: string
description: string
}
}
export interface FetchAutomationResponse {
automations: Automation[]
builderData?: Record<string, AutomationBuilderData> // The key will be the automationId
}