From 4e1a593321efa312e0c414a615494b30e7829845 Mon Sep 17 00:00:00 2001 From: Alexey Date: Mon, 27 May 2024 23:45:21 +0800 Subject: [PATCH] CB-5139 domain manager improvements (#2645) * CB-5139 feat: domain manager improvements * CB-5139 feat: deployment address verification * CB-5139 refactor: use computed isDisabled in FormState --------- Co-authored-by: kseniaguzeeva <112612526+kseniaguzeeva@users.noreply.github.com> --- webapp/packages/core-blocks/src/locales/en.ts | 8 +++++++ webapp/packages/core-blocks/src/locales/it.ts | 8 +++++++ webapp/packages/core-blocks/src/locales/ru.ts | 8 +++++++ .../core-localization/src/locales/en.ts | 2 ++ .../core-localization/src/locales/it.ts | 2 ++ .../core-localization/src/locales/ru.ts | 2 ++ .../core-localization/src/locales/zh.ts | 2 ++ webapp/packages/core-ui/src/Form/FormPart.ts | 11 ++++++---- webapp/packages/core-ui/src/Form/FormState.ts | 21 +++++++++++-------- webapp/packages/core-ui/src/Form/IFormPart.ts | 1 - 10 files changed, 51 insertions(+), 14 deletions(-) diff --git a/webapp/packages/core-blocks/src/locales/en.ts b/webapp/packages/core-blocks/src/locales/en.ts index 9284a03de0..f3eea53f0f 100644 --- a/webapp/packages/core-blocks/src/locales/en.ts +++ b/webapp/packages/core-blocks/src/locales/en.ts @@ -1,8 +1,16 @@ +/* + * CloudBeaver - Cloud Database Manager + * Copyright (C) 2020-2024 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 default [ ['core_block_properties_table_name', 'Name'], ['core_block_properties_table_value', 'Value'], ['core_block_properties_table_filter_name', 'Filter'], ['core_block_properties_table_add', 'Add property'], + ['core_blocks_confirmation_dialog_title', 'Confirmation required'], ['core_blocks_properties_table_item_reset', 'Reset to default'], ['core_blocks_object_property_info_form_empty_placeholder', 'Properties empty'], ['core_blocks_object_property_info_password_saved', 'Field value is saved'], diff --git a/webapp/packages/core-blocks/src/locales/it.ts b/webapp/packages/core-blocks/src/locales/it.ts index 3109133d4a..df727c8735 100644 --- a/webapp/packages/core-blocks/src/locales/it.ts +++ b/webapp/packages/core-blocks/src/locales/it.ts @@ -1,7 +1,15 @@ +/* + * CloudBeaver - Cloud Database Manager + * Copyright (C) 2020-2024 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 default [ ['core_block_properties_table_name', 'Nome'], ['core_block_properties_table_value', 'Valore'], ['core_block_properties_table_add', 'Aggiungi proprietà'], + ['core_blocks_confirmation_dialog_title', 'Confirmation required'], ['core_blocks_properties_table_item_reset', 'Reset to default'], ['core_blocks_object_property_info_form_empty_placeholder', 'Properties empty'], ['core_blocks_properties_table_item_remove', 'Remove property'], diff --git a/webapp/packages/core-blocks/src/locales/ru.ts b/webapp/packages/core-blocks/src/locales/ru.ts index 4e183fa4b3..49965cd5a9 100644 --- a/webapp/packages/core-blocks/src/locales/ru.ts +++ b/webapp/packages/core-blocks/src/locales/ru.ts @@ -1,8 +1,16 @@ +/* + * CloudBeaver - Cloud Database Manager + * Copyright (C) 2020-2024 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 default [ ['core_block_properties_table_name', 'Название'], ['core_block_properties_table_value', 'Значение'], ['core_block_properties_table_filter_name', 'Фильтр'], ['core_block_properties_table_add', 'Добавить параметр'], + ['core_blocks_confirmation_dialog_title', 'Требуется подтверждение'], ['core_blocks_properties_table_item_reset', 'Вернуть дефолтное значение'], ['core_blocks_object_property_info_form_empty_placeholder', 'Параметры отсутствуют'], ['core_blocks_properties_table_item_remove', 'Удалить параметр'], diff --git a/webapp/packages/core-localization/src/locales/en.ts b/webapp/packages/core-localization/src/locales/en.ts index 16abffab17..aedb81da43 100644 --- a/webapp/packages/core-localization/src/locales/en.ts +++ b/webapp/packages/core-localization/src/locales/en.ts @@ -24,6 +24,8 @@ export default [ ['ui_processing_ok', 'Ok'], ['ui_processing_create', 'Create'], ['ui_processing_save', 'Save'], + ['ui_processing_saving', 'Saving...'], + ['ui_processing_do_you_want_to_proceed', 'Do you want to proceed?'], ['ui_processing_saved', 'Saved'], ['ui_processing_stop', 'Stop'], ['ui_processing_skip', 'Skip'], diff --git a/webapp/packages/core-localization/src/locales/it.ts b/webapp/packages/core-localization/src/locales/it.ts index b11450c90d..ae1c482cb0 100644 --- a/webapp/packages/core-localization/src/locales/it.ts +++ b/webapp/packages/core-localization/src/locales/it.ts @@ -23,6 +23,8 @@ export default [ ['ui_processing_ok', 'Ok'], ['ui_processing_create', 'Crea'], ['ui_processing_save', 'Salva'], + ['ui_processing_saving', 'Saving...'], + ['ui_processing_do_you_want_to_proceed', 'Do you want to proceed?'], ['ui_processing_saved', 'Saved'], ['ui_processing_stop', 'Stop'], ['ui_processing_skip', 'Skip'], diff --git a/webapp/packages/core-localization/src/locales/ru.ts b/webapp/packages/core-localization/src/locales/ru.ts index ce1eff2a27..493917324e 100644 --- a/webapp/packages/core-localization/src/locales/ru.ts +++ b/webapp/packages/core-localization/src/locales/ru.ts @@ -22,6 +22,8 @@ export default [ ['ui_processing_ok', 'Принять'], ['ui_processing_create', 'Создать'], ['ui_processing_save', 'Сохранить'], + ['ui_processing_saving', 'Сохранение...'], + ['ui_processing_do_you_want_to_proceed', 'Хотите продолжить?'], ['ui_processing_saved', 'Сохранено'], ['ui_processing_stop', 'Остановить'], ['ui_processing_skip', 'Пропустить'], diff --git a/webapp/packages/core-localization/src/locales/zh.ts b/webapp/packages/core-localization/src/locales/zh.ts index c7835f0808..cb171094ad 100644 --- a/webapp/packages/core-localization/src/locales/zh.ts +++ b/webapp/packages/core-localization/src/locales/zh.ts @@ -23,6 +23,8 @@ export default [ ['ui_processing_ok', '好'], ['ui_processing_create', '创建'], ['ui_processing_save', '保存'], + ['ui_processing_saving', 'Saving...'], + ['ui_processing_do_you_want_to_proceed', 'Do you want to proceed?'], ['ui_processing_saved', 'Saved'], ['ui_processing_stop', 'Stop'], ['ui_processing_skip', 'Skip'], diff --git a/webapp/packages/core-ui/src/Form/FormPart.ts b/webapp/packages/core-ui/src/Form/FormPart.ts index 9329d0a527..2dcf2063d7 100644 --- a/webapp/packages/core-ui/src/Form/FormPart.ts +++ b/webapp/packages/core-ui/src/Form/FormPart.ts @@ -7,7 +7,7 @@ */ import { action, makeObservable, observable, toJS } from 'mobx'; -import { executorHandlerFilter, type IExecutionContextProvider } from '@cloudbeaver/core-executor'; +import { executorHandlerFilter, ExecutorInterrupter, type IExecutionContextProvider } from '@cloudbeaver/core-executor'; import { isObjectsEqual } from '@cloudbeaver/core-utils'; import type { IFormPart } from './IFormPart'; @@ -76,7 +76,7 @@ export abstract class FormPart implements IFormPar return !isObjectsEqual(this.initialState, this.state); } - async save(): Promise { + async save(data: IFormState, contexts: IExecutionContextProvider>): Promise { if (this.loading) { return; } @@ -89,7 +89,10 @@ export abstract class FormPart implements IFormPar return; } - await this.saveChanges(); + await this.saveChanges(data, contexts); + if (ExecutorInterrupter.isInterrupted(contexts)) { + return; + } this.loaded = false; this.exception = null; @@ -149,5 +152,5 @@ export abstract class FormPart implements IFormPar protected validate(data: IFormState, contexts: IExecutionContextProvider>): void | Promise {} protected abstract loader(): Promise; - protected abstract saveChanges(): Promise; + protected abstract saveChanges(data: IFormState, contexts: IExecutionContextProvider>): Promise; } diff --git a/webapp/packages/core-ui/src/Form/FormState.ts b/webapp/packages/core-ui/src/Form/FormState.ts index cb76a082ae..bc1aee5f50 100644 --- a/webapp/packages/core-ui/src/Form/FormState.ts +++ b/webapp/packages/core-ui/src/Form/FormState.ts @@ -5,7 +5,7 @@ * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. */ -import { action, makeObservable, observable } from 'mobx'; +import { action, computed, makeObservable, observable } from 'mobx'; import { dataContextAddDIProvider, DataContextGetter, type IDataContext, TempDataContext } from '@cloudbeaver/core-data-context'; import type { App } from '@cloudbeaver/core-di'; @@ -25,7 +25,7 @@ export class FormState implements IFormState { mode: FormMode; parts: MetadataMap>; state: TState; - isDisabled: boolean; + isSaving: boolean; statusMessage: string | string[] | null; statusType: ENotificationType | null; @@ -33,6 +33,10 @@ export class FormState implements IFormState { promise: Promise | null; + get isDisabled(): boolean { + return this.isSaving || this.isLoading(); + } + readonly id: string; readonly service: FormBaseService; readonly dataContext: IDataContext; @@ -52,7 +56,7 @@ export class FormState implements IFormState { this.mode = FormMode.Create; this.parts = new MetadataMap(); this.state = state; - this.isDisabled = false; + this.isSaving = false; this.statusMessage = null; this.statusType = null; @@ -87,8 +91,9 @@ export class FormState implements IFormState { parts: observable.ref, promise: observable.ref, exception: observable.ref, - isDisabled: observable.ref, + isSaving: observable.ref, state: observable, + isDisabled: computed, setMode: action, setPartsState: action, setException: action, @@ -97,7 +102,7 @@ export class FormState implements IFormState { } isLoading(): boolean { - return this.dataContext.get(DATA_CONTEXT_LOADABLE_STATE).loaders.some(loader => loader.isLoading()); + return this.promise !== null || this.dataContext.get(DATA_CONTEXT_LOADABLE_STATE).loaders.some(loader => loader.isLoading()); } isLoaded(): boolean { @@ -138,7 +143,6 @@ export class FormState implements IFormState { this.promise = (async () => { try { - this.isDisabled = true; await this.configureTask.execute(this); const loaders = this.dataContext.get(DATA_CONTEXT_LOADABLE_STATE).loaders; @@ -163,7 +167,6 @@ export class FormState implements IFormState { this.exception = exception; throw exception; } finally { - this.isDisabled = false; this.promise = null; } })(); @@ -211,7 +214,7 @@ export class FormState implements IFormState { async save(): Promise { try { - this.isDisabled = true; + this.isSaving = true; const context = await this.submitTask.execute(this); if (ExecutorInterrupter.isInterrupted(context)) { @@ -223,7 +226,7 @@ export class FormState implements IFormState { } catch (exception: any) { this.exception = exception; } finally { - this.isDisabled = false; + this.isSaving = false; } return false; } diff --git a/webapp/packages/core-ui/src/Form/IFormPart.ts b/webapp/packages/core-ui/src/Form/IFormPart.ts index c11b933c4a..faa9e63117 100644 --- a/webapp/packages/core-ui/src/Form/IFormPart.ts +++ b/webapp/packages/core-ui/src/Form/IFormPart.ts @@ -14,6 +14,5 @@ export interface IFormPart extends ILoadableState { isChanged(): boolean; load(): Promise; - save(): Promise; reset(): void; }