From 872446e5244d8b904332fa5d21b6529249279f09 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 3 Sep 2024 19:47:12 +0100 Subject: [PATCH] Replace other usages of manual row actions API calls with store usage --- .../UpdateRowActionModal.svelte | 13 ++++--- .../actions/RowAction.svelte | 36 +++---------------- .../table/[tableId]/[viewId]/index.svelte | 6 +--- .../data/table/[tableId]/index.svelte | 6 +--- .../builder/src/stores/builder/automations.js | 9 ++--- .../builder/src/stores/builder/rowActions.js | 30 ++++++++++++++++ 6 files changed, 48 insertions(+), 52 deletions(-) diff --git a/packages/builder/src/components/automation/AutomationPanel/UpdateRowActionModal.svelte b/packages/builder/src/components/automation/AutomationPanel/UpdateRowActionModal.svelte index af754d7ca9..db22dab678 100644 --- a/packages/builder/src/components/automation/AutomationPanel/UpdateRowActionModal.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/UpdateRowActionModal.svelte @@ -1,5 +1,5 @@
diff --git a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte index 3596f1b832..698e8307de 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte @@ -28,11 +28,7 @@ return (rowActions || []).map(action => ({ text: action.name, onClick: async row => { - await API.rowActions.trigger({ - rowActionId: action.id, - sourceId: id, - rowId: row._id, - }) + await rowActions.trigger(id, action.id, row._id) }, })) } diff --git a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/index.svelte index 788b178fc7..09c20cf059 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/index.svelte @@ -66,11 +66,7 @@ return (rowActions || []).map(action => ({ text: action.name, onClick: async row => { - await API.rowActions.trigger({ - rowActionId: action.id, - sourceId: id, - rowId: row._id, - }) + await rowActions.trigger(id, action.id, row._id) }, })) } diff --git a/packages/builder/src/stores/builder/automations.js b/packages/builder/src/stores/builder/automations.js index 69a340d340..d6d89567a7 100644 --- a/packages/builder/src/stores/builder/automations.js +++ b/packages/builder/src/stores/builder/automations.js @@ -7,6 +7,7 @@ import { notifications } from "@budibase/bbui" import { updateReferencesInObject } from "dataBinding" import { AutomationTriggerStepId } from "@budibase/types" import { sdk } from "@budibase/shared-core" +import { rowActions } from "./rowActions" const initialAutomationState = { automations: [], @@ -126,10 +127,10 @@ const automationActions = store => ({ delete: async automation => { const isRowAction = sdk.automations.isRowAction(automation) if (isRowAction) { - await API.rowActions.delete({ - tableId: automation.definition.trigger.inputs.tableId, - rowActionId: automation.definition.trigger.inputs.rowActionId, - }) + await rowActions.delete( + automation.definition.trigger.inputs.tableId, + automation.definition.trigger.inputs.rowActionId + ) } else { await API.deleteAutomation({ automationId: automation?._id, diff --git a/packages/builder/src/stores/builder/rowActions.js b/packages/builder/src/stores/builder/rowActions.js index 0255e4726c..58a207bb2e 100644 --- a/packages/builder/src/stores/builder/rowActions.js +++ b/packages/builder/src/stores/builder/rowActions.js @@ -86,6 +86,36 @@ export class RowActionStore extends BudiStore { }) await this.refreshRowActions(tableId) } + + rename = async (tableId, rowActionId, name) => { + await API.rowActions.update({ + tableId, + rowActionId, + name, + }) + await Promise.all([ + this.refreshRowActions(tableId), + automationStore.actions.fetch(), + ]) + } + + delete = async (tableId, rowActionId) => { + await API.rowActions.delete({ + tableId, + rowActionId, + }) + await this.refreshRowActions(tableId) + // We don't need to refresh automations as we can only delete row actions + // from the automations store, so we already handle the state update there + } + + trigger = async (sourceId, rowActionId, rowId) => { + await API.rowActions.trigger({ + sourceId, + rowActionId, + rowId, + }) + } } const store = new RowActionStore()