Display data
This commit is contained in:
parent
6221b9320e
commit
b7a969280f
|
@ -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}
|
||||
<InlineAlert
|
||||
header="Automation trigger"
|
||||
message="This trigger is tied to the row action TODO on your TODO"
|
||||
header={$selectedAutomationDisplayData.triggerInfo.title}
|
||||
message={$selectedAutomationDisplayData.triggerInfo.description}
|
||||
/>
|
||||
{/if}
|
||||
{#if lastStep}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<void, FetchAutomationResponse>) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Record<string, AutomationBuilderData>> {
|
||||
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) {
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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<string, AutomationBuilderData> // The key will be the automationId
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue