From 19566d9b7d7f6517075cae8f1749e546d0693ab9 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 23 Feb 2021 14:07:19 +0000 Subject: [PATCH 1/3] Add new automation trigger for updating rows --- packages/server/src/api/controllers/row.js | 1 - packages/server/src/automations/triggers.js | 55 +++++++++++++++++++-- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/packages/server/src/api/controllers/row.js b/packages/server/src/api/controllers/row.js index 43d831dc60..54f4e4508e 100644 --- a/packages/server/src/api/controllers/row.js +++ b/packages/server/src/api/controllers/row.js @@ -111,7 +111,6 @@ exports.patch = async function(ctx) { } row._rev = response.rev row.type = "row" - ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:update`, appId, row, table) ctx.body = row ctx.status = 200 diff --git a/packages/server/src/automations/triggers.js b/packages/server/src/automations/triggers.js index e4c91e5610..fcdb8a7e83 100644 --- a/packages/server/src/automations/triggers.js +++ b/packages/server/src/automations/triggers.js @@ -13,11 +13,11 @@ const FAKE_DATETIME = "1970-01-01T00:00:00.000Z" const BUILTIN_DEFINITIONS = { ROW_SAVED: { - name: "Row Saved", + name: "Row Created", event: "row:save", icon: "ri-save-line", tagline: "Row is added to {{inputs.enriched.table.name}}", - description: "Fired when a row is saved to your database", + description: "Fired when a row is added to your database", stepId: "ROW_SAVED", inputs: {}, schema: { @@ -36,7 +36,47 @@ const BUILTIN_DEFINITIONS = { row: { type: "object", customType: "row", - description: "The new row that was saved", + description: "The new row that was created", + }, + id: { + type: "string", + description: "Row ID - can be used for updating", + }, + revision: { + type: "string", + description: "Revision of row", + }, + }, + required: ["row", "id"], + }, + }, + type: "TRIGGER", + }, + ROW_UPDATED: { + name: "Row Updated", + event: "row:update", + icon: "ri-save-line", + tagline: "Row is updated in {{inputs.enriched.table.name}}", + description: "Fired when a row is updated in your database", + stepId: "ROW_UPDATED", + inputs: {}, + schema: { + inputs: { + properties: { + tableId: { + type: "string", + customType: "table", + title: "Table", + }, + }, + required: ["tableId"], + }, + outputs: { + properties: { + row: { + type: "object", + customType: "row", + description: "The row that was updated", }, id: { type: "string", @@ -79,7 +119,7 @@ const BUILTIN_DEFINITIONS = { description: "The row that was deleted", }, }, - required: ["row", "id"], + required: ["row"], }, }, type: "TRIGGER", @@ -191,6 +231,13 @@ emitter.on("row:save", async function(event) { await queueRelevantRowAutomations(event, "row:save") }) +emitter.on("row:update", async function(event) { + if (!event || !event.row || !event.row.tableId) { + return + } + await queueRelevantRowAutomations(event, "row:update") +}) + emitter.on("row:delete", async function(event) { if (!event || !event.row || !event.row.tableId) { return From c47ef73a4a97948608312d5d8b15bd7fa2867ae7 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 23 Feb 2021 14:16:44 +0000 Subject: [PATCH 2/3] Update icon for row updated trigger --- packages/server/src/automations/triggers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/automations/triggers.js b/packages/server/src/automations/triggers.js index fcdb8a7e83..73ce9edeed 100644 --- a/packages/server/src/automations/triggers.js +++ b/packages/server/src/automations/triggers.js @@ -55,7 +55,7 @@ const BUILTIN_DEFINITIONS = { ROW_UPDATED: { name: "Row Updated", event: "row:update", - icon: "ri-save-line", + icon: "ri-refresh-line", tagline: "Row is updated in {{inputs.enriched.table.name}}", description: "Fired when a row is updated in your database", stepId: "ROW_UPDATED", From 2f78afac6d8d33264a7167aac083693777219199 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 23 Feb 2021 14:28:05 +0000 Subject: [PATCH 3/3] Fix cypress test --- .../integration/createAutomation.spec.js | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/builder/cypress/integration/createAutomation.spec.js b/packages/builder/cypress/integration/createAutomation.spec.js index 92d1f907bd..efc185be7c 100644 --- a/packages/builder/cypress/integration/createAutomation.spec.js +++ b/packages/builder/cypress/integration/createAutomation.spec.js @@ -17,23 +17,33 @@ context("Create a automation", () => { cy.get("[data-cy=new-automation]").click() cy.get(".modal").within(() => { cy.get("input").type("Add Row") - cy.get(".buttons").contains("Create").click() + cy.get(".buttons") + .contains("Create") + .click() }) // Add trigger cy.contains("Trigger").click() - cy.contains("Row Saved").click() + cy.contains("Row Created").click() cy.get(".setup").within(() => { - cy.get("select").first().select("dog") + cy.get("select") + .first() + .select("dog") }) // Create action cy.contains("Action").click() cy.contains("Create Row").click() cy.get(".setup").within(() => { - cy.get("select").first().select("dog") - cy.get("input").first().type("goodboy") - cy.get("input").eq(1).type("11") + cy.get("select") + .first() + .select("dog") + cy.get("input") + .first() + .type("goodboy") + cy.get("input") + .eq(1) + .type("11") }) // Save