From 2b5b3444a1a392865bfa8824fef223746c6aad66 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Mon, 13 May 2024 12:44:44 -0300 Subject: [PATCH] some adjusts --- .../create-update-delete-record.mjs | 18 +++++++++++++-- components/twenty/common/utils.mjs | 23 +++++++++++++++++++ .../new-record-modified-instant.mjs} | 4 ++-- .../test-event.mjs | 0 4 files changed, 41 insertions(+), 4 deletions(-) rename components/twenty/sources/{new-record-instant/new-record-instant.mjs => new-record-modified-instant/new-record-modified-instant.mjs} (92%) rename components/twenty/sources/{new-record-instant => new-record-modified-instant}/test-event.mjs (100%) diff --git a/components/twenty/actions/create-update-delete-record/create-update-delete-record.mjs b/components/twenty/actions/create-update-delete-record/create-update-delete-record.mjs index 7b652fc3988b9..8ea2961cf67c0 100644 --- a/components/twenty/actions/create-update-delete-record/create-update-delete-record.mjs +++ b/components/twenty/actions/create-update-delete-record/create-update-delete-record.mjs @@ -1,4 +1,6 @@ -import { camelCaseToWords } from "../../common/utils.mjs"; +import { + camelCaseToWords, parseObject, +} from "../../common/utils.mjs"; import twenty from "../../twenty.app.mjs"; export default { @@ -23,6 +25,12 @@ export default { ], reloadProps: true, }, + additionalProp: { + type: "object", + label: "Additional Prop", + description: "Any additional prop you want to fill.", + optional: true, + }, }, async additionalProps() { const props = {}; @@ -94,6 +102,7 @@ export default { id, recordId, actionType, + additionalProp, ...data } = this; @@ -110,7 +119,12 @@ export default { id, actionType: this.actionType, recordName: tags[index + 1].name, - data, + data: { + ...data, + ...(additionalProp + ? parseObject(additionalProp) + : {}), + }, }); $.export("$summary", `Successfully performed ${actionType} ${recordId} on record with ID: ${id || response.data[`${actionType}${recordId}`].id}`); diff --git a/components/twenty/common/utils.mjs b/components/twenty/common/utils.mjs index 81f4a9ea51d28..f097aeac6c1b2 100644 --- a/components/twenty/common/utils.mjs +++ b/components/twenty/common/utils.mjs @@ -6,3 +6,26 @@ export const camelCaseToWords = (s) => { export const capitalizeFirstLetter = (string) => { return string.charAt(0).toLowerCase() + string.slice(1); }; + +export const parseObject = (obj) => { + if (Array.isArray(obj)) { + return obj.map((item) => { + if (typeof item === "string") { + try { + return JSON.parse(item); + } catch (e) { + return item; + } + } + return item; + }); + } + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch (e) { + return obj; + } + } + return obj; +}; diff --git a/components/twenty/sources/new-record-instant/new-record-instant.mjs b/components/twenty/sources/new-record-modified-instant/new-record-modified-instant.mjs similarity index 92% rename from components/twenty/sources/new-record-instant/new-record-instant.mjs rename to components/twenty/sources/new-record-modified-instant/new-record-modified-instant.mjs index f8552e7e74d30..3209ad0503310 100644 --- a/components/twenty/sources/new-record-instant/new-record-instant.mjs +++ b/components/twenty/sources/new-record-modified-instant/new-record-modified-instant.mjs @@ -2,8 +2,8 @@ import twenty from "../../twenty.app.mjs"; import sampleEmit from "./test-event.mjs"; export default { - key: "twenty-new-record-instant", - name: "New Record (Instant)", + key: "twenty-new-record-modified-instant", + name: "New Record Modified (Instant)", description: "Emit new event when a record is created, updated, or deleted.", version: "0.0.1", type: "source", diff --git a/components/twenty/sources/new-record-instant/test-event.mjs b/components/twenty/sources/new-record-modified-instant/test-event.mjs similarity index 100% rename from components/twenty/sources/new-record-instant/test-event.mjs rename to components/twenty/sources/new-record-modified-instant/test-event.mjs