From 332a83bb402dcea5eb77858cb570cd85a13fade4 Mon Sep 17 00:00:00 2001 From: Naumov Alexey Date: Wed, 29 Sep 2021 21:34:56 +0300 Subject: [PATCH] fix(plugin-connections): CB-783 ask for reconnect if connection was updated --- .../core-localization/src/locales/en.ts | 1 + .../core-localization/src/locales/ru.ts | 1 + .../PublicConnectionForm.tsx | 2 +- .../PublicConnectionFormService.ts | 31 +++++++++++++++++++ .../plugin-connections/src/locales/en.ts | 3 ++ .../plugin-connections/src/locales/ru.ts | 3 ++ 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/webapp/packages/core-localization/src/locales/en.ts b/webapp/packages/core-localization/src/locales/en.ts index 202d67bd1a..771fb1063a 100644 --- a/webapp/packages/core-localization/src/locales/en.ts +++ b/webapp/packages/core-localization/src/locales/en.ts @@ -44,6 +44,7 @@ export const defaultENLocale = [ ['ui_no_items_placeholder', 'There are no items yet.'], ['ui_search_no_result_placeholder', 'No results have been found.'], ['ui_save_reminder', 'You have unsaved changes.'], + ['ui_yes', 'Yes'], ['root_permission_denied', 'You have no permissions'], ['app_root_session_expire_warning_title', 'Session is about to expire'], diff --git a/webapp/packages/core-localization/src/locales/ru.ts b/webapp/packages/core-localization/src/locales/ru.ts index 3a5d6473a7..6afc6ffb5c 100644 --- a/webapp/packages/core-localization/src/locales/ru.ts +++ b/webapp/packages/core-localization/src/locales/ru.ts @@ -42,6 +42,7 @@ export const defaultRULocale = [ ['ui_no_items_placeholder', 'Вы еще ничего не добавили.'], ['ui_search_no_result_placeholder', 'По вашему запросу ничего не найдено.'], ['ui_save_reminder', 'У вас есть несохраненные изменения.'], + ['ui_yes', 'Да'], ['root_permission_denied', 'Отказано в доступе'], ['app_root_session_expire_warning_title', 'Ваша сессия скоро закончится'], diff --git a/webapp/packages/plugin-connections/src/PublicConnectionForm/PublicConnectionForm.tsx b/webapp/packages/plugin-connections/src/PublicConnectionForm/PublicConnectionForm.tsx index 91c4a68aa1..9259e48b99 100644 --- a/webapp/packages/plugin-connections/src/PublicConnectionForm/PublicConnectionForm.tsx +++ b/webapp/packages/plugin-connections/src/PublicConnectionForm/PublicConnectionForm.tsx @@ -26,7 +26,7 @@ export const PublicConnectionForm: React.FC = observer(function PublicConnection const service = useService(PublicConnectionFormService); const close = useCallback(() => service.close(true), []); - const save = useCallback(() => service.close(true), []); + const save = useCallback(() => service.save(), []); return styled(styles)( diff --git a/webapp/packages/plugin-connections/src/PublicConnectionForm/PublicConnectionFormService.ts b/webapp/packages/plugin-connections/src/PublicConnectionForm/PublicConnectionFormService.ts index de60084901..a1584a67ed 100644 --- a/webapp/packages/plugin-connections/src/PublicConnectionForm/PublicConnectionFormService.ts +++ b/webapp/packages/plugin-connections/src/PublicConnectionForm/PublicConnectionFormService.ts @@ -12,6 +12,7 @@ import { ConnectionFormService, ConnectionInfoResource, IConnectionFormState } f import { ConnectionFormState } from '@cloudbeaver/core-connections'; import { injectable } from '@cloudbeaver/core-di'; import { CommonDialogService, ConfirmationDialog, DialogueStateResult } from '@cloudbeaver/core-dialogs'; +import { NotificationService } from '@cloudbeaver/core-events'; import { ExecutorInterrupter, IExecutorHandler } from '@cloudbeaver/core-executor'; import { SessionDataResource } from '@cloudbeaver/core-root'; import type { ConnectionConfig, ResourceKey } from '@cloudbeaver/core-sdk'; @@ -27,6 +28,7 @@ export class PublicConnectionFormService { constructor( private readonly commonDialogService: CommonDialogService, + private readonly notificationService: NotificationService, private readonly optionsPanelService: OptionsPanelService, private readonly connectionFormService: ConnectionFormService, private readonly connectionInfoResource: ConnectionInfoResource, @@ -84,6 +86,16 @@ export class PublicConnectionFormService { } } + save(): void { + const connection = this.formState?.info; + + this.close(true); + + if (connection?.id && connection.connected) { + this.tryReconnect(connection.id); + } + } + private closeDeleted: IExecutorHandler> = (data, contexts) => { if (!this.formState || !this.formState.config.connectionId) { return; @@ -123,6 +135,25 @@ export class PublicConnectionFormService { } }; + private async tryReconnect(id: string) { + const result = await this.commonDialogService.open(ConfirmationDialog, { + title: 'connections_public_connection_edit_reconnect_title', + message: 'connections_public_connection_edit_reconnect_message', + confirmActionText: 'ui_yes', + }); + + if (result === DialogueStateResult.Rejected) { + return; + } + + try { + await this.connectionInfoResource.close(id); + await this.connectionInfoResource.init({ id }); + } catch (exception) { + this.notificationService.logException(exception, 'connections_public_connection_edit_reconnect_failed'); + } + } + private clearFormState() { this.formState?.dispose(); this.formState = null; diff --git a/webapp/packages/plugin-connections/src/locales/en.ts b/webapp/packages/plugin-connections/src/locales/en.ts index f807e88c7d..a34a6a922b 100644 --- a/webapp/packages/plugin-connections/src/locales/en.ts +++ b/webapp/packages/plugin-connections/src/locales/en.ts @@ -2,4 +2,7 @@ export default [ ['connections_public_connection_edit_menu_item_title', 'Edit Connection'], ['connections_public_connection_edit_cancel_title', 'Cancel confirmation'], ['connections_public_connection_edit_cancel_message', 'You\'re going to cancel connection changes. Unsaved changes will be lost. Are you sure?'], + ['connections_public_connection_edit_reconnect_title', 'Connection updated'], + ['connections_public_connection_edit_reconnect_message', 'Connection has been updated. Do you want to reconnect?'], + ['connections_public_connection_edit_reconnect_failed', 'Failed to reconnect'], ]; diff --git a/webapp/packages/plugin-connections/src/locales/ru.ts b/webapp/packages/plugin-connections/src/locales/ru.ts index 1ed9674006..b114fe5796 100644 --- a/webapp/packages/plugin-connections/src/locales/ru.ts +++ b/webapp/packages/plugin-connections/src/locales/ru.ts @@ -2,4 +2,7 @@ export default [ ['connections_public_connection_edit_menu_item_title', 'Изменить подключение'], ['connections_public_connection_edit_cancel_title', 'Отмена редактирования'], ['connections_public_connection_edit_cancel_message', 'Вы собираетесь закрыть редактор, несохраненные изменения не будут применены. Вы уверены?'], + ['connections_public_connection_edit_reconnect_title', 'Подключение обновлено'], + ['connections_public_connection_edit_reconnect_message', 'Подключение было обновлено. Вы хотите переподключиться?'], + ['connections_public_connection_edit_reconnect_failed', 'Не удалось переподключиться'], ];