Merge pull request #14854 from Budibase/chore/simplify-automation-data

Trigger info data in the frontend
This commit is contained in:
Adria Navarro 2024-10-23 17:15:21 +02:00 committed by GitHub
commit 8466f8883c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 18 additions and 112 deletions

View File

@ -3,7 +3,7 @@
automationStore, automationStore,
selectedAutomation, selectedAutomation,
permissions, permissions,
selectedAutomationDisplayData, tables,
} from "stores/builder" } from "stores/builder"
import { import {
Icon, Icon,
@ -17,6 +17,7 @@
AbsTooltip, AbsTooltip,
InlineAlert, InlineAlert,
} from "@budibase/bbui" } from "@budibase/bbui"
import { sdk } from "@budibase/shared-core"
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,7 +52,12 @@
$: isAppAction && setPermissions(role) $: isAppAction && setPermissions(role)
$: isAppAction && getPermissions(automationId) $: isAppAction && getPermissions(automationId)
$: triggerInfo = $selectedAutomationDisplayData?.triggerInfo $: triggerInfo = sdk.automations.isRowAction($selectedAutomation) && {
title: "Automation trigger",
tableName: $tables.list.find(
x => x._id === $selectedAutomation.definition.trigger.inputs?.tableId
)?.name,
}
async function setPermissions(role) { async function setPermissions(role) {
if (!role || !automationId) { if (!role || !automationId) {
@ -187,10 +193,10 @@
{block} {block}
{webhookModal} {webhookModal}
/> />
{#if isTrigger && triggerInfo} {#if triggerInfo}
<InlineAlert <InlineAlert
header={triggerInfo.type} header={triggerInfo.title}
message={`This trigger is tied to the "${triggerInfo.rowAction.name}" row action in your ${triggerInfo.table.name} table`} message={`This trigger is tied to your "${triggerInfo.tableName}" table`}
/> />
{/if} {/if}
{#if lastStep} {#if lastStep}

View File

@ -112,7 +112,7 @@
iconColor={automation.disabled iconColor={automation.disabled
? "var(--spectrum-global-color-gray-600)" ? "var(--spectrum-global-color-gray-600)"
: "var(--spectrum-global-color-gray-900)"} : "var(--spectrum-global-color-gray-900)"}
text={automation.displayName} text={automation.name}
selected={automation._id === $selectedAutomation?._id} selected={automation._id === $selectedAutomation?._id}
hovering={automation._id === $contextMenuStore.id} hovering={automation._id === $contextMenuStore.id}
on:click={() => automationStore.actions.select(automation._id)} on:click={() => automationStore.actions.select(automation._id)}

View File

@ -25,15 +25,9 @@
automation.name.toLowerCase().includes(searchString.toLowerCase()) automation.name.toLowerCase().includes(searchString.toLowerCase())
) )
}) })
.map(automation => ({
...automation,
displayName:
$automationStore.automationDisplayData[automation._id]?.displayName ||
automation.name,
}))
.sort((a, b) => { .sort((a, b) => {
const lowerA = a.displayName.toLowerCase() const lowerA = a.name.toLowerCase()
const lowerB = b.displayName.toLowerCase() const lowerB = b.name.toLowerCase()
return lowerA > lowerB ? 1 : -1 return lowerA > lowerB ? 1 : -1
}) })

View File

