From db501fb10a21abf1bbbdaa21ba26197e67580286 Mon Sep 17 00:00:00 2001 From: Dean Date: Mon, 10 Jul 2023 09:30:15 +0100 Subject: [PATCH] Enabled collaboration behaviour in the automation section --- .../builderStore/store/automation/index.js | 36 +++++++++++++++++++ .../builder/src/builderStore/websocket.js | 12 ++++++- .../AutomationPanel/AutomationList.svelte | 9 +++-- .../AutomationPanel/AutomationPanel.svelte | 2 +- .../builder/app/[application]/_layout.svelte | 2 +- .../[application]/automation/_layout.svelte | 4 +++ .../server/src/api/controllers/automation.ts | 4 +++ packages/server/src/websockets/builder.ts | 15 ++++++++ packages/shared-core/src/constants.ts | 1 + 9 files changed, 79 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/builderStore/store/automation/index.js b/packages/builder/src/builderStore/store/automation/index.js index 9e5516c512..9f29f61803 100644 --- a/packages/builder/src/builderStore/store/automation/index.js +++ b/packages/builder/src/builderStore/store/automation/index.js @@ -3,6 +3,7 @@ import { API } from "api" import { cloneDeep } from "lodash/fp" import { generate } from "shortid" import { selectedAutomation } from "builderStore" +import { automationStore } from "builderStore" const initialAutomationState = { automations: [], @@ -248,4 +249,39 @@ const automationActions = store => ({ } await store.actions.save(newAutomation) }, + replace: async (automationId, automation) => { + if (!automationId) { + return + } + if (!automation) { + store.update(state => { + // Remove the automation + state.automations = state.automations.filter( + x => x._id !== automationId + ) + // Select a new automation if required + if (automationId === state.selectedAutomationId) { + store.actions.select(state.automations[0]?._id) + } + return state + }) + } else { + const index = get(store).automations.findIndex( + x => x._id === automation._id + ) + if (index === -1) { + // Automation addition + store.update(state => ({ + ...state, + automations: [...state.automations, automation], + })) + } else { + // Automation update + store.update(state => { + state.automations[index] = automation + return state + }) + } + } + }, }) diff --git a/packages/builder/src/builderStore/websocket.js b/packages/builder/src/builderStore/websocket.js index 87195bed25..6121831c38 100644 --- a/packages/builder/src/builderStore/websocket.js +++ b/packages/builder/src/builderStore/websocket.js @@ -1,5 +1,10 @@ import { createWebsocket } from "@budibase/frontend-core" -import { userStore, store, deploymentStore } from "builderStore" +import { + userStore, + store, + deploymentStore, + automationStore, +} from "builderStore" import { datasources, tables } from "stores/backend" import { get } from "svelte/store" import { auth } from "stores/portal" @@ -67,5 +72,10 @@ export const createBuilderWebsocket = appId => { } ) + // Automations + socket.onOther(BuilderSocketEvent.AutomationChange, ({ id, automation }) => { + automationStore.actions.replace(id, automation) + }) + return socket } diff --git a/packages/builder/src/components/automation/AutomationPanel/AutomationList.svelte b/packages/builder/src/components/automation/AutomationPanel/AutomationList.svelte index 80d65a5cb6..9620dfe86c 100644 --- a/packages/builder/src/components/automation/AutomationPanel/AutomationList.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/AutomationList.svelte @@ -1,6 +1,10 @@