From 18694fcab71b57ccf6dd0b7fb227b8785fac315c Mon Sep 17 00:00:00 2001 From: Ayobami Akingbade Date: Fri, 19 Jan 2024 02:15:32 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(form-actions):=20?= =?UTF-8?q?split=20integrations=20API=20from=20=20form-actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/_/forCodeCoverage.spec.ts | 14 +- src/__tests__/admin/[entity]/index.spec.tsx | 16 +- src/__tests__/admin/index.spec.tsx | 14 -- src/__tests__/api/_test-utils/_all.ts | 4 +- ...{_action-instances.ts => _form-actions.ts} | 16 +- .../api/data/[entity]/[id]/index.spec.ts | 2 +- src/__tests__/api/data/[entity]/index.spec.ts | 2 +- .../instances => form-actions}/[key].spec.ts | 40 ++--- .../instances => form-actions}/index.spec.ts | 42 +----- .../integrations/actions/[key]/index.spec.ts | 14 +- .../variables__constants.spec.tsx | 4 +- ...variables__credentials--non-admin.spec.tsx | 4 +- .../variables__credentials.spec.tsx | 8 +- src/__tests__/roles/index.spec.tsx | 12 +- src/__tests__/users/index.spec.tsx | 10 +- src/backend/data/data.service.ts | 17 +-- .../__tests__/run-action.spec.ts | 14 +- .../form-actions/form-actions.service.ts | 54 +++++++ src/backend/form-actions/run-form-action.ts | 56 +++++++ .../integrations.service.ts} | 141 +++--------------- .../libs}/http/__tests__/index.spec.ts | 0 .../libs}/http/index.ts | 0 .../libs}/index.ts | 0 .../libs}/mailgun/__tests__/index.spec.ts | 0 .../libs}/mailgun/__tests__/sendMail.spec.ts | 0 .../libs}/mailgun/index.ts | 0 .../libs}/mailgun/sendMail.ts | 0 .../libs}/mailgun/types.ts | 0 .../libs}/makeIntegrationRequest.ts | 0 .../libs}/postmark/__tests__/index.spec.ts | 0 .../libs}/postmark/__tests__/sendMail.spec.ts | 0 .../libs}/postmark/index.ts | 0 .../libs}/postmark/sendMail.ts | 0 .../libs}/postmark/types.ts | 0 .../libs}/sendgrid/__tests__/index.spec.ts | 0 .../libs}/sendgrid/__tests__/sendMail.spec.ts | 0 .../libs}/sendgrid/index.ts | 0 .../libs}/sendgrid/sendMail.ts | 0 .../libs}/sendgrid/types.ts | 0 .../libs}/sendinblue/__tests__/index.spec.ts | 0 .../sendinblue/__tests__/sendMail.spec.ts | 0 .../libs}/sendinblue/index.ts | 0 .../libs}/sendinblue/sendMail.ts | 0 .../libs}/sendinblue/types.ts | 0 .../libs}/slack/__tests__/index.spec.ts | 0 .../libs}/slack/__tests__/sendMessage.spec.ts | 0 .../libs}/slack/index.ts | 0 .../libs}/slack/sendMessage.ts | 0 .../libs}/slack/types.ts | 0 .../libs}/smtp/__tests__/index.spec.ts | 0 .../libs}/smtp/__tests__/sendMail.spec.ts | 0 .../libs}/smtp/index.ts | 0 .../libs}/smtp/sendMail.ts | 0 .../libs}/smtp/types.ts | 0 .../libs}/twilio/__tests__/index.spec.ts | 0 .../twilio/__tests__/sendMessage.spec.ts | 0 .../libs}/twilio/index.ts | 0 .../libs}/twilio/sendSms.ts | 0 .../libs}/twilio/types.ts | 0 src/backend/lib/config-persistence/types.ts | 2 +- src/frontend/docs/form-integrations.tsx | 7 +- src/frontend/views/entity/Actions/Base.tsx | 80 +++++----- src/frontend/views/entity/Actions/Form.tsx | 24 +-- .../views/entity/Actions/constants.ts | 6 +- ...stances.store.ts => form-actions.store.ts} | 66 ++++---- src/frontend/views/entity/Actions/index.tsx | 12 +- src/frontend/views/entity/_Base.tsx | 4 +- .../integrations/actions/View/Deactivate.tsx | 4 +- .../instances => form-actions}/[key].ts | 8 +- .../instances => form-actions}/index.ts | 4 +- src/pages/api/healthcheck/index.ts | 4 +- .../integrations/actions/[key]/credentials.ts | 4 +- .../actions/[key]/implementations.ts | 4 +- .../api/integrations/actions/[key]/index.ts | 8 +- src/pages/api/integrations/actions/active.ts | 4 +- src/pages/api/integrations/actions/list.ts | 4 +- src/shared/constants/Icons.tsx | 2 +- src/shared/types/actions.ts | 4 +- 78 files changed, 350 insertions(+), 385 deletions(-) rename src/__tests__/api/_test-utils/{_action-instances.ts => _form-actions.ts} (54%) rename src/__tests__/api/{integrations/actions/instances => form-actions}/[key].spec.ts (78%) rename src/__tests__/api/{integrations/actions/instances => form-actions}/index.spec.ts (65%) rename src/backend/{actions => form-actions}/__tests__/run-action.spec.ts (96%) create mode 100644 src/backend/form-actions/form-actions.service.ts create mode 100644 src/backend/form-actions/run-form-action.ts rename src/backend/{actions/actions.service.ts => integrations/integrations.service.ts} (51%) rename src/backend/{actions/integrations => integrations/libs}/http/__tests__/index.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/http/index.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/index.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/mailgun/__tests__/index.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/mailgun/__tests__/sendMail.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/mailgun/index.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/mailgun/sendMail.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/mailgun/types.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/makeIntegrationRequest.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/postmark/__tests__/index.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/postmark/__tests__/sendMail.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/postmark/index.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/postmark/sendMail.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/postmark/types.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/sendgrid/__tests__/index.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/sendgrid/__tests__/sendMail.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/sendgrid/index.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/sendgrid/sendMail.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/sendgrid/types.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/sendinblue/__tests__/index.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/sendinblue/__tests__/sendMail.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/sendinblue/index.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/sendinblue/sendMail.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/sendinblue/types.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/slack/__tests__/index.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/slack/__tests__/sendMessage.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/slack/index.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/slack/sendMessage.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/slack/types.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/smtp/__tests__/index.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/smtp/__tests__/sendMail.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/smtp/index.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/smtp/sendMail.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/smtp/types.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/twilio/__tests__/index.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/twilio/__tests__/sendMessage.spec.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/twilio/index.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/twilio/sendSms.ts (100%) rename src/backend/{actions/integrations => integrations/libs}/twilio/types.ts (100%) rename src/frontend/views/entity/Actions/{instances.store.ts => form-actions.store.ts} (50%) rename src/pages/api/{integrations/actions/instances => form-actions}/[key].ts (81%) rename src/pages/api/{integrations/actions/instances => form-actions}/index.ts (77%) diff --git a/src/__tests__/_/forCodeCoverage.spec.ts b/src/__tests__/_/forCodeCoverage.spec.ts index 860eef0c3..d1e2913b0 100644 --- a/src/__tests__/_/forCodeCoverage.spec.ts +++ b/src/__tests__/_/forCodeCoverage.spec.ts @@ -9,13 +9,13 @@ import { FOR_CODE_COV as $8 } from "shared/types/db"; import { FOR_CODE_COV as $9 } from "shared/types/ui"; import { FOR_CODE_COV as $10 } from "backend/data/types"; import { FOR_CODE_COV as $11 } from "backend/lib/request/validations/implementations/types"; -import { FOR_CODE_COV as $12 } from "backend/actions/integrations/mailgun/types"; -import { FOR_CODE_COV as $13 } from "backend/actions/integrations/postmark/types"; -import { FOR_CODE_COV as $14 } from "backend/actions/integrations/sendgrid/types"; -import { FOR_CODE_COV as $15 } from "backend/actions/integrations/sendinblue/types"; -import { FOR_CODE_COV as $16 } from "backend/actions/integrations/slack/types"; -import { FOR_CODE_COV as $17 } from "backend/actions/integrations/smtp/types"; -import { FOR_CODE_COV as $18 } from "backend/actions/integrations/twilio/types"; +import { FOR_CODE_COV as $12 } from "backend/integrations/libs/mailgun/types"; +import { FOR_CODE_COV as $13 } from "backend/integrations/libs/postmark/types"; +import { FOR_CODE_COV as $14 } from "backend/integrations/libs/sendgrid/types"; +import { FOR_CODE_COV as $15 } from "backend/integrations/libs/sendinblue/types"; +import { FOR_CODE_COV as $16 } from "backend/integrations/libs/slack/types"; +import { FOR_CODE_COV as $17 } from "backend/integrations/libs/smtp/types"; +import { FOR_CODE_COV as $18 } from "backend/integrations/libs/twilio/types"; import { FOR_CODE_COV as $19 } from "backend/storage/types"; import { FOR_CODE_COV as $21 } from "shared/form-schemas/roles/permissions/base"; import { FOR_CODE_COV as $22 } from "backend/lib/config-persistence/portal/index"; diff --git a/src/__tests__/admin/[entity]/index.spec.tsx b/src/__tests__/admin/[entity]/index.spec.tsx index 5c2eb159e..b093ec863 100644 --- a/src/__tests__/admin/[entity]/index.spec.tsx +++ b/src/__tests__/admin/[entity]/index.spec.tsx @@ -32,7 +32,21 @@ describe("pages/admin/[entity]/index", () => { expect(await getTableRows(screen.getByRole("table"))) .toMatchInlineSnapshot(` [ - "Entity 1 Id FieldEntity 1 Reference FieldEntity 1 String FieldEntity 1 Number FieldEntity 1 Boolean FieldEntity 1 Date FieldEntity 1 Enum FieldActions", + "Entity 1 Id Field + + Entity 1 Reference Field + + Entity 1 String Field + + Entity 1 Number Field + + Entity 1 Boolean Field + + Entity 1 Date Field + + Entity 1 Enum Field + + Actions", "187‌hello > p-1,t=15,o=d < 347th May 2022foo", "188‌there > p-1,t=15,o=d < 217th May 2021foo", "189‌today > p-1,t=15,o=d < 187th Feb 2022bar", diff --git a/src/__tests__/admin/index.spec.tsx b/src/__tests__/admin/index.spec.tsx index a71afe3c2..f8ba43618 100644 --- a/src/__tests__/admin/index.spec.tsx +++ b/src/__tests__/admin/index.spec.tsx @@ -91,15 +91,6 @@ describe("pages/admin", () => { "Some SVG Here" ); - // expect(within(widget).getByLabelText("New Summary Card Icon").innerHTML) - // .toBe(` - // - // `); - - expect(within(widget).getByLabelText("Bar Card Icon")).toHaveAttribute( - "color", - "#FF165D" - ); expect(within(widget).getByLabelText("Total Count")).toHaveTextContent( "10" ); @@ -113,11 +104,6 @@ describe("pages/admin", () => { "#03d87f" ); - expect(within(widget).getByLabelText("Bar Card Icon")).toHaveAttribute( - "color", - "#FF165D" - ); - expect(within(widget).getByRole("link", { name: "View" })).toHaveAttribute( "href", "/admin/entity-1" diff --git a/src/__tests__/api/_test-utils/_all.ts b/src/__tests__/api/_test-utils/_all.ts index 89fb74c72..957219a18 100644 --- a/src/__tests__/api/_test-utils/_all.ts +++ b/src/__tests__/api/_test-utils/_all.ts @@ -10,7 +10,7 @@ import { setupSchemaTestData } from "./_schema"; import { setupUsersTestData } from "./_users"; import { setupIntegrationsEnvTestData } from "./_integrations-env"; import { setupActivatedIntegrationsTestData } from "./_activated-integrations"; -import { setupActionInstanceTestData } from "./_action-instances"; +import { setupFormActionsTestData } from "./_form-actions"; import { setupTestDatabaseData } from "./_data"; import { portalTestData } from "./portal"; import { setupUserPreferencesTestData } from "./_user-preferences"; @@ -26,7 +26,7 @@ export const setupAllTestData = async (domains: DomainTypes[]) => { ["schema", setupSchemaTestData], ["data", setupTestDatabaseData], ["activated-integrations", setupActivatedIntegrationsTestData], - ["action-instances", setupActionInstanceTestData], + ["form-actions", setupFormActionsTestData], ["constants", setupIntegrationsConstantsTestData], ["environment-variables", setupIntegrationsEnvTestData], ["credentials", setupCredentialsTestData], diff --git a/src/__tests__/api/_test-utils/_action-instances.ts b/src/__tests__/api/_test-utils/_form-actions.ts similarity index 54% rename from src/__tests__/api/_test-utils/_action-instances.ts rename to src/__tests__/api/_test-utils/_form-actions.ts index cfcf84c3b..13cc2a870 100644 --- a/src/__tests__/api/_test-utils/_action-instances.ts +++ b/src/__tests__/api/_test-utils/_form-actions.ts @@ -1,10 +1,10 @@ import { createConfigDomainPersistenceService } from "backend/lib/config-persistence"; -import { ActionIntegrations, IActionInstance } from "shared/types/actions"; +import { ActionIntegrations, IFormAction } from "shared/types/actions"; import { DataEventActions } from "shared/types/data"; -const TEST_ACTION_INSTANCES: IActionInstance[] = [ +const TEST_FORM_ACTIONS: IFormAction[] = [ { - instanceId: "instance-id-1", + id: "form-action-id-1", integration: ActionIntegrations.SMTP, entity: "base-model", action: "SEND_MESSAGE", @@ -14,7 +14,7 @@ const TEST_ACTION_INSTANCES: IActionInstance[] = [ }, }, { - instanceId: "instance-id-2", + id: "form-action-id-2", integration: ActionIntegrations.HTTP, entity: "secondary-model", action: "POST", @@ -25,11 +25,11 @@ const TEST_ACTION_INSTANCES: IActionInstance[] = [ }, ]; -export const setupActionInstanceTestData = async ( - testActionInstances: IActionInstance[] = TEST_ACTION_INSTANCES +export const setupFormActionsTestData = async ( + formActions: IFormAction[] = TEST_FORM_ACTIONS ) => { const configPersistenceService = - createConfigDomainPersistenceService("action-instances"); + createConfigDomainPersistenceService("form-actions"); - await configPersistenceService.resetState("instanceId", testActionInstances); + await configPersistenceService.resetState("id", formActions); }; diff --git a/src/__tests__/api/data/[entity]/[id]/index.spec.ts b/src/__tests__/api/data/[entity]/[id]/index.spec.ts index 35ce2bfb2..312dd1f6d 100644 --- a/src/__tests__/api/data/[entity]/[id]/index.spec.ts +++ b/src/__tests__/api/data/[entity]/[id]/index.spec.ts @@ -12,7 +12,7 @@ describe("/api/data/[entity]/[id]/index", () => { "credentials", "app-config", "data", - "action-instances", + "form-actions", ]); }); diff --git a/src/__tests__/api/data/[entity]/index.spec.ts b/src/__tests__/api/data/[entity]/index.spec.ts index abceab2b8..fe7e96724 100644 --- a/src/__tests__/api/data/[entity]/index.spec.ts +++ b/src/__tests__/api/data/[entity]/index.spec.ts @@ -13,7 +13,7 @@ describe("/api/data/[entity]/index", () => { "credentials", "app-config", "data", - "action-instances", + "form-actions", ]); }); diff --git a/src/__tests__/api/integrations/actions/instances/[key].spec.ts b/src/__tests__/api/form-actions/[key].spec.ts similarity index 78% rename from src/__tests__/api/integrations/actions/instances/[key].spec.ts rename to src/__tests__/api/form-actions/[key].spec.ts index d6408b72f..0430e28c8 100644 --- a/src/__tests__/api/integrations/actions/instances/[key].spec.ts +++ b/src/__tests__/api/form-actions/[key].spec.ts @@ -1,15 +1,15 @@ -import handler from "pages/api/integrations/actions/instances/[key]"; -import { ActionIntegrations, IActionInstance } from "shared/types/actions"; +import handler from "pages/api/form-actions/[key]"; +import { ActionIntegrations, IFormAction } from "shared/types/actions"; import { createAuthenticatedMocks, setupAllTestData, } from "__tests__/api/_test-utils"; -import { setupActionInstanceTestData } from "__tests__/api/_test-utils/_action-instances"; +import { setupFormActionsTestData } from "__tests__/api/_test-utils/_form-actions"; import { DataEventActions } from "shared/types/data"; -const TEST_ACTION_INSTANCES: IActionInstance[] = [ +const TEST_FORM_ACTIONS: IFormAction[] = [ { - instanceId: "instance-id-1", + id: "form-action-id-1", integration: ActionIntegrations.SMTP, entity: "base-model", action: "SEND_MESSAGE", @@ -19,7 +19,7 @@ const TEST_ACTION_INSTANCES: IActionInstance[] = [ }, }, { - instanceId: "instance-id-2", + id: "form-action-id-2", integration: ActionIntegrations.SMTP, entity: "base-model", action: "SEND_MESSAGE", @@ -29,7 +29,7 @@ const TEST_ACTION_INSTANCES: IActionInstance[] = [ }, }, { - instanceId: "instance-id-3", + id: "form-action-id-3", integration: ActionIntegrations.SMTP, entity: "base-model", action: "SEND_MESSAGE", @@ -39,7 +39,7 @@ const TEST_ACTION_INSTANCES: IActionInstance[] = [ }, }, { - instanceId: "instance-id-4", + id: "form-action-id-4", integration: ActionIntegrations.HTTP, entity: "secondary-model", action: "POST", @@ -50,13 +50,13 @@ const TEST_ACTION_INSTANCES: IActionInstance[] = [ }, ]; -describe("/api/integrations/actions/instances/[key]", () => { +describe("/api/form-action/[key]", () => { beforeAll(async () => { await setupAllTestData(["activated-integrations"]); - await setupActionInstanceTestData(TEST_ACTION_INSTANCES); + await setupFormActionsTestData(TEST_FORM_ACTIONS); }); - it("should show entity action instances", async () => { + it("should show entity form actions", async () => { const { req, res } = createAuthenticatedMocks({ method: "GET", query: { @@ -74,7 +74,7 @@ describe("/api/integrations/actions/instances/[key]", () => { "foo": "bar", }, "entity": "base-model", - "instanceId": "instance-id-1", + "id": "form-action-id-1", "integration": "smtp", "trigger": "create", }, @@ -84,7 +84,7 @@ describe("/api/integrations/actions/instances/[key]", () => { "foo1": "bar1", }, "entity": "base-model", - "instanceId": "instance-id-2", + "id": "form-action-id-2", "integration": "smtp", "trigger": "delete", }, @@ -94,7 +94,7 @@ describe("/api/integrations/actions/instances/[key]", () => { "foo2": "bar2", }, "entity": "base-model", - "instanceId": "instance-id-3", + "id": "form-action-id-3", "integration": "smtp", "trigger": "update", }, @@ -102,11 +102,11 @@ describe("/api/integrations/actions/instances/[key]", () => { `); }); - it("should delete action instances", async () => { + it("should delete form actions", async () => { const { req, res } = createAuthenticatedMocks({ method: "DELETE", query: { - key: "instance-id-3", + key: "form-action-id-3", }, }); await handler(req, res); @@ -125,11 +125,11 @@ describe("/api/integrations/actions/instances/[key]", () => { expect(getRes._getJSONData()).toHaveLength(2); }); - it("should patch action instances", async () => { + it("should patch form action", async () => { const { req, res } = createAuthenticatedMocks({ method: "PATCH", query: { - key: "instance-id-2", + key: "form-action-id-2", }, body: { integration: "slack", @@ -163,7 +163,7 @@ describe("/api/integrations/actions/instances/[key]", () => { "foo": "bar", }, "entity": "base-model", - "instanceId": "instance-id-1", + "id": "form-action-id-1", "integration": "smtp", "trigger": "create", }, @@ -174,7 +174,7 @@ describe("/api/integrations/actions/instances/[key]", () => { "you": "are", }, "entity": "base-model", - "instanceId": "instance-id-2", + "id": "form-action-id-2", "integration": "slack", "trigger": "update", }, diff --git a/src/__tests__/api/integrations/actions/instances/index.spec.ts b/src/__tests__/api/form-actions/index.spec.ts similarity index 65% rename from src/__tests__/api/integrations/actions/instances/index.spec.ts rename to src/__tests__/api/form-actions/index.spec.ts index 762eb345b..94df4e63c 100644 --- a/src/__tests__/api/integrations/actions/instances/index.spec.ts +++ b/src/__tests__/api/form-actions/index.spec.ts @@ -1,5 +1,5 @@ -import handler from "pages/api/integrations/actions/instances/index"; -import getHandler from "pages/api/integrations/actions/instances/[key]"; +import handler from "pages/api/form-actions/index"; +import getHandler from "pages/api/form-actions/[key]"; import { createAuthenticatedMocks, setupAllTestData, @@ -12,9 +12,9 @@ jest.mock("nanoid", () => ({ .mockReturnValueOnce("nano-id-2"), })); -describe("/api/integrations/actions/instances/index", () => { +describe("/api/form-actions/index", () => { beforeAll(async () => { - await setupAllTestData(["action-instances", "activated-integrations"]); + await setupAllTestData(["form-actions", "activated-integrations"]); }); it("should instantiate actions", async () => { @@ -59,35 +59,7 @@ describe("/api/integrations/actions/instances/index", () => { expect(res._getStatusCode()).toBe(201); }); - it("should not instantiate action for un-activated integration", async () => { - const { req, res } = createAuthenticatedMocks({ - method: "POST", - body: { - integration: "postmark", - entity: "test-entity-2", - action: "GET", - trigger: "update", - configuration: { - bad: '{"request": "hello"}', - }, - }, - }); - - await handler(req, res); - - expect(res._getStatusCode()).toBe(400); - expect(res._getJSONData()).toMatchInlineSnapshot(` - { - "message": "The integration for 'postmark' has not yet been activated", - "method": "POST", - "name": "BadRequestError", - "path": "", - "statusCode": 400, - } - `); - }); - - it("should show all the added action instances", async () => { + it("should show all the added form actions", async () => { const { req, res } = createAuthenticatedMocks({ method: "GET", query: { @@ -107,7 +79,7 @@ describe("/api/integrations/actions/instances/index", () => { "to": "me", }, "entity": "test-entity", - "instanceId": "nano-id-1", + "id": "nano-id-1", "integration": "smtp", "trigger": "update", }, @@ -119,7 +91,7 @@ describe("/api/integrations/actions/instances/index", () => { "url": "/some-where", }, "entity": "test-entity", - "instanceId": "nano-id-2", + "id": "nano-id-2", "integration": "http", "trigger": "create", }, diff --git a/src/__tests__/api/integrations/actions/[key]/index.spec.ts b/src/__tests__/api/integrations/actions/[key]/index.spec.ts index 62fa8ed7d..46634bb43 100644 --- a/src/__tests__/api/integrations/actions/[key]/index.spec.ts +++ b/src/__tests__/api/integrations/actions/[key]/index.spec.ts @@ -1,13 +1,13 @@ import handler from "pages/api/integrations/actions/[key]/index"; import activeHandler from "pages/api/integrations/actions/active"; -import getHandler from "pages/api/integrations/actions/instances/[key]"; +import getHandler from "pages/api/form-actions/[key]"; import credentialsHandler from "pages/api/integrations/actions/[key]/credentials"; import { createAuthenticatedMocks, setupAllTestData, } from "__tests__/api/_test-utils"; -import { setupActionInstanceTestData } from "__tests__/api/_test-utils/_action-instances"; +import { setupFormActionsTestData } from "__tests__/api/_test-utils/_form-actions"; import { ActionIntegrations } from "shared/types/actions"; import { DataEventActions } from "shared/types/data"; @@ -19,9 +19,9 @@ describe("/api/integrations/actions/[key]/index", () => { beforeAll(async () => { await setupAllTestData(["activated-integrations", "users"]); - await setupActionInstanceTestData([ + await setupFormActionsTestData([ { - instanceId: "instance-id-1", + id: "form-action-id-1", integration: ActionIntegrations.HTTP, entity: "base-model", action: "SEND_MESSAGE", @@ -31,7 +31,7 @@ describe("/api/integrations/actions/[key]/index", () => { }, }, { - instanceId: "instance-id-2", + id: "form-action-id-2", integration: ActionIntegrations.SLACK, entity: "secondary-model", action: "POST", @@ -246,7 +246,7 @@ describe("/api/integrations/actions/[key]/index", () => { }); describe("DELETE", () => { - it("should list integration instances", async () => { + it("should list integration form actions", async () => { const { req: getReq, res: resReq } = createAuthenticatedMocks({ method: "GET", query: { @@ -311,7 +311,7 @@ describe("/api/integrations/actions/[key]/index", () => { `); }); - it("should delete all instances", async () => { + it("should delete all form actions", async () => { const { req: getReq, res: resReq } = createAuthenticatedMocks({ method: "GET", query: { diff --git a/src/__tests__/integrations/variables__constants.spec.tsx b/src/__tests__/integrations/variables__constants.spec.tsx index 16d7f3bc6..6b3cdd642 100644 --- a/src/__tests__/integrations/variables__constants.spec.tsx +++ b/src/__tests__/integrations/variables__constants.spec.tsx @@ -114,7 +114,7 @@ describe("pages/integrations/variables => constants", () => { await userEvent.click( within(tableRows[1]).getByRole("button", { - name: "Edit", + name: "Edit Constant", }) ); @@ -172,7 +172,7 @@ describe("pages/integrations/variables => constants", () => { await userEvent.click( within(tableRows[2]).getByRole("button", { - name: "Delete Button", + name: "Delete Constant", }) ); diff --git a/src/__tests__/integrations/variables__credentials--non-admin.spec.tsx b/src/__tests__/integrations/variables__credentials--non-admin.spec.tsx index 4f8d16201..24b09b985 100644 --- a/src/__tests__/integrations/variables__credentials--non-admin.spec.tsx +++ b/src/__tests__/integrations/variables__credentials--non-admin.spec.tsx @@ -83,7 +83,7 @@ describe("pages/integrations/variables => credentials -- non admin", () => { ).not.toBeInTheDocument(); expect( screen.queryByRole("button", { - name: "Delete Button", + name: "Delete Secret", }) ).not.toBeInTheDocument(); }); @@ -119,7 +119,7 @@ describe("pages/integrations/variables => credentials -- non admin", () => { ).not.toBeInTheDocument(); expect( await screen.findAllByRole("button", { - name: "Delete Button", + name: "Delete Secret", }) ).toHaveLength(3); }); diff --git a/src/__tests__/integrations/variables__credentials.spec.tsx b/src/__tests__/integrations/variables__credentials.spec.tsx index 5fd84d6e6..94fc65f9a 100644 --- a/src/__tests__/integrations/variables__credentials.spec.tsx +++ b/src/__tests__/integrations/variables__credentials.spec.tsx @@ -151,7 +151,7 @@ describe("pages/integrations/variables => credentials", () => { ).not.toBeInTheDocument(); expect( screen.queryByRole("button", { - name: "Edit", + name: "Edit Secret", }) ).not.toBeInTheDocument(); expect( @@ -305,7 +305,7 @@ describe("pages/integrations/variables => credentials", () => { expect( screen.queryAllByRole("button", { - name: "Edit", + name: "Edit Secret", }) ).toHaveLength(3); expect( @@ -349,7 +349,7 @@ describe("pages/integrations/variables => credentials", () => { within((await within(table).findAllByRole("row"))[1]).getByRole( "button", { - name: "Edit", + name: "Edit Secret", } ) ); @@ -449,7 +449,7 @@ describe("pages/integrations/variables => credentials", () => { await userEvent.click( within(tableRows[2]).getByRole("button", { - name: "Delete Button", + name: "Delete Secret", }) ); diff --git a/src/__tests__/roles/index.spec.tsx b/src/__tests__/roles/index.spec.tsx index 856911219..9d96247d0 100644 --- a/src/__tests__/roles/index.spec.tsx +++ b/src/__tests__/roles/index.spec.tsx @@ -31,10 +31,10 @@ describe("pages/roles", () => { expect(screen.getByRole("row", { name: "Creator" })).toBeInTheDocument(); expect(screen.getByRole("row", { name: "Viewer" })).toBeInTheDocument(); expect( - screen.getByRole("row", { name: "Role 1 Edit" }) + screen.getByRole("row", { name: "Role 1 Edit Role" }) ).toBeInTheDocument(); expect( - screen.getByRole("row", { name: "Role 2 Edit" }) + screen.getByRole("row", { name: "Role 2 Edit Role" }) ).toBeInTheDocument(); }); @@ -73,7 +73,7 @@ describe("pages/roles", () => { ); - const tableRows = await screen.findAllByRole("link", { name: "Edit" }); + const tableRows = await screen.findAllByRole("link", { name: "Edit Role" }); expect(tableRows).toHaveLength(2); }); @@ -101,19 +101,19 @@ describe("pages/roles", () => { expect( within(tableRows[1]).queryByRole("button", { - name: "Delete Button", + name: "Delete Role", }) ).not.toBeInTheDocument(); expect( within(tableRows[2]).queryByRole("button", { - name: "Delete Button", + name: "Delete Role", }) ).not.toBeInTheDocument(); await userEvent.click( within(tableRows[4]).getByRole("button", { - name: "Delete Button", + name: "Delete Role", }) ); diff --git a/src/__tests__/users/index.spec.tsx b/src/__tests__/users/index.spec.tsx index 82a28f597..7f7bd1a93 100644 --- a/src/__tests__/users/index.spec.tsx +++ b/src/__tests__/users/index.spec.tsx @@ -30,16 +30,16 @@ describe("pages/users", () => { ).toBeInTheDocument(); expect( screen.getByRole("row", { - name: "user-1 User 1 Role 1 user-1@here.com station - 1 Edit", + name: "user-1 User 1 Role 1 user-1@here.com station - 1 Edit User", }) ).toBeInTheDocument(); expect( screen.getByRole("row", { - name: "user-2 User 2 Role 2 user-1@here.com Edit", + name: "user-2 User 2 Role 2 user-1@here.com Edit User", }) ).toBeInTheDocument(); expect( - screen.getByRole("row", { name: "user-3 User 3 Role 3 Edit" }) + screen.getByRole("row", { name: "user-3 User 3 Role 3 Edit User" }) ).toBeInTheDocument(); }); @@ -78,7 +78,7 @@ describe("pages/users", () => { ); - const tableRows = await screen.findAllByRole("link", { name: "Edit" }); + const tableRows = await screen.findAllByRole("link", { name: "Edit User" }); expect(tableRows[0]).toHaveAttribute("href", "/users/user-1"); expect(tableRows[1]).toHaveAttribute("href", "/users/user-2"); @@ -108,7 +108,7 @@ describe("pages/users", () => { await userEvent.click( within(tableRows[1]).getByRole("button", { - name: "Delete Button", + name: "Delete User", }) ); diff --git a/src/backend/data/data.service.ts b/src/backend/data/data.service.ts index d658d0142..5b6725e93 100644 --- a/src/backend/data/data.service.ts +++ b/src/backend/data/data.service.ts @@ -5,13 +5,10 @@ import { PaginatedData, QueryFilterSchema, } from "shared/types/data"; -import { - actionsApiService, - ActionsApiService, -} from "backend/actions/actions.service"; import { IEntityField } from "shared/types/db"; import { IAccountProfile } from "shared/types/user"; import { compileTemplateString } from "shared/lib/strings/templates"; +import { runFormAction } from "backend/form-actions/run-form-action"; import { rDBMSDataApiService, RDBMSDataApiService } from "./data-access/RDBMS"; import { IDataApiService, IPaginationFilters } from "./types"; import { @@ -33,8 +30,7 @@ export class DataApiService implements IDataApiService { constructor( private _rDBMSApiDataService: RDBMSDataApiService, private _entitiesApiService: EntitiesApiService, - private _configurationApiService: ConfigurationApiService, - private _actionsApiService: ActionsApiService + private _configurationApiService: ConfigurationApiService ) {} async bootstrap() { @@ -151,7 +147,7 @@ export class DataApiService implements IDataApiService { insertId: id, }); - await this._actionsApiService.runAction( + await runFormAction( entity, DataEventActions.Create, async () => await this.showData(entity, id), @@ -267,7 +263,7 @@ export class DataApiService implements IDataApiService { options, }); - await this._actionsApiService.runAction( + await runFormAction( entity, DataEventActions.Update, async () => await this.showData(entity, id), @@ -280,7 +276,7 @@ export class DataApiService implements IDataApiService { id: string, accountProfile: IAccountProfile ): Promise { - await this._actionsApiService.runAction( + await runFormAction( entity, DataEventActions.Delete, async () => await this.showData(entity, id), @@ -363,6 +359,5 @@ export class DataApiService implements IDataApiService { export const dataApiService = new DataApiService( rDBMSDataApiService, entitiesApiService, - configurationApiService, - actionsApiService + configurationApiService ); diff --git a/src/backend/actions/__tests__/run-action.spec.ts b/src/backend/form-actions/__tests__/run-action.spec.ts similarity index 96% rename from src/backend/actions/__tests__/run-action.spec.ts rename to src/backend/form-actions/__tests__/run-action.spec.ts index 2476db4b8..f78d10a29 100644 --- a/src/backend/actions/__tests__/run-action.spec.ts +++ b/src/backend/form-actions/__tests__/run-action.spec.ts @@ -7,7 +7,7 @@ import { setupAllTestData, setupCredentialsTestData, } from "__tests__/api/_test-utils"; -import { setupActionInstanceTestData } from "__tests__/api/_test-utils/_action-instances"; +import { setupFormActionsTestData } from "__tests__/api/_test-utils/_form-actions"; import { setupIntegrationsConstantsTestData } from "__tests__/api/_test-utils/_integrations-constants"; import { createTransport } from "nodemailer"; import { DataEventActions } from "shared/types/data"; @@ -60,9 +60,9 @@ describe("Run Action", () => { "aad0f7e776963ae66b7459222d54871433f8e119ab9a9712d4e82e8cbb77246e47a750a773c0ea316c110a1d3f2ee16c2509906fb89f1c4b039d09f139b1d7eacc26908c25137c46f269cfb13f63221da2f1631bf4f59cbe14cc18cbfb8993098bd7e2d865f20717", }); - await setupActionInstanceTestData([ + await setupFormActionsTestData([ { - instanceId: "instance-id-1", + id: "form-action-id-1", integration: ActionIntegrations.SMTP, entity: "tests", action: "SEND_MAIL", @@ -78,7 +78,7 @@ describe("Run Action", () => { }, }, { - instanceId: "instance-id-5", + id: "form-action-id-5", integration: ActionIntegrations.HTTP, entity: "tests", action: "POST", @@ -93,7 +93,7 @@ describe("Run Action", () => { }, }, { - instanceId: "instance-id-2", + id: "form-action-id-2", integration: ActionIntegrations.SLACK, entity: "tests", action: "SEND_MESSAGE", @@ -105,7 +105,7 @@ describe("Run Action", () => { }, }, { - instanceId: "instance-id-3", + id: "form-action-id-3", integration: ActionIntegrations.SLACK, entity: "DO_NOT_CALL_ME_CAUSE_INVALID_ENTITY", action: "SEND_MESSAGE", @@ -117,7 +117,7 @@ describe("Run Action", () => { }, }, { - instanceId: "instance-id-4", + id: "form-action-id-4", integration: ActionIntegrations.HTTP, entity: "tests", action: "POST", diff --git a/src/backend/form-actions/form-actions.service.ts b/src/backend/form-actions/form-actions.service.ts new file mode 100644 index 000000000..58fefb1db --- /dev/null +++ b/src/backend/form-actions/form-actions.service.ts @@ -0,0 +1,54 @@ +import { + createConfigDomainPersistenceService, + AbstractConfigDataPersistenceService, +} from "backend/lib/config-persistence"; +import { IApplicationService } from "backend/types"; +import { nanoid } from "nanoid"; +import { IFormAction } from "shared/types/actions"; + +export class FormActionsApiService implements IApplicationService { + constructor( + private readonly _formActionsPersistenceService: AbstractConfigDataPersistenceService + ) {} + + async bootstrap() { + await this._formActionsPersistenceService.setup(); + } + + async createFormAction(action: Omit) { + const id = nanoid(); + + await this._formActionsPersistenceService.createItem(id, { + ...action, + id, + }); + } + + async updateFormAction(id: string, formAction: Omit) { + await this._formActionsPersistenceService.upsertItem(id, { + ...formAction, + id, + }); + } + + async deleteFormAction(formActionId: string) { + await this._formActionsPersistenceService.removeItem(formActionId); + } + + async getAllFormAction() { + return await this._formActionsPersistenceService.getAllItems(); + } + + async listEntityFormActions(entity$1: string) { + return (await this._formActionsPersistenceService.getAllItems()).filter( + ({ entity }) => entity === entity$1 + ); + } +} + +const formActionsPersistenceService = + createConfigDomainPersistenceService("form-actions"); + +export const formActionsApiService = new FormActionsApiService( + formActionsPersistenceService +); diff --git a/src/backend/form-actions/run-form-action.ts b/src/backend/form-actions/run-form-action.ts new file mode 100644 index 000000000..e566b4b0e --- /dev/null +++ b/src/backend/form-actions/run-form-action.ts @@ -0,0 +1,56 @@ +import { DataEventActions } from "shared/types/data"; +import { IAccountProfile } from "shared/types/user"; +import { compileTemplateString } from "shared/lib/strings/templates"; +import { getAppCredentialsAndConstants } from "backend/integrations-configurations/utils"; +import { INTEGRATIONS_GROUP_CONFIG } from "shared/config-bag/integrations"; +import { integrationsApiService } from "backend/integrations/integrations.service"; +import { ACTION_INTEGRATIONS } from "../integrations/libs"; +import { formActionsApiService } from "./form-actions.service"; + +export const runFormAction = async ( + entity: string, + dataEventAction: DataEventActions, + getData: () => Promise>, + accountProfile: IAccountProfile +) => { + const formActions = await formActionsApiService.listEntityFormActions(entity); + const actionsToRun = formActions.filter( + (action) => action.trigger === dataEventAction + ); + + if (actionsToRun.length === 0) { + return; + } + + const data = await getData(); + + const { appConstants, credentials } = await getAppCredentialsAndConstants(); + + for (const actionToRun of actionsToRun) { + const { configuration, action, integration } = actionToRun; + + const actionConfiguration = + await integrationsApiService.getIntegrationCredentials(integration); + + const connection = await ACTION_INTEGRATIONS[integration].connect( + actionConfiguration + ); + + const compiledConfiguration = Object.fromEntries( + Object.entries(configuration || {}).map(([key, value]) => [ + key, + compileTemplateString(value, { + data, + [INTEGRATIONS_GROUP_CONFIG.constants.prefix]: appConstants, + [INTEGRATIONS_GROUP_CONFIG.credentials.prefix]: credentials, + auth: accountProfile, + }), + ]) + ); + + await ACTION_INTEGRATIONS[integration].performsImplementation[action].do( + connection, + compiledConfiguration + ); + } +}; diff --git a/src/backend/actions/actions.service.ts b/src/backend/integrations/integrations.service.ts similarity index 51% rename from src/backend/actions/actions.service.ts rename to src/backend/integrations/integrations.service.ts index a1159e9a4..82db59788 100644 --- a/src/backend/actions/actions.service.ts +++ b/src/backend/integrations/integrations.service.ts @@ -2,133 +2,36 @@ import { credentialsApiService, CredentialsApiService, } from "backend/integrations-configurations"; -import { - createConfigDomainPersistenceService, - AbstractConfigDataPersistenceService, -} from "backend/lib/config-persistence"; -import { BadRequestError } from "backend/lib/errors"; import { validateSchemaRequestBody } from "backend/lib/errors/validate-schema-request-input"; -import { IApplicationService } from "backend/types"; -import { nanoid } from "nanoid"; -import { INTEGRATIONS_GROUP_CONFIG } from "shared/config-bag/integrations"; import { IIntegrationsList, - IActionInstance, IIntegrationImplementationList, ActionIntegrations, } from "shared/types/actions"; -import { IAccountProfile } from "shared/types/user"; -import { compileTemplateString } from "shared/lib/strings/templates"; import { sluggify } from "shared/lib/strings"; -import { DataEventActions } from "shared/types/data"; import { createKeyValueDomainPersistenceService, KeyValueStoreApiService, } from "backend/lib/key-value"; -import { getAppCredentialsAndConstants } from "backend/integrations-configurations/utils"; -import { ACTION_INTEGRATIONS } from "./integrations"; +import { IApplicationService } from "backend/types"; +import { noop } from "shared/lib/noop"; +import { + formActionsApiService, + FormActionsApiService, +} from "backend/form-actions/form-actions.service"; +import { ACTION_INTEGRATIONS } from "./libs"; -export class ActionsApiService implements IApplicationService { +export class IntegrationsApiService implements IApplicationService { constructor( private readonly _activatedIntegrationsPersistenceService: KeyValueStoreApiService< ActionIntegrations[] >, - private readonly _actionInstancesPersistenceService: AbstractConfigDataPersistenceService, - private readonly _credentialsApiService: CredentialsApiService + private readonly _credentialsApiService: CredentialsApiService, + private readonly _formActionsApiService: FormActionsApiService ) {} async bootstrap() { - await this._actionInstancesPersistenceService.setup(); - } - - async runAction( - entity: string, - dataEventAction: DataEventActions, - getData: () => Promise>, - accountProfile: IAccountProfile - ) { - const instances = await this.listEntityActionInstances(entity); - const actionsToRun = instances.filter( - (action) => action.trigger === dataEventAction - ); - - if (actionsToRun.length === 0) { - return; - } - - const data = await getData(); - - const { appConstants, credentials } = await getAppCredentialsAndConstants(); - - for (const actionToRun of actionsToRun) { - const { configuration, action, integration } = actionToRun; - - const actionConfiguration = await this.getIntegrationCredentials( - integration - ); - - const connection = await ACTION_INTEGRATIONS[integration].connect( - actionConfiguration - ); - - const compiledConfiguration = Object.fromEntries( - Object.entries(configuration || {}).map(([key, value]) => [ - key, - compileTemplateString(value, { - data, - [INTEGRATIONS_GROUP_CONFIG.constants.prefix]: appConstants, - [INTEGRATIONS_GROUP_CONFIG.credentials.prefix]: credentials, - auth: accountProfile, - }), - ]) - ); - - await ACTION_INTEGRATIONS[integration].performsImplementation[action].do( - connection, - compiledConfiguration - ); - } - } - - async instantiateAction(action: Omit) { - const instanceId = nanoid(); - const activatedIntegrations = await this.listActivatedIntegrations(); - - const integration = activatedIntegrations.find( - (activatedIntegration) => activatedIntegration === action.integration - ); - - if (!integration) { - throw new BadRequestError( - `The integration for '${action.integration}' has not yet been activated` - ); - } - - await this._actionInstancesPersistenceService.createItem(instanceId, { - ...action, - integration, - instanceId, - }); - } - - async updateActionInstance( - instanceId: string, - instance: Omit - ) { - await this._actionInstancesPersistenceService.upsertItem(instanceId, { - ...instance, - instanceId, - }); - } - - async deleteActionInstance(instanceId: string) { - await this._actionInstancesPersistenceService.removeItem(instanceId); - } - - async listEntityActionInstances(entity$1: string) { - return (await this._actionInstancesPersistenceService.getAllItems()).filter( - ({ entity }) => entity === entity$1 - ); + noop(); } listActionIntegrations(): IIntegrationsList[] { @@ -161,7 +64,7 @@ export class ActionsApiService implements IApplicationService { return [...activatedIntegrations, ActionIntegrations.HTTP]; } - async activateAction( + async activateIntegration( integration: ActionIntegrations, configuration: Record ): Promise { @@ -243,14 +146,11 @@ export class ActionsApiService implements IApplicationService { ) ); - const instances = - await this._actionInstancesPersistenceService.getAllItems(); + const formActions = await this._formActionsApiService.getAllFormAction(); - for (const instance of instances) { - if (instance.integration === integration) { - await this._actionInstancesPersistenceService.removeItem( - instance.instanceId - ); + for (const formAction of formActions) { + if (formAction.integration === integration) { + await this._formActionsApiService.deleteFormAction(formAction.id); } } } @@ -261,11 +161,8 @@ const activatedIntegrationsPersistenceService = "activated-integrations" ); -const actionInstancesPersistenceService = - createConfigDomainPersistenceService("action-instances"); - -export const actionsApiService = new ActionsApiService( +export const integrationsApiService = new IntegrationsApiService( activatedIntegrationsPersistenceService, - actionInstancesPersistenceService, - credentialsApiService + credentialsApiService, + formActionsApiService ); diff --git a/src/backend/actions/integrations/http/__tests__/index.spec.ts b/src/backend/integrations/libs/http/__tests__/index.spec.ts similarity index 100% rename from src/backend/actions/integrations/http/__tests__/index.spec.ts rename to src/backend/integrations/libs/http/__tests__/index.spec.ts diff --git a/src/backend/actions/integrations/http/index.ts b/src/backend/integrations/libs/http/index.ts similarity index 100% rename from src/backend/actions/integrations/http/index.ts rename to src/backend/integrations/libs/http/index.ts diff --git a/src/backend/actions/integrations/index.ts b/src/backend/integrations/libs/index.ts similarity index 100% rename from src/backend/actions/integrations/index.ts rename to src/backend/integrations/libs/index.ts diff --git a/src/backend/actions/integrations/mailgun/__tests__/index.spec.ts b/src/backend/integrations/libs/mailgun/__tests__/index.spec.ts similarity index 100% rename from src/backend/actions/integrations/mailgun/__tests__/index.spec.ts rename to src/backend/integrations/libs/mailgun/__tests__/index.spec.ts diff --git a/src/backend/actions/integrations/mailgun/__tests__/sendMail.spec.ts b/src/backend/integrations/libs/mailgun/__tests__/sendMail.spec.ts similarity index 100% rename from src/backend/actions/integrations/mailgun/__tests__/sendMail.spec.ts rename to src/backend/integrations/libs/mailgun/__tests__/sendMail.spec.ts diff --git a/src/backend/actions/integrations/mailgun/index.ts b/src/backend/integrations/libs/mailgun/index.ts similarity index 100% rename from src/backend/actions/integrations/mailgun/index.ts rename to src/backend/integrations/libs/mailgun/index.ts diff --git a/src/backend/actions/integrations/mailgun/sendMail.ts b/src/backend/integrations/libs/mailgun/sendMail.ts similarity index 100% rename from src/backend/actions/integrations/mailgun/sendMail.ts rename to src/backend/integrations/libs/mailgun/sendMail.ts diff --git a/src/backend/actions/integrations/mailgun/types.ts b/src/backend/integrations/libs/mailgun/types.ts similarity index 100% rename from src/backend/actions/integrations/mailgun/types.ts rename to src/backend/integrations/libs/mailgun/types.ts diff --git a/src/backend/actions/integrations/makeIntegrationRequest.ts b/src/backend/integrations/libs/makeIntegrationRequest.ts similarity index 100% rename from src/backend/actions/integrations/makeIntegrationRequest.ts rename to src/backend/integrations/libs/makeIntegrationRequest.ts diff --git a/src/backend/actions/integrations/postmark/__tests__/index.spec.ts b/src/backend/integrations/libs/postmark/__tests__/index.spec.ts similarity index 100% rename from src/backend/actions/integrations/postmark/__tests__/index.spec.ts rename to src/backend/integrations/libs/postmark/__tests__/index.spec.ts diff --git a/src/backend/actions/integrations/postmark/__tests__/sendMail.spec.ts b/src/backend/integrations/libs/postmark/__tests__/sendMail.spec.ts similarity index 100% rename from src/backend/actions/integrations/postmark/__tests__/sendMail.spec.ts rename to src/backend/integrations/libs/postmark/__tests__/sendMail.spec.ts diff --git a/src/backend/actions/integrations/postmark/index.ts b/src/backend/integrations/libs/postmark/index.ts similarity index 100% rename from src/backend/actions/integrations/postmark/index.ts rename to src/backend/integrations/libs/postmark/index.ts diff --git a/src/backend/actions/integrations/postmark/sendMail.ts b/src/backend/integrations/libs/postmark/sendMail.ts similarity index 100% rename from src/backend/actions/integrations/postmark/sendMail.ts rename to src/backend/integrations/libs/postmark/sendMail.ts diff --git a/src/backend/actions/integrations/postmark/types.ts b/src/backend/integrations/libs/postmark/types.ts similarity index 100% rename from src/backend/actions/integrations/postmark/types.ts rename to src/backend/integrations/libs/postmark/types.ts diff --git a/src/backend/actions/integrations/sendgrid/__tests__/index.spec.ts b/src/backend/integrations/libs/sendgrid/__tests__/index.spec.ts similarity index 100% rename from src/backend/actions/integrations/sendgrid/__tests__/index.spec.ts rename to src/backend/integrations/libs/sendgrid/__tests__/index.spec.ts diff --git a/src/backend/actions/integrations/sendgrid/__tests__/sendMail.spec.ts b/src/backend/integrations/libs/sendgrid/__tests__/sendMail.spec.ts similarity index 100% rename from src/backend/actions/integrations/sendgrid/__tests__/sendMail.spec.ts rename to src/backend/integrations/libs/sendgrid/__tests__/sendMail.spec.ts diff --git a/src/backend/actions/integrations/sendgrid/index.ts b/src/backend/integrations/libs/sendgrid/index.ts similarity index 100% rename from src/backend/actions/integrations/sendgrid/index.ts rename to src/backend/integrations/libs/sendgrid/index.ts diff --git a/src/backend/actions/integrations/sendgrid/sendMail.ts b/src/backend/integrations/libs/sendgrid/sendMail.ts similarity index 100% rename from src/backend/actions/integrations/sendgrid/sendMail.ts rename to src/backend/integrations/libs/sendgrid/sendMail.ts diff --git a/src/backend/actions/integrations/sendgrid/types.ts b/src/backend/integrations/libs/sendgrid/types.ts similarity index 100% rename from src/backend/actions/integrations/sendgrid/types.ts rename to src/backend/integrations/libs/sendgrid/types.ts diff --git a/src/backend/actions/integrations/sendinblue/__tests__/index.spec.ts b/src/backend/integrations/libs/sendinblue/__tests__/index.spec.ts similarity index 100% rename from src/backend/actions/integrations/sendinblue/__tests__/index.spec.ts rename to src/backend/integrations/libs/sendinblue/__tests__/index.spec.ts diff --git a/src/backend/actions/integrations/sendinblue/__tests__/sendMail.spec.ts b/src/backend/integrations/libs/sendinblue/__tests__/sendMail.spec.ts similarity index 100% rename from src/backend/actions/integrations/sendinblue/__tests__/sendMail.spec.ts rename to src/backend/integrations/libs/sendinblue/__tests__/sendMail.spec.ts diff --git a/src/backend/actions/integrations/sendinblue/index.ts b/src/backend/integrations/libs/sendinblue/index.ts similarity index 100% rename from src/backend/actions/integrations/sendinblue/index.ts rename to src/backend/integrations/libs/sendinblue/index.ts diff --git a/src/backend/actions/integrations/sendinblue/sendMail.ts b/src/backend/integrations/libs/sendinblue/sendMail.ts similarity index 100% rename from src/backend/actions/integrations/sendinblue/sendMail.ts rename to src/backend/integrations/libs/sendinblue/sendMail.ts diff --git a/src/backend/actions/integrations/sendinblue/types.ts b/src/backend/integrations/libs/sendinblue/types.ts similarity index 100% rename from src/backend/actions/integrations/sendinblue/types.ts rename to src/backend/integrations/libs/sendinblue/types.ts diff --git a/src/backend/actions/integrations/slack/__tests__/index.spec.ts b/src/backend/integrations/libs/slack/__tests__/index.spec.ts similarity index 100% rename from src/backend/actions/integrations/slack/__tests__/index.spec.ts rename to src/backend/integrations/libs/slack/__tests__/index.spec.ts diff --git a/src/backend/actions/integrations/slack/__tests__/sendMessage.spec.ts b/src/backend/integrations/libs/slack/__tests__/sendMessage.spec.ts similarity index 100% rename from src/backend/actions/integrations/slack/__tests__/sendMessage.spec.ts rename to src/backend/integrations/libs/slack/__tests__/sendMessage.spec.ts diff --git a/src/backend/actions/integrations/slack/index.ts b/src/backend/integrations/libs/slack/index.ts similarity index 100% rename from src/backend/actions/integrations/slack/index.ts rename to src/backend/integrations/libs/slack/index.ts diff --git a/src/backend/actions/integrations/slack/sendMessage.ts b/src/backend/integrations/libs/slack/sendMessage.ts similarity index 100% rename from src/backend/actions/integrations/slack/sendMessage.ts rename to src/backend/integrations/libs/slack/sendMessage.ts diff --git a/src/backend/actions/integrations/slack/types.ts b/src/backend/integrations/libs/slack/types.ts similarity index 100% rename from src/backend/actions/integrations/slack/types.ts rename to src/backend/integrations/libs/slack/types.ts diff --git a/src/backend/actions/integrations/smtp/__tests__/index.spec.ts b/src/backend/integrations/libs/smtp/__tests__/index.spec.ts similarity index 100% rename from src/backend/actions/integrations/smtp/__tests__/index.spec.ts rename to src/backend/integrations/libs/smtp/__tests__/index.spec.ts diff --git a/src/backend/actions/integrations/smtp/__tests__/sendMail.spec.ts b/src/backend/integrations/libs/smtp/__tests__/sendMail.spec.ts similarity index 100% rename from src/backend/actions/integrations/smtp/__tests__/sendMail.spec.ts rename to src/backend/integrations/libs/smtp/__tests__/sendMail.spec.ts diff --git a/src/backend/actions/integrations/smtp/index.ts b/src/backend/integrations/libs/smtp/index.ts similarity index 100% rename from src/backend/actions/integrations/smtp/index.ts rename to src/backend/integrations/libs/smtp/index.ts diff --git a/src/backend/actions/integrations/smtp/sendMail.ts b/src/backend/integrations/libs/smtp/sendMail.ts similarity index 100% rename from src/backend/actions/integrations/smtp/sendMail.ts rename to src/backend/integrations/libs/smtp/sendMail.ts diff --git a/src/backend/actions/integrations/smtp/types.ts b/src/backend/integrations/libs/smtp/types.ts similarity index 100% rename from src/backend/actions/integrations/smtp/types.ts rename to src/backend/integrations/libs/smtp/types.ts diff --git a/src/backend/actions/integrations/twilio/__tests__/index.spec.ts b/src/backend/integrations/libs/twilio/__tests__/index.spec.ts similarity index 100% rename from src/backend/actions/integrations/twilio/__tests__/index.spec.ts rename to src/backend/integrations/libs/twilio/__tests__/index.spec.ts diff --git a/src/backend/actions/integrations/twilio/__tests__/sendMessage.spec.ts b/src/backend/integrations/libs/twilio/__tests__/sendMessage.spec.ts similarity index 100% rename from src/backend/actions/integrations/twilio/__tests__/sendMessage.spec.ts rename to src/backend/integrations/libs/twilio/__tests__/sendMessage.spec.ts diff --git a/src/backend/actions/integrations/twilio/index.ts b/src/backend/integrations/libs/twilio/index.ts similarity index 100% rename from src/backend/actions/integrations/twilio/index.ts rename to src/backend/integrations/libs/twilio/index.ts diff --git a/src/backend/actions/integrations/twilio/sendSms.ts b/src/backend/integrations/libs/twilio/sendSms.ts similarity index 100% rename from src/backend/actions/integrations/twilio/sendSms.ts rename to src/backend/integrations/libs/twilio/sendSms.ts diff --git a/src/backend/actions/integrations/twilio/types.ts b/src/backend/integrations/libs/twilio/types.ts similarity index 100% rename from src/backend/actions/integrations/twilio/types.ts rename to src/backend/integrations/libs/twilio/types.ts diff --git a/src/backend/lib/config-persistence/types.ts b/src/backend/lib/config-persistence/types.ts index f944f15fc..8d72b4e25 100644 --- a/src/backend/lib/config-persistence/types.ts +++ b/src/backend/lib/config-persistence/types.ts @@ -13,7 +13,7 @@ export type ConfigDomain = | "list-order" | "temp-storage" | "key-value" - | "action-instances" + | "form-actions" | "roles"; export enum ConfigAdaptorTypes { diff --git a/src/frontend/docs/form-integrations.tsx b/src/frontend/docs/form-integrations.tsx index a457a7c6d..7761e6a72 100644 --- a/src/frontend/docs/form-integrations.tsx +++ b/src/frontend/docs/form-integrations.tsx @@ -1,5 +1,5 @@ import { INTEGRATIONS_GROUP_CONFIG } from "shared/config-bag/integrations"; -import { ADMIN_ACTION_INSTANCES_CRUD_CONFIG } from "frontend/views/entity/Actions/constants"; +import { FORM_ACTION_CRUD_CONFIG } from "frontend/views/entity/Actions/constants"; import { ErrorAlert, InfoAlert } from "frontend/design-system/components/Alert"; import { RenderCode } from "frontend/design-system/components/RenderCode"; import { DocumentationRoot } from "./_base"; @@ -29,9 +29,8 @@ export function FormIntegrationsDocumentation() {
  1. {" "} - Click on the{" "} - - {ADMIN_ACTION_INSTANCES_CRUD_CONFIG.TEXT_LANG.CREATE} + Click on the + {FORM_ACTION_CRUD_CONFIG.TEXT_LANG.CREATE} {" "} button.
  2. diff --git a/src/frontend/views/entity/Actions/Base.tsx b/src/frontend/views/entity/Actions/Base.tsx index 7afcb63ed..e95a39c22 100644 --- a/src/frontend/views/entity/Actions/Base.tsx +++ b/src/frontend/views/entity/Actions/Base.tsx @@ -9,7 +9,7 @@ import { useActiveIntegrations, } from "frontend/views/integrations/actions/actions.store"; import { useCallback, useState } from "react"; -import { IActionInstance } from "shared/types/actions"; +import { IFormAction } from "shared/types/actions"; import { useApi } from "frontend/lib/data/useApi"; import { SoftButton } from "frontend/design-system/components/Button/SoftButton"; import { Stack } from "frontend/design-system/primitives/Stack"; @@ -19,65 +19,63 @@ import { OffCanvas } from "frontend/design-system/components/OffCanvas"; import { userFriendlyCase } from "shared/lib/strings/friendly-case"; import { ActionButtons } from "frontend/design-system/components/Button/ActionButtons"; import { DELETE_BUTTON_PROPS } from "frontend/design-system/components/Button/constants"; -import { ADMIN_ACTION_INSTANCES_CRUD_CONFIG } from "./constants"; +import { FORM_ACTION_CRUD_CONFIG } from "./constants"; import { - LIST_ACTION_INSTANCES, - useCreateActionInstanceMutation, - useDeleteActionInstanceMutation, - useUpdateActionInstanceMutation, -} from "./instances.store"; + LIST_ENTITY_FORM_ACTIONS, + useCreateFormActionMutation, + useDeleteFormActionMutation, + useUpdateFormActionMutation, +} from "./form-actions.store"; import { ActionForm } from "./Form"; const NEW_ACTION_ITEM = "__new_action_item__"; -export function BaseActionInstances({ entity }: { entity: string }) { +export function FormActions({ entity }: { entity: string }) { const activeIntegration = useActiveIntegrations(); const integrationsList = useIntegrationsList(); - const dataEndpoint = LIST_ACTION_INSTANCES(entity); + const dataEndpoint = LIST_ENTITY_FORM_ACTIONS(entity); - const tableData = useApi(dataEndpoint, { + const tableData = useApi(dataEndpoint, { defaultData: [], }); - const deleteActionInstanceMutation = useDeleteActionInstanceMutation(entity); - const updateActionInstanceMutation = useUpdateActionInstanceMutation(); - const createActionInstanceMutation = useCreateActionInstanceMutation(); + const deleteFormActionMutation = useDeleteFormActionMutation(entity); + const updateFormActionMutation = useUpdateFormActionMutation(); + const createFormActionMutation = useCreateFormActionMutation(); - const [currentInstanceId, setCurrentInstanceItem] = useState(""); + const [currentFormActionId, setCurrentFormActionId] = useState(""); const closeConfigItem = () => { - setCurrentInstanceItem(""); + setCurrentFormActionId(""); }; const MemoizedAction = useCallback( - ({ row }: IFETableCell) => ( + ({ row }: IFETableCell) => ( setCurrentInstanceItem(row.original.instanceId), - label: ADMIN_ACTION_INSTANCES_CRUD_CONFIG.TEXT_LANG.DELETE, + action: () => setCurrentFormActionId(row.original.id), + label: FORM_ACTION_CRUD_CONFIG.TEXT_LANG.DELETE, systemIcon: "Edit", }, { ...DELETE_BUTTON_PROPS({ action: () => - deleteActionInstanceMutation.mutateAsync( - row.original.instanceId - ), - label: ADMIN_ACTION_INSTANCES_CRUD_CONFIG.TEXT_LANG.DELETE, + deleteFormActionMutation.mutateAsync(row.original.id), + label: FORM_ACTION_CRUD_CONFIG.TEXT_LANG.DELETE, isMakingRequest: false, }), }, ]} /> ), - [deleteActionInstanceMutation.isLoading] + [deleteFormActionMutation.isLoading] ); - const columns: IFETableColumn[] = [ + const columns: IFETableColumn[] = [ { Header: "Integration", accessor: "integration", @@ -86,7 +84,7 @@ export function BaseActionInstances({ entity }: { entity: string }) { bag: undefined, }, // eslint-disable-next-line react/no-unstable-nested-components - Cell: ({ value }: IFETableCell) => { + Cell: ({ value }: IFETableCell) => { return <>{userFriendlyCase(value as string)}; }, }, @@ -98,7 +96,7 @@ export function BaseActionInstances({ entity }: { entity: string }) { bag: undefined, }, // eslint-disable-next-line react/no-unstable-nested-components - Cell: ({ value }: IFETableCell) => { + Cell: ({ value }: IFETableCell) => { return <>{userFriendlyCase(value as string)}; }, }, @@ -110,7 +108,7 @@ export function BaseActionInstances({ entity }: { entity: string }) { bag: undefined, }, // eslint-disable-next-line react/no-unstable-nested-components - Cell: ({ value }: IFETableCell) => { + Cell: ({ value }: IFETableCell) => { return <>{userFriendlyCase(value as string)}; }, }, @@ -131,9 +129,9 @@ export function BaseActionInstances({ entity }: { entity: string }) { > setCurrentInstanceItem(NEW_ACTION_ITEM)} + action={() => setCurrentFormActionId(NEW_ACTION_ITEM)} systemIcon="Plus" - label={ADMIN_ACTION_INSTANCES_CRUD_CONFIG.TEXT_LANG.CREATE} + label={FORM_ACTION_CRUD_CONFIG.TEXT_LANG.CREATE} /> @@ -142,38 +140,38 @@ export function BaseActionInstances({ entity }: { entity: string }) { dataEndpoint={dataEndpoint} columns={columns} empty={{ - text: ADMIN_ACTION_INSTANCES_CRUD_CONFIG.TEXT_LANG.EMPTY_LIST, + text: FORM_ACTION_CRUD_CONFIG.TEXT_LANG.EMPTY_LIST, createNew: { - label: ADMIN_ACTION_INSTANCES_CRUD_CONFIG.TEXT_LANG.CREATE, - action: () => setCurrentInstanceItem(NEW_ACTION_ITEM), + label: FORM_ACTION_CRUD_CONFIG.TEXT_LANG.CREATE, + action: () => setCurrentFormActionId(NEW_ACTION_ITEM), }, }} /> { - if (currentInstanceId === NEW_ACTION_ITEM) { - await createActionInstanceMutation.mutateAsync(data); + if (currentFormActionId === NEW_ACTION_ITEM) { + await createFormActionMutation.mutateAsync(data); } else { - await updateActionInstanceMutation.mutateAsync(data); + await updateFormActionMutation.mutateAsync(data); } closeConfigItem(); }} entity={entity} initialValues={tableData.data.find( - ({ instanceId }) => instanceId === currentInstanceId + ({ id }) => id === currentFormActionId )} formAction={ - currentInstanceId === NEW_ACTION_ITEM ? "create" : "update" + currentFormActionId === NEW_ACTION_ITEM ? "create" : "update" } integrationsList={integrationsList.data} activatedIntegrations={activeIntegration.data} diff --git a/src/frontend/views/entity/Actions/Form.tsx b/src/frontend/views/entity/Actions/Form.tsx index d364b672c..9d91838e1 100644 --- a/src/frontend/views/entity/Actions/Form.tsx +++ b/src/frontend/views/entity/Actions/Form.tsx @@ -4,17 +4,17 @@ import { useState } from "react"; import { IAppliedSchemaFormConfig } from "shared/form-schemas/types"; import { ActionIntegrations, - IActionInstance, + IFormAction, IIntegrationsList, } from "shared/types/actions"; import { userFriendlyCase } from "shared/lib/strings/friendly-case"; import { DataEventActions } from "shared/types/data"; -import { useIntegrationImplementationsList } from "./instances.store"; -import { ADMIN_ACTION_INSTANCES_CRUD_CONFIG } from "./constants"; +import { useIntegrationImplementationsList } from "./form-actions.store"; +import { FORM_ACTION_CRUD_CONFIG } from "./constants"; interface IProps { - onSubmit: (instance: IActionInstance) => Promise; - initialValues?: Partial; + onSubmit: (formAction: IFormAction) => Promise; + initialValues?: Partial; formAction: "create" | "update"; integrationsList: IIntegrationsList[]; activatedIntegrations: ActionIntegrations[]; @@ -39,7 +39,7 @@ export function ActionForm({ value: integration, })); - const [formValues, setFormValues] = useState>({}); + const [formValues, setFormValues] = useState>({}); const implementations = useIntegrationImplementationsList( formValues.integration @@ -113,19 +113,19 @@ export function ActionForm({ }, initialValues); return ( - + buttonText={ formAction === "create" - ? ADMIN_ACTION_INSTANCES_CRUD_CONFIG.FORM_LANG.CREATE - : ADMIN_ACTION_INSTANCES_CRUD_CONFIG.FORM_LANG.UPDATE + ? FORM_ACTION_CRUD_CONFIG.FORM_LANG.CREATE + : FORM_ACTION_CRUD_CONFIG.FORM_LANG.UPDATE } initialValues={initialValues$1} fields={fields} systemIcon={formAction === "create" ? "Plus" : "Save"} onChange={setFormValues} action={formAction} - onSubmit={async (instance) => { - const cleanedConfigurationForm = Object.entries(instance).reduce( + onSubmit={async (value) => { + const cleanedConfigurationForm = Object.entries(value).reduce( (cleanForm, [formKey, formValue]) => { if (formKey.startsWith(CONFIGURATION_FORM_PREFIX)) { const key = formKey.replace(CONFIGURATION_FORM_PREFIX, ""); @@ -137,7 +137,7 @@ export function ActionForm({ return { ...cleanForm, [formKey]: formValue }; }, { configuration: {} } - ) as IActionInstance; + ) as IFormAction; await onSubmit(cleanedConfigurationForm); }} diff --git a/src/frontend/views/entity/Actions/constants.ts b/src/frontend/views/entity/Actions/constants.ts index a95e9c718..a1020a04a 100644 --- a/src/frontend/views/entity/Actions/constants.ts +++ b/src/frontend/views/entity/Actions/constants.ts @@ -1,9 +1,7 @@ import { MAKE_CRUD_CONFIG } from "frontend/lib/crud-config"; -export const BASE_ACTIONS_ENDPOINT = `/api/integrations/actions`; - -export const ADMIN_ACTION_INSTANCES_CRUD_CONFIG = MAKE_CRUD_CONFIG({ - path: `${BASE_ACTIONS_ENDPOINT}/instances`, +export const FORM_ACTION_CRUD_CONFIG = MAKE_CRUD_CONFIG({ + path: `/api/form-actions`, plural: "Form Actions", singular: "Form Action", }); diff --git a/src/frontend/views/entity/Actions/instances.store.ts b/src/frontend/views/entity/Actions/form-actions.store.ts similarity index 50% rename from src/frontend/views/entity/Actions/instances.store.ts rename to src/frontend/views/entity/Actions/form-actions.store.ts index c617eafa2..39070ab95 100644 --- a/src/frontend/views/entity/Actions/instances.store.ts +++ b/src/frontend/views/entity/Actions/form-actions.store.ts @@ -1,7 +1,7 @@ import { CRUD_CONFIG_NOT_FOUND } from "frontend/lib/crud-config"; import { useMutation } from "react-query"; import { - IActionInstance, + IFormAction, IIntegrationImplementationList, } from "shared/types/actions"; import { useApiMutateOptimisticOptions } from "frontend/lib/data/useMutate/useApiMutateOptimisticOptions"; @@ -9,13 +9,12 @@ import { MutationHelpers } from "frontend/lib/data/useMutate/mutation-helpers"; import { makeActionRequest } from "frontend/lib/data/makeRequest"; import { useWaitForResponseMutationOptions } from "frontend/lib/data/useMutate/useWaitForResponseMutationOptions"; import { useApi } from "frontend/lib/data/useApi"; -import { - ADMIN_ACTION_INSTANCES_CRUD_CONFIG, - BASE_ACTIONS_ENDPOINT, -} from "./constants"; +import { FORM_ACTION_CRUD_CONFIG } from "./constants"; + +const BASE_ACTIONS_ENDPOINT = `/api/integrations/actions`; -export const LIST_ACTION_INSTANCES = (entity: string) => { - return `${BASE_ACTIONS_ENDPOINT}/instances/${entity}`; +export const LIST_ENTITY_FORM_ACTIONS = (entity: string) => { + return `${FORM_ACTION_CRUD_CONFIG.ENDPOINTS.LIST}/${entity}`; }; export const useIntegrationImplementationsList = (integration: string) => @@ -28,65 +27,62 @@ export const useIntegrationImplementationsList = (integration: string) => } ); -export function useDeleteActionInstanceMutation(entity: string) { - const apiMutateOptions = useApiMutateOptimisticOptions< - IActionInstance[], - string - >({ - dataQueryPath: LIST_ACTION_INSTANCES(entity), - otherEndpoints: [BASE_ACTIONS_ENDPOINT], - successMessage: ADMIN_ACTION_INSTANCES_CRUD_CONFIG.MUTATION_LANG.DELETE, - onMutate: MutationHelpers.deleteByKey("instanceId") as unknown as ( - oldData: IActionInstance[], - form: string - ) => IActionInstance[], - }); +export function useDeleteFormActionMutation(entity: string) { + const apiMutateOptions = useApiMutateOptimisticOptions( + { + dataQueryPath: LIST_ENTITY_FORM_ACTIONS(entity), + otherEndpoints: [LIST_ENTITY_FORM_ACTIONS(entity)], + successMessage: FORM_ACTION_CRUD_CONFIG.MUTATION_LANG.DELETE, + onMutate: MutationHelpers.deleteByKey("id") as unknown as ( + oldData: IFormAction[], + form: string + ) => IFormAction[], + } + ); return useMutation( - async (instanceId: string) => + async (formActionId: string) => await makeActionRequest( "DELETE", - ADMIN_ACTION_INSTANCES_CRUD_CONFIG.ENDPOINTS.DELETE(instanceId) + FORM_ACTION_CRUD_CONFIG.ENDPOINTS.DELETE(formActionId) ), apiMutateOptions ); } -export function useCreateActionInstanceMutation() { +export function useCreateFormActionMutation() { const apiMutateOptions = useWaitForResponseMutationOptions< Record >({ - endpoints: [BASE_ACTIONS_ENDPOINT], - successMessage: ADMIN_ACTION_INSTANCES_CRUD_CONFIG.MUTATION_LANG.CREATE, + endpoints: [FORM_ACTION_CRUD_CONFIG.ENDPOINTS.LIST], + successMessage: FORM_ACTION_CRUD_CONFIG.MUTATION_LANG.CREATE, }); return useMutation( - async (configuration: IActionInstance) => + async (configuration: IFormAction) => await makeActionRequest( "POST", - ADMIN_ACTION_INSTANCES_CRUD_CONFIG.ENDPOINTS.CREATE, + FORM_ACTION_CRUD_CONFIG.ENDPOINTS.CREATE, configuration ), apiMutateOptions ); } -export function useUpdateActionInstanceMutation() { +export function useUpdateFormActionMutation() { const apiMutateOptions = useWaitForResponseMutationOptions< Record >({ - endpoints: [BASE_ACTIONS_ENDPOINT], - successMessage: ADMIN_ACTION_INSTANCES_CRUD_CONFIG.MUTATION_LANG.EDIT, + endpoints: [FORM_ACTION_CRUD_CONFIG.ENDPOINTS.LIST], + successMessage: FORM_ACTION_CRUD_CONFIG.MUTATION_LANG.EDIT, }); return useMutation( - async (configuration: IActionInstance) => + async (formAction: IFormAction) => await makeActionRequest( "PATCH", - ADMIN_ACTION_INSTANCES_CRUD_CONFIG.ENDPOINTS.UPDATE( - configuration.instanceId - ), - configuration + FORM_ACTION_CRUD_CONFIG.ENDPOINTS.UPDATE(formAction.id), + formAction ), apiMutateOptions ); diff --git a/src/frontend/views/entity/Actions/index.tsx b/src/frontend/views/entity/Actions/index.tsx index 5af10ebbb..4a5f212ac 100644 --- a/src/frontend/views/entity/Actions/index.tsx +++ b/src/frontend/views/entity/Actions/index.tsx @@ -7,26 +7,26 @@ import { SectionBox } from "frontend/design-system/components/Section/SectionBox import { useDocumentationActionButton } from "frontend/docs/constants"; import { BaseEntitySettingsLayout } from "../_Base"; import { ENTITY_CONFIGURATION_VIEW } from "../constants"; -import { BaseActionInstances } from "./Base"; -import { ADMIN_ACTION_INSTANCES_CRUD_CONFIG } from "./constants"; +import { FormActions } from "./Base"; +import { FORM_ACTION_CRUD_CONFIG } from "./constants"; export function EntityFormActionsSettings() { const entity = useEntitySlug(); useSetPageDetails({ - pageTitle: ADMIN_ACTION_INSTANCES_CRUD_CONFIG.TEXT_LANG.TITLE, + pageTitle: FORM_ACTION_CRUD_CONFIG.TEXT_LANG.TITLE, viewKey: ENTITY_CONFIGURATION_VIEW, permission: USER_PERMISSIONS.CAN_CONFIGURE_APP, }); const documentationActionButton = useDocumentationActionButton( - ADMIN_ACTION_INSTANCES_CRUD_CONFIG.TEXT_LANG.TITLE + FORM_ACTION_CRUD_CONFIG.TEXT_LANG.TITLE ); return ( - + diff --git a/src/frontend/views/entity/_Base.tsx b/src/frontend/views/entity/_Base.tsx index 26c90b35f..6dd71fb47 100644 --- a/src/frontend/views/entity/_Base.tsx +++ b/src/frontend/views/entity/_Base.tsx @@ -12,7 +12,7 @@ import { import { ContentLayout } from "frontend/design-system/components/Section/SectionDivider"; import { Spacer } from "frontend/design-system/primitives/Spacer"; import { IDropDownMenuItem } from "frontend/design-system/components/DropdownMenu"; -import { ADMIN_ACTION_INSTANCES_CRUD_CONFIG } from "./Actions/constants"; +import { FORM_ACTION_CRUD_CONFIG } from "./Actions/constants"; import { ENTITY_CRUD_LABELS, ENTITY_FIELD_SETTINGS_TAB_LABELS, @@ -68,7 +68,7 @@ const baseMenuItems = (entity: string): IMenuSectionItem[] => [ }, { action: NAVIGATION_LINKS.ENTITY.CONFIG.FORM_INTEGRATIONS(entity), - name: ADMIN_ACTION_INSTANCES_CRUD_CONFIG.TEXT_LANG.TITLE, + name: FORM_ACTION_CRUD_CONFIG.TEXT_LANG.TITLE, systemIcon: "Zap", order: 80, }, diff --git a/src/frontend/views/integrations/actions/View/Deactivate.tsx b/src/frontend/views/integrations/actions/View/Deactivate.tsx index 17e22337b..b80c80583 100644 --- a/src/frontend/views/integrations/actions/View/Deactivate.tsx +++ b/src/frontend/views/integrations/actions/View/Deactivate.tsx @@ -28,8 +28,8 @@ export function Deactivate({ integrationDetail, activationId }: IProps) { return ( <> - Deactivating an action will irrevocabily delete its configurations and - remove all its instances + Deactivating an integration will irrevocabily delete its configurations + and remove all its form actions { - return await actionsApiService.listActivatedIntegrations(); + return await integrationsApiService.listActivatedIntegrations(); }, }); diff --git a/src/pages/api/integrations/actions/list.ts b/src/pages/api/integrations/actions/list.ts index 3e7952ea3..d0cd8b985 100644 --- a/src/pages/api/integrations/actions/list.ts +++ b/src/pages/api/integrations/actions/list.ts @@ -1,8 +1,8 @@ -import { actionsApiService } from "backend/actions/actions.service"; +import { integrationsApiService } from "backend/integrations/integrations.service"; import { requestHandler } from "backend/lib/request"; export default requestHandler({ GET: () => { - return actionsApiService.listActionIntegrations(); + return integrationsApiService.listActionIntegrations(); }, }); diff --git a/src/shared/constants/Icons.tsx b/src/shared/constants/Icons.tsx index e5dcc6ffc..af63e2152 100644 --- a/src/shared/constants/Icons.tsx +++ b/src/shared/constants/Icons.tsx @@ -99,7 +99,7 @@ export const systemIconToSVG = (icon: string, strokeWidth = 2) => { return icon; } - const svgProps = `fill="none" stroke-linejoin="round" stroke-linecap="round" stroke-width="${strokeWidth}" stroke="currentColor" `; + const svgProps = `fill="none" stroke-linejoin="round" stroke-linecap="round" stroke-width="${strokeWidth}" stroke="currentColor"`; iconPath = iconPath.replaceAll(`