diff --git a/packages/backend-core/src/events/processors/posthog/PosthogProcessor.ts b/packages/backend-core/src/events/processors/posthog/PosthogProcessor.ts index 12d2bb7e2c..6c45da09e6 100644 --- a/packages/backend-core/src/events/processors/posthog/PosthogProcessor.ts +++ b/packages/backend-core/src/events/processors/posthog/PosthogProcessor.ts @@ -13,9 +13,7 @@ const EXCLUDED_EVENTS: Event[] = [ Event.ROLE_UPDATED, Event.DATASOURCE_UPDATED, Event.QUERY_UPDATED, - Event.TABLE_UPDATED, Event.VIEW_UPDATED, - Event.VIEW_FILTER_UPDATED, Event.VIEW_CALCULATION_UPDATED, Event.AUTOMATION_TRIGGER_UPDATED, Event.USER_GROUP_UPDATED, diff --git a/packages/backend-core/src/events/publishers/index.ts b/packages/backend-core/src/events/publishers/index.ts index 9c92b80499..aaec62f979 100644 --- a/packages/backend-core/src/events/publishers/index.ts +++ b/packages/backend-core/src/events/publishers/index.ts @@ -23,3 +23,4 @@ export { default as plugin } from "./plugin" export { default as backup } from "./backup" export { default as environmentVariable } from "./environmentVariable" export { default as auditLog } from "./auditLog" +export { default as rowAction } from "./rowAction" diff --git a/packages/backend-core/src/events/publishers/rowAction.ts b/packages/backend-core/src/events/publishers/rowAction.ts new file mode 100644 index 0000000000..eac35cc489 --- /dev/null +++ b/packages/backend-core/src/events/publishers/rowAction.ts @@ -0,0 +1,13 @@ +import { publishEvent } from "../events" +import { Event, RowActionCreatedEvent } from "@budibase/types" + +async function created( + rowAction: RowActionCreatedEvent, + timestamp?: string | number +) { + await publishEvent(Event.ROW_ACTION_CREATED, rowAction, timestamp) +} + +export default { + created, +} diff --git a/packages/backend-core/src/events/publishers/table.ts b/packages/backend-core/src/events/publishers/table.ts index dc3200291a..77a2c3e1a4 100644 --- a/packages/backend-core/src/events/publishers/table.ts +++ b/packages/backend-core/src/events/publishers/table.ts @@ -1,13 +1,14 @@ import { publishEvent } from "../events" import { Event, - TableExportFormat, + FieldType, Table, TableCreatedEvent, - TableUpdatedEvent, TableDeletedEvent, TableExportedEvent, + TableExportFormat, TableImportedEvent, + TableUpdatedEvent, } from "@budibase/types" async function created(table: Table, timestamp?: string | number) { @@ -20,14 +21,34 @@ async function created(table: Table, timestamp?: string | number) { await publishEvent(Event.TABLE_CREATED, properties, timestamp) } -async function updated(table: Table) { +async function updated(oldTable: Table, newTable: Table) { + // only publish the event if it has fields we are interested in + let defaultValues, aiColumn + + // check that new fields have been added + for (const key in newTable.schema) { + if (!oldTable.schema[key]) { + const newColumn = newTable.schema[key] + if ("default" in newColumn && newColumn.default != null) { + defaultValues = true + } + if (newColumn.type === FieldType.AI) { + aiColumn = newColumn.operation + } + } + } + const properties: TableUpdatedEvent = { - tableId: table._id as string, + tableId: newTable._id as string, + defaultValues, + aiColumn, audited: { - name: table.name, + name: newTable.name, }, } - await publishEvent(Event.TABLE_UPDATED, properties) + if (defaultValues || aiColumn) { + await publishEvent(Event.TABLE_UPDATED, properties) + } } async function deleted(table: Table) { diff --git a/packages/backend-core/src/events/publishers/view.ts b/packages/backend-core/src/events/publishers/view.ts index 9cc4138ca0..503b011373 100644 --- a/packages/backend-core/src/events/publishers/view.ts +++ b/packages/backend-core/src/events/publishers/view.ts @@ -1,6 +1,11 @@ import { publishEvent } from "../events" import { + CalculationType, Event, + Table, + TableExportFormat, + View, + ViewCalculation, ViewCalculationCreatedEvent, ViewCalculationDeletedEvent, ViewCalculationUpdatedEvent, @@ -11,20 +16,20 @@ import { ViewFilterDeletedEvent, ViewFilterUpdatedEvent, ViewUpdatedEvent, - View, - ViewCalculation, - Table, - TableExportFormat, + ViewV2, + ViewJoinCreatedEvent, } from "@budibase/types" -async function created(view: View, timestamp?: string | number) { +async function created(view: ViewV2, timestamp?: string | number) { const properties: ViewCreatedEvent = { + name: view.name, + type: view.type, tableId: view.tableId, } await publishEvent(Event.VIEW_CREATED, properties, timestamp) } -async function updated(view: View) { +async function updated(view: ViewV2) { const properties: ViewUpdatedEvent = { tableId: view.tableId, } @@ -46,16 +51,27 @@ async function exported(table: Table, format: TableExportFormat) { await publishEvent(Event.VIEW_EXPORTED, properties) } -async function filterCreated(view: View, timestamp?: string | number) { +async function filterCreated( + { tableId, filterGroups }: { tableId: string; filterGroups: number }, + timestamp?: string | number +) { const properties: ViewFilterCreatedEvent = { - tableId: view.tableId, + tableId, + filterGroups, } await publishEvent(Event.VIEW_FILTER_CREATED, properties, timestamp) } -async function filterUpdated(view: View) { +async function filterUpdated({ + tableId, + filterGroups, +}: { + tableId: string + filterGroups: number +}) { const properties: ViewFilterUpdatedEvent = { - tableId: view.tableId, + tableId: tableId, + filterGroups, } await publishEvent(Event.VIEW_FILTER_UPDATED, properties) } @@ -67,10 +83,16 @@ async function filterDeleted(view: View) { await publishEvent(Event.VIEW_FILTER_DELETED, properties) } -async function calculationCreated(view: View, timestamp?: string | number) { +async function calculationCreated( + { + tableId, + calculationType, + }: { tableId: string; calculationType: CalculationType }, + timestamp?: string | number +) { const properties: ViewCalculationCreatedEvent = { - tableId: view.tableId, - calculation: view.calculation as ViewCalculation, + tableId, + calculation: calculationType, } await publishEvent(Event.VIEW_CALCULATION_CREATED, properties, timestamp) } @@ -91,6 +113,13 @@ async function calculationDeleted(existingView: View) { await publishEvent(Event.VIEW_CALCULATION_DELETED, properties) } +async function viewJoinCreated(tableId: any, timestamp?: string | number) { + const properties: ViewJoinCreatedEvent = { + tableId, + } + await publishEvent(Event.VIEW_JOIN_CREATED, properties, timestamp) +} + export default { created, updated, @@ -102,4 +131,5 @@ export default { calculationCreated, calculationUpdated, calculationDeleted, + viewJoinCreated, } diff --git a/packages/backend-core/tests/core/utilities/mocks/events.ts b/packages/backend-core/tests/core/utilities/mocks/events.ts index 96f351de10..433986352e 100644 --- a/packages/backend-core/tests/core/utilities/mocks/events.ts +++ b/packages/backend-core/tests/core/utilities/mocks/events.ts @@ -117,6 +117,7 @@ beforeAll(async () => { jest.spyOn(events.view, "calculationCreated") jest.spyOn(events.view, "calculationUpdated") jest.spyOn(events.view, "calculationDeleted") + jest.spyOn(events.view, "viewJoinCreated") jest.spyOn(events.plugin, "init") jest.spyOn(events.plugin, "imported") diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/TestDataModal.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/TestDataModal.svelte index 5ec66870a8..eebd977e6c 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/TestDataModal.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/TestDataModal.svelte @@ -46,7 +46,7 @@ } } else { // Leave the core data as it is - return testData + return cloneDeep(testData) } } @@ -63,7 +63,10 @@ return true } - $: testData = testData || parseTestData($selectedAutomation.data.testData) + $: currentTestData = $selectedAutomation.data.testData + + // Can be updated locally to avoid race condition when testing + $: testData = parseTestData(currentTestData) $: { // clone the trigger so we're not mutating the reference @@ -85,7 +88,7 @@ required => testData?.[required] || required !== "row" ) - function parseTestJSON(e) { + async function parseTestJSON(e) { let jsonUpdate try { @@ -105,7 +108,9 @@ } } - automationStore.actions.addTestDataToAutomation(jsonUpdate) + const updatedAuto = + automationStore.actions.addTestDataToAutomation(jsonUpdate) + await automationStore.actions.save(updatedAuto) } const testAutomation = async () => { @@ -150,10 +155,14 @@ {#if selectedValues}
{ + const { testData: updatedTestData } = e.detail + testData = updatedTestData + }} />
{/if} @@ -162,7 +171,7 @@