@ -23,7 +23,6 @@ const initialAutomationState = {
ACTION: {}, ACTION: {},
}, },
selectedAutomationId: null, selectedAutomationId: null,
automationDisplayData: {},
} }
// If this functions, remove the actions elements // If this functions, remove the actions elements
@ -83,7 +82,7 @@ const automationActions = store => ({
}, },
fetch: async () => { fetch: async () => {
const [automationResponse, definitions] = await Promise.all([ const [automationResponse, definitions] = await Promise.all([
API.getAutomations({ enrich: true }), API.getAutomations(),
API.getAutomationDefinitions(), API.getAutomationDefinitions(),
]) ])
store.update(state => { store.update(state => {
@ -91,7 +90,6 @@ const automationActions = store => ({
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 = getFinalDefinitions( state.blockDefinitions = getFinalDefinitions(
definitions.trigger, definitions.trigger,
definitions.action definitions.action
@ -153,8 +151,6 @@ const automationActions = store => ({
state.selectedAutomationId = state.automations[0]?._id || null state.selectedAutomationId = state.automations[0]?._id || null
} }
// Clear out automationDisplayData for the automation
delete state.automationDisplayData[automation._id]
return state return state
}) })
}, },
@ -432,13 +428,3 @@ 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,7 +11,6 @@ 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"
@ -46,7 +45,6 @@ export {
previewStore, previewStore,
automationStore, automationStore,
selectedAutomation, selectedAutomation,
selectedAutomationDisplayData,
automationHistoryStore, automationHistoryStore,
sortedScreens, sortedScreens,
userStore, userStore,

View File

@ -26,14 +26,9 @@ export const buildAutomationEndpoints = API => ({
/** /**
* Gets a list of all automations. * Gets a list of all automations.
*/ */
getAutomations: async ({ enrich }) => { getAutomations: async () => {
const params = new URLSearchParams()
if (enrich) {
params.set("enrich", true)
}
return await API.get({ return await API.get({
url: `/api/automations?${params.toString()}`, url: "/api/automations",
}) })
}, },

View File

@ -76,16 +76,8 @@ export async function update(ctx: UserCtx) {
} }
export async function fetch(ctx: UserCtx<void, FetchAutomationResponse>) { export async function fetch(ctx: UserCtx<void, FetchAutomationResponse>) {
const query: { enrich?: string } = ctx.request.query || {}
const enrich = query.enrich === "true"
const automations = await sdk.automations.fetch() const automations = await sdk.automations.fetch()
ctx.body = { automations } ctx.body = { automations }
if (enrich) {
ctx.body.builderData = await sdk.automations.utils.getBuilderData(
automations
)
}
} }
export async function find(ctx: UserCtx) { export async function find(ctx: UserCtx) {

View File

@ -1,56 +1,7 @@
import { import { Automation, AutomationActionStepId } from "@budibase/types"
Automation,
AutomationActionStepId,
AutomationBuilderData,
} from "@budibase/types"
import { sdk as coreSdk } from "@budibase/shared-core"
import sdk from "../../../sdk"
export function checkForCollectStep(automation: Automation) { export function checkForCollectStep(automation: Automation) {
return automation.definition.steps.some( return automation.definition.steps.some(
(step: any) => step.stepId === AutomationActionStepId.COLLECT (step: any) => step.stepId === AutomationActionStepId.COLLECT
) )
} }
export async function getBuilderData(
automations: Automation[]
): Promise<Record<string, AutomationBuilderData>> {
const tableNameCache: Record<string, string> = {}
async function getTableName(tableId: string) {
if (!tableNameCache[tableId]) {
const table = await sdk.tables.getTable(tableId)
tableNameCache[tableId] = table.name
}
return tableNameCache[tableId]
}
const result: Record<string, AutomationBuilderData> = {}
for (const automation of automations) {
const isRowAction = coreSdk.automations.isRowAction(automation)
if (!isRowAction) {
result[automation._id!] = { displayName: automation.name }
continue
}
const { tableId, rowActionId } = automation.definition.trigger.inputs
if (!tableId || !rowActionId) {
continue
}
const tableName = await getTableName(tableId)
const rowActionName = automation.name
result[automation._id!] = {
displayName: rowActionName,
triggerInfo: {
type: "Automation trigger",
table: { id: tableId, name: tableName },
rowAction: {
id: rowActionId,
name: rowActionName,
},
},
}
}
return result
}

View File

@ -3,22 +3,6 @@ import { Automation } from "../../documents"
export interface DeleteAutomationResponse extends DocumentDestroyResponse {} export interface DeleteAutomationResponse extends DocumentDestroyResponse {}
export interface AutomationBuilderData {
displayName: string
triggerInfo?: {
type: string
table: {
id: string
name: string
}
rowAction: {
id: string
name: string
}
}
}
export interface FetchAutomationResponse { export interface FetchAutomationResponse {
automations: Automation[] automations: Automation[]
builderData?: Record<string, AutomationBuilderData> // The key will be the automationId
} }