From 247122633a0966bcd2fc0233c259d7ae6ea2d8af Mon Sep 17 00:00:00 2001 From: Eric Tuvesson Date: Tue, 26 Mar 2024 22:05:21 +0100 Subject: [PATCH] feat: Cloud Services, allow changing all fields (#1) --- .../CloudServices/ExternalCloudService.ts | 8 +++-- .../editor/src/models/CloudServices/type.ts | 2 ++ .../CloudServiceModal/CloudSerivceModal.tsx | 29 +++++++++++++++---- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/packages/noodl-editor/src/editor/src/models/CloudServices/ExternalCloudService.ts b/packages/noodl-editor/src/editor/src/models/CloudServices/ExternalCloudService.ts index deb0a15..2b7a81f 100644 --- a/packages/noodl-editor/src/editor/src/models/CloudServices/ExternalCloudService.ts +++ b/packages/noodl-editor/src/editor/src/models/CloudServices/ExternalCloudService.ts @@ -52,9 +52,11 @@ export class ExternalCloudService { const broker = brokers.find((x) => x.id === options.id); if (!broker) return false; - if (options.name) broker.name = options.name; - if (options.description) broker.description = options.description; - if (options.masterKey) broker.masterKey = options.masterKey; + if (typeof options.name !== undefined) broker.name = options.name; + if (typeof options.description !== undefined) broker.description = options.description; + if (typeof options.appId !== undefined) broker.appId = options.appId; + if (typeof options.masterKey !== undefined) broker.masterKey = options.masterKey; + if (typeof options.url !== undefined) broker.endpoint = options.url; await JSONStorage.set('externalBrokers', { brokers }); diff --git a/packages/noodl-editor/src/editor/src/models/CloudServices/type.ts b/packages/noodl-editor/src/editor/src/models/CloudServices/type.ts index 7927c15..9cc7d16 100644 --- a/packages/noodl-editor/src/editor/src/models/CloudServices/type.ts +++ b/packages/noodl-editor/src/editor/src/models/CloudServices/type.ts @@ -14,7 +14,9 @@ export type UpdateEnvironmentRequest = { id: string; name: string | undefined; description: string | undefined; + appId: string | undefined; masterKey: string | undefined; + url: string | undefined; }; export type CreateEnvironment = { diff --git a/packages/noodl-editor/src/editor/src/views/panels/CloudServicePanel/CloudServiceModal/CloudSerivceModal.tsx b/packages/noodl-editor/src/editor/src/views/panels/CloudServicePanel/CloudServiceModal/CloudSerivceModal.tsx index 285958e..aae8e53 100644 --- a/packages/noodl-editor/src/editor/src/views/panels/CloudServicePanel/CloudServiceModal/CloudSerivceModal.tsx +++ b/packages/noodl-editor/src/editor/src/views/panels/CloudServicePanel/CloudServiceModal/CloudSerivceModal.tsx @@ -42,16 +42,31 @@ function AsSelfHosted({ }: CloudServiceModalProps) { const [name, setName] = useState(environment.name); const [description, setDescription] = useState(environment.description); + const [appId, setAppId] = useState(environment.appId); + const [url, setUrl] = useState(environment.url); const [showMasterKey, setShowMasterKey] = useState(false); const [masterKey, setMasterKey] = useState(environment.masterKey); function update() { + // Early return if none of the values changed + if ( + name === environment.name && + description === environment.description && + appId === environment.appId && + masterKey === environment.masterKey && + url === environment.url + ) { + return; + } + CloudService.instance.backend .update({ id: environment.id, name, description, - masterKey + appId, + masterKey, + url }) .then(() => { ToastLayer.showSuccess(`Updated Cloud Service`); @@ -86,12 +101,14 @@ function AsSelfHosted({ setAppId(e.target.value)} + onBlur={update} + onEnter={update} /> setUrl(e.target.value)} + onBlur={update} + onEnter={update} />