Merge pull request #14854 from Budibase/chore/simplify-automation-data
Trigger info data in the frontend
This commit is contained in:
commit
8466f8883c
|
@ -3,7 +3,7 @@
|
|||
automationStore,
|
||||
selectedAutomation,
|
||||
permissions,
|
||||
selectedAutomationDisplayData,
|
||||
tables,
|
||||
} from "stores/builder"
|
||||
import {
|
||||
Icon,
|
||||
|
@ -17,6 +17,7 @@
|
|||
AbsTooltip,
|
||||
InlineAlert,
|
||||
} from "@budibase/bbui"
|
||||
import { sdk } from "@budibase/shared-core"
|
||||
import AutomationBlockSetup from "../../SetupPanel/AutomationBlockSetup.svelte"
|
||||
import CreateWebhookModal from "components/automation/Shared/CreateWebhookModal.svelte"
|
||||
import ActionModal from "./ActionModal.svelte"
|
||||
|
@ -51,7 +52,12 @@
|
|||
$: isAppAction && setPermissions(role)
|
||||
$: 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) {
|
||||
if (!role || !automationId) {
|
||||
|
@ -187,10 +193,10 @@
|
|||
{block}
|
||||
{webhookModal}
|
||||
/>
|
||||
{#if isTrigger && triggerInfo}
|
||||
{#if triggerInfo}
|
||||
<InlineAlert
|
||||
header={triggerInfo.type}
|
||||
message={`This trigger is tied to the "${triggerInfo.rowAction.name}" row action in your ${triggerInfo.table.name} table`}
|
||||
header={triggerInfo.title}
|
||||
message={`This trigger is tied to your "${triggerInfo.tableName}" table`}
|
||||
/>
|
||||
{/if}
|
||||
{#if lastStep}
|
||||
|
|
|
@ -112,7 +112,7 @@
|
|||
iconColor={automation.disabled
|
||||
? "var(--spectrum-global-color-gray-600)"
|
||||
: "var(--spectrum-global-color-gray-900)"}
|
||||
text={automation.displayName}
|
||||
text={automation.name}
|
||||
selected={automation._id === $selectedAutomation?._id}
|
||||
hovering={automation._id === $contextMenuStore.id}
|
||||
on:click={() => automationStore.actions.select(automation._id)}
|
||||
|
|
|
@ -25,15 +25,9 @@
|
|||
automation.name.toLowerCase().includes(searchString.toLowerCase())
|
||||
)
|
||||
})
|
||||
.map(automation => ({
|
||||
...automation,
|
||||
displayName:
|
||||
$automationStore.automationDisplayData[automation._id]?.displayName ||
|
||||
automation.name,
|
||||
}))
|
||||
.sort((a, b) => {
|
||||
const lowerA = a.displayName.toLowerCase()
|
||||
const lowerB = b.displayName.toLowerCase()
|
||||
const lowerA = a.name.toLowerCase()
|
||||
const lowerB = b.name.toLowerCase()
|
||||
return lowerA > lowerB ? 1 : -1
|
||||
})
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ const initialAutomationState = {
|
|||
ACTION: {},
|
||||
},
|
||||
selectedAutomationId: null,
|
||||
automationDisplayData: {},
|
||||
}
|
||||
|
||||
// If this functions, remove the actions elements
|
||||
|
@ -83,7 +82,7 @@ const automationActions = store => ({
|
|||
},
|
||||
fetch: async () => {
|
||||
const [automationResponse, definitions] = await Promise.all([
|
||||
API.getAutomations({ enrich: true }),
|
||||
API.getAutomations(),
|
||||
API.getAutomationDefinitions(),
|
||||
])
|
||||
store.update(state => {
|
||||
|
@ -91,7 +90,6 @@ const automationActions = store => ({
|
|||
state.automations.sort((a, b) => {
|
||||
return a.name < b.name ? -1 : 1
|
||||
})
|
||||
state.automationDisplayData = automationResponse.builderData
|
||||
state.blockDefinitions = getFinalDefinitions(
|
||||
definitions.trigger,
|
||||
definitions.action
|
||||
|
@ -153,8 +151,6 @@ const automationActions = store => ({
|
|||
state.selectedAutomationId = state.automations[0]?._id || null
|
||||
}
|
||||
|
||||
// Clear out automationDisplayData for the automation
|
||||
delete state.automationDisplayData[automation._id]
|
||||
return state
|
||||
})
|
||||
},
|
||||
|
@ -432,13 +428,3 @@ 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]
|
||||
}
|
||||
)
|
||||
|
|
|
@ -11,7 +11,6 @@ import {
|
|||
automationStore,
|
||||
selectedAutomation,
|
||||
automationHistoryStore,
|
||||
selectedAutomationDisplayData,
|
||||
} from "./automations.js"
|
||||
import { userStore, userSelectedResourceMap, isOnlyUser } from "./users.js"
|
||||
import { deploymentStore } from "./deployments.js"
|
||||
|
@ -46,7 +45,6 @@ export {
|
|||
previewStore,
|
||||
automationStore,
|
||||
selectedAutomation,
|
||||
selectedAutomationDisplayData,
|
||||
automationHistoryStore,
|
||||
sortedScreens,
|
||||
userStore,
|
||||
|
|
|
@ -26,14 +26,9 @@ export const buildAutomationEndpoints = API => ({
|
|||
/**
|
||||
* Gets a list of all automations.
|
||||
*/
|
||||
getAutomations: async ({ enrich }) => {
|
||||
const params = new URLSearchParams()
|
||||
if (enrich) {
|
||||
params.set("enrich", true)
|
||||
}
|
||||
|
||||
getAutomations: async () => {
|
||||
return await API.get({
|
||||
url: `/api/automations?${params.toString()}`,
|
||||
url: "/api/automations",
|
||||
})
|
||||
},
|
||||
|
||||
|
|
|
@ -76,16 +76,8 @@ export async function update(ctx: UserCtx) {
|
|||
}
|
||||
|
||||
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()
|
||||
ctx.body = { automations }
|
||||
if (enrich) {
|
||||
ctx.body.builderData = await sdk.automations.utils.getBuilderData(
|
||||
automations
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function find(ctx: UserCtx) {
|
||||
|
|
|
@ -1,56 +1,7 @@
|
|||
import {
|
||||
Automation,
|
||||
AutomationActionStepId,
|
||||
AutomationBuilderData,
|
||||
} from "@budibase/types"
|
||||
import { sdk as coreSdk } from "@budibase/shared-core"
|
||||
import sdk from "../../../sdk"
|
||||
import { Automation, AutomationActionStepId } from "@budibase/types"
|
||||
|
||||
export function checkForCollectStep(automation: Automation) {
|
||||
return automation.definition.steps.some(
|
||||
(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
|
||||
}
|
||||
|
|
|
@ -3,22 +3,6 @@ import { Automation } from "../../documents"
|
|||
|
||||
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 {
|
||||
automations: Automation[]
|
||||
builderData?: Record<string, AutomationBuilderData> // The key will be the automationId
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue