fix: CB-780 connection form close confirmation

This commit is contained in:
Wroud
2021-04-21 17:48:45 +03:00
parent 6308111fbd
commit fbccdf754c
7 changed files with 97 additions and 18 deletions
@@ -8,8 +8,9 @@
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import type { IExecutionContextProvider } from '@cloudbeaver/core-executor';
import { isPropertiesEqual } from '@cloudbeaver/core-utils';
import { isObjectPropertyInfoStateEqual } from '@cloudbeaver/core-sdk';
import { DBDriverResource } from '../../DBDriverResource';
import { connectionConfigContext } from '../connectionConfigContext';
import { IConnectionFormSubmitData, ConnectionFormService, IConnectionFormState } from '../ConnectionFormService';
import { connectionFormStateContext } from '../connectionFormStateContext';
@@ -18,7 +19,8 @@ import { DriverProperties } from './DriverProperties';
@injectable()
export class ConnectionDriverPropertiesTabService extends Bootstrap {
constructor(
private readonly connectionFormService: ConnectionFormService
private readonly connectionFormService: ConnectionFormService,
private readonly dbDriverResource: DBDriverResource,
) {
super();
}
@@ -54,15 +56,21 @@ export class ConnectionDriverPropertiesTabService extends Bootstrap {
) {
const config = contexts.getContext(connectionConfigContext);
config.properties = state.config.properties;
config.properties = { ...state.config.properties };
}
private formState(
private async formState(
data: IConnectionFormState,
contexts: IExecutionContextProvider<IConnectionFormState>
) {
if (!data.info || !data.config.driverId) {
return;
}
const config = contexts.getContext(connectionConfigContext);
if (!isPropertiesEqual(config.properties, data.info?.properties)) {
const driver = await this.dbDriverResource.load(data.config.driverId, ['includeDriverProperties']);
if (!isObjectPropertyInfoStateEqual(driver.driverProperties, config.properties, data.info.properties)) {
const stateContext = contexts.getContext(connectionFormStateContext);
stateContext.markEdited();
@@ -8,8 +8,8 @@
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import type { IExecutionContextProvider } from '@cloudbeaver/core-executor';
import type { ObjectPropertyInfo } from '@cloudbeaver/core-sdk';
import { isPropertiesEqual } from '@cloudbeaver/core-utils';
import { isObjectPropertyInfoStateEqual, ObjectPropertyInfo } from '@cloudbeaver/core-sdk';
import { isValuesEqual } from '@cloudbeaver/core-utils';
import { ConnectionsResource, DatabaseConnection } from '../../Administration/ConnectionsResource';
import { ConnectionInfoResource } from '../../ConnectionInfoResource';
@@ -208,22 +208,27 @@ export class ConnectionOptionsTabService extends Bootstrap {
const config = contexts.getContext(connectionConfigContext);
const stateContext = contexts.getContext(connectionFormStateContext);
const driver = await this.dbDriverResource.load(data.config.driverId!, ['includeProviderProperties']);
if (
config.name !== data.info.name
|| config.description !== data.info.description
|| config.template !== data.info.template
|| config.driverId !== data.info.driverId
|| (config.url !== undefined && config.url !== data.info.url)
|| (config.host !== undefined && config.host !== data.info.host)
|| (config.port !== undefined && config.port !== data.info.port)
|| (config.databaseName !== undefined && config.databaseName !== data.info.databaseName)
!isValuesEqual(config.name, data.info.name, '')
|| !isValuesEqual(config.description, data.info.description, '')
|| !isValuesEqual(config.template, data.info.template, true)
|| !isValuesEqual(config.driverId, data.info.driverId, '')
|| (config.url !== undefined && !isValuesEqual(config.url, data.info.url, ''))
|| (config.host !== undefined && !isValuesEqual(config.host, data.info.host, ''))
|| (config.port !== undefined && !isValuesEqual(config.port, data.info.port, ''))
|| (config.databaseName !== undefined && !isValuesEqual(config.databaseName, data.info.databaseName, ''))
|| config.credentials !== undefined
|| (config.authModelId !== undefined && config.authModelId !== data.info.authModel)
|| (config.authModelId !== undefined && !isValuesEqual(config.authModelId, data.info.authModel, ''))
|| (config.saveCredentials !== undefined && config.saveCredentials !== data.info.saveCredentials)
|| (
config.providerProperties !== undefined
&& !isPropertiesEqual(config.providerProperties, data.info.providerProperties)
&& !isObjectPropertyInfoStateEqual(
driver.providerProperties,
config.providerProperties,
data.info.providerProperties
)
)
) {
stateContext.markEdited();
+1
View File
@@ -11,5 +11,6 @@ export * from './getErrorDetails';
export * from './GQLError';
export * from './GQLErrorCatcher';
export * from './GraphQLService';
export * from './isObjectPropertyInfoStateEqual';
export * from './sdk';
export * from './ServerInternalError';
@@ -0,0 +1,49 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2021 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { isValuesEqual } from '@cloudbeaver/core-utils';
import type { ObjectPropertyInfo } from './sdk';
type RequiredObjectPropertyInfoFields = Pick<ObjectPropertyInfo, 'id' | 'defaultValue'>;
export function isObjectPropertyInfoStateEqual<T>(
properties: RequiredObjectPropertyInfoFields[],
first: T,
second: T
): boolean {
if (
first === null
|| second === null
|| typeof first !== 'object'
|| typeof second !== 'object'
) {
return false;
}
const customKeys = [...Object.keys(first), ...Object.keys(second)]
.filter(key => !properties.some(property => key === property.id));
for (const property of properties) {
if (!property.id) {
continue;
}
if (!isValuesEqual(first[property.id as keyof T], second[property.id as keyof T], property.defaultValue)) {
return false;
}
}
for (const key of customKeys) {
if (first[key as keyof T] !== second[key as keyof T]) {
return false;
}
}
return true;
}
+1
View File
@@ -7,6 +7,7 @@ export * from './uuid_';
export * from './generateFileName';
export * from './isArraysEqual';
export * from './isPropertiesEqual';
export * from './isValuesEqual';
export * from './md5';
export * from './TextTools';
export * from './copyToClipboard';
@@ -0,0 +1,15 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2021 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
export function isValuesEqual<T extends string | boolean | number>(
first: T | null | undefined,
second: T | null | undefined,
defaultValue?: T
): boolean {
return (first ?? defaultValue) === (second ?? defaultValue);
}
@@ -59,7 +59,7 @@ const PublicConnectionFormRenderer: React.FC<Props> = observer(function PublicCo
export const PublicConnectionForm: React.FC = observer(function PublicConnectionForm() {
const service = useService(PublicConnectionFormService);
const close = useCallback(() => service.close(), []);
const close = useCallback(() => service.close(true), []);
const save = useCallback(() => service.close(true), []);
return styled(styles)(