From cf80ce20c0ba797a83fbb6c50f6ee8b66c36906d Mon Sep 17 00:00:00 2001 From: Wroud Date: Mon, 7 Sep 2020 13:05:39 +0300 Subject: [PATCH] fix(core-connections): connection mutation while editing CB-257 --- .../ConnectionEditController.ts | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/webapp/packages/core-connections/src/Administration/Connections/ConnectionsTable/ConnectionEditController.ts b/webapp/packages/core-connections/src/Administration/Connections/ConnectionsTable/ConnectionEditController.ts index 715eb636b1..c3b39069b3 100644 --- a/webapp/packages/core-connections/src/Administration/Connections/ConnectionsTable/ConnectionEditController.ts +++ b/webapp/packages/core-connections/src/Administration/Connections/ConnectionsTable/ConnectionEditController.ts @@ -11,10 +11,8 @@ import { observable, computed } from 'mobx'; import { injectable, IInitializableController, IDestructibleController } from '@cloudbeaver/core-di'; -import { CommonDialogService } from '@cloudbeaver/core-dialogs'; import { NotificationService } from '@cloudbeaver/core-events'; -import { ErrorDetailsDialog } from '@cloudbeaver/core-notifications'; -import { GQLErrorCatcher, AdminConnectionGrantInfo } from '@cloudbeaver/core-sdk'; +import { GQLErrorCatcher, AdminConnectionGrantInfo, ConnectionInfo } from '@cloudbeaver/core-sdk'; import { DBDriverResource } from '../../../DBDriverResource'; import { ConnectionsResource } from '../../ConnectionsResource'; @@ -25,6 +23,7 @@ implements IInitializableController, IDestructibleController { @observable grantedSubjects: AdminConnectionGrantInfo[] | null = null; @observable isLoading = true; @observable credentials: Record = {}; + @observable connection: ConnectionInfo | null = null; @computed get isDisabled() { return this.isLoading; @@ -37,10 +36,6 @@ implements IInitializableController, IDestructibleController { return this.dbDriverResource.get(this.connection.driverId) || null; } - @computed get connection() { - return this.connectionsResource.get(this.connectionId); - } - @computed get availableDrivers() { if (!this.connection) { return []; @@ -52,12 +47,10 @@ implements IInitializableController, IDestructibleController { readonly editing = true; // used as model IConnectionFormModel readonly error = new GQLErrorCatcher(); - private isDistructed = false; constructor( private connectionsResource: ConnectionsResource, private notificationService: NotificationService, - private commonDialogService: CommonDialogService, private dbDriverResource: DBDriverResource, ) { } @@ -67,25 +60,13 @@ implements IInitializableController, IDestructibleController { } destruct(): void { - this.isDistructed = true; - } - - onShowDetails = () => { - if (this.error.exception) { - this.commonDialogService.open(ErrorDetailsDialog, this.error.exception); - } - } - - private showError(exception: Error, message: string) { - if (!this.error.catch(exception) || this.isDistructed) { - this.notificationService.logException(exception, message); - } } private async loadConnectionInfo() { this.isLoading = true; try { - await this.connectionsResource.load(this.connectionId); + // we create a copy to protect the current value from mutation + this.connection = JSON.parse(JSON.stringify(await this.connectionsResource.load(this.connectionId))); } catch (exception) { this.notificationService.logException(exception, `Can't load ConnectionInfo ${this.connectionId}`); } finally {