diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/DuplicateRow.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/DuplicateRow.svelte new file mode 100644 index 0000000000..38c4347e43 --- /dev/null +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/DuplicateRow.svelte @@ -0,0 +1,152 @@ + + +
+ + Choose the data source that provides the row you would like to duplicate. +
+ You can always add or override fields manually. + + +
+ + option.name} + getOptionValue={option => option._id} + /> + +
+ + {#if parameters.tableId} +
+ +
+ {/if} +
+ + diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/index.js b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/index.js index cca8ece484..1734416605 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/index.js +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/EventsEditor/actions/index.js @@ -13,6 +13,7 @@ import CloseScreenModal from "./CloseScreenModal.svelte" import ChangeFormStep from "./ChangeFormStep.svelte" import UpdateStateStep from "./UpdateState.svelte" import RefreshDataProvider from "./RefreshDataProvider.svelte" +import DuplicateRow from "./DuplicateRow.svelte" // Defines which actions are available to configure in the front end. // Unfortunately the "name" property is used as the identifier so please don't @@ -27,6 +28,10 @@ export const getAvailableActions = () => { name: "Save Row", component: SaveRow, }, + { + name: "Duplicate Row", + component: DuplicateRow, + }, { name: "Delete Row", component: DeleteRow, diff --git a/packages/client/src/utils/buttonActions.js b/packages/client/src/utils/buttonActions.js index 5ee571ae5d..0380f6d1e8 100644 --- a/packages/client/src/utils/buttonActions.js +++ b/packages/client/src/utils/buttonActions.js @@ -10,6 +10,25 @@ import { saveRow, deleteRow, executeQuery, triggerAutomation } from "api" import { ActionTypes } from "constants" const saveRowHandler = async (action, context) => { + const { fields, providerId, tableId } = action.parameters + let payload + if (providerId) { + payload = context[providerId] + } else { + payload = {} + } + if (fields) { + for (let [field, value] of Object.entries(fields)) { + payload[field] = value + } + } + if (tableId) { + payload.tableId = tableId + } + await saveRow(payload) +} + +const duplicateRowHandler = async (action, context) => { const { fields, providerId, tableId } = action.parameters if (providerId) { let draft = context[providerId] @@ -21,6 +40,8 @@ const saveRowHandler = async (action, context) => { if (tableId) { draft.tableId = tableId } + delete draft._id + delete draft._rev await saveRow(draft) } } @@ -120,6 +141,7 @@ const updateStateHandler = action => { const handlerMap = { ["Save Row"]: saveRowHandler, + ["Duplicate Row"]: duplicateRowHandler, ["Delete Row"]: deleteRowHandler, ["Navigate To"]: navigationHandler, ["Execute Query"]: queryExecutionHandler,