From d62d67726a4e6093b2e8eb29560f203ba4b9db3d Mon Sep 17 00:00:00 2001 From: Konstantin Zharich Date: Tue, 18 Apr 2023 17:56:31 +0200 Subject: [PATCH 1/4] - emitted event for remote and standalone version --- .../services/struct/remoteStructService.ts | 3 +++ packages/ketcher-core/src/typing.d.ts | 7 +++++++ .../src/utilities/emitEventRequestIsFinished.ts | 9 +++++++++ packages/ketcher-core/src/utilities/index.ts | 1 + .../services/struct/standaloneStructService.ts | 5 ++++- 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 packages/ketcher-core/src/typing.d.ts create mode 100644 packages/ketcher-core/src/utilities/emitEventRequestIsFinished.ts diff --git a/packages/ketcher-core/src/infrastructure/services/struct/remoteStructService.ts b/packages/ketcher-core/src/infrastructure/services/struct/remoteStructService.ts index da0bf411a2..4a12809f6e 100644 --- a/packages/ketcher-core/src/infrastructure/services/struct/remoteStructService.ts +++ b/packages/ketcher-core/src/infrastructure/services/struct/remoteStructService.ts @@ -40,6 +40,7 @@ import { StructService, StructServiceOptions } from 'domain/services' +import { emitEventRequestIsFinished } from 'utilities' function pollDeferred(process, complete, timeGap, startTimeGap) { return new Promise((resolve, reject) => { @@ -94,6 +95,8 @@ function request( .then((res) => (response.ok ? res : Promise.reject(res.error))) ) } + console.log('remote request') + response.finally(() => emitEventRequestIsFinished()) return response } diff --git a/packages/ketcher-core/src/typing.d.ts b/packages/ketcher-core/src/typing.d.ts new file mode 100644 index 0000000000..8b0e52c73e --- /dev/null +++ b/packages/ketcher-core/src/typing.d.ts @@ -0,0 +1,7 @@ +import { Ketcher } from 'ketcher-core' + +declare global { + interface Window { + ketcher: Ketcher + } +} diff --git a/packages/ketcher-core/src/utilities/emitEventRequestIsFinished.ts b/packages/ketcher-core/src/utilities/emitEventRequestIsFinished.ts new file mode 100644 index 0000000000..cf46fb161e --- /dev/null +++ b/packages/ketcher-core/src/utilities/emitEventRequestIsFinished.ts @@ -0,0 +1,9 @@ +export const REQUEST_IS_FINISHED = 'REQUEST_IS_FINISHED' + +/** + * Emit event when request is finished + * Used only for autotesters repository to prevent long delays + */ +export function emitEventRequestIsFinished(): void { + window?.ketcher?.eventBus.emit(REQUEST_IS_FINISHED) +} diff --git a/packages/ketcher-core/src/utilities/index.ts b/packages/ketcher-core/src/utilities/index.ts index c0fd2c2b3e..c312125eee 100644 --- a/packages/ketcher-core/src/utilities/index.ts +++ b/packages/ketcher-core/src/utilities/index.ts @@ -18,3 +18,4 @@ export * from './ifDef' export * from './tfx' export * from './runAsyncAction' export * from './b64toBlob' +export * from './emitEventRequestIsFinished' diff --git a/packages/ketcher-standalone/src/infrastructure/services/struct/standaloneStructService.ts b/packages/ketcher-standalone/src/infrastructure/services/struct/standaloneStructService.ts index f47de1f564..eee389e534 100644 --- a/packages/ketcher-standalone/src/infrastructure/services/struct/standaloneStructService.ts +++ b/packages/ketcher-standalone/src/infrastructure/services/struct/standaloneStructService.ts @@ -58,7 +58,8 @@ import { LayoutResult, RecognizeResult, StructService, - StructServiceOptions + StructServiceOptions, + emitEventRequestIsFinished } from 'ketcher-core' // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -185,6 +186,8 @@ class IndigoService implements StructService { if (message.type !== undefined) { const event = messageTypeToEventMapping[message.type] this.EE.emit(event, { data: message }) + console.log('standalone mode') + emitEventRequestIsFinished() } } } From 3f954fee203fa1b3aa51f372c66b6a9eebfe4171 Mon Sep 17 00:00:00 2001 From: Konstantin Zharich Date: Wed, 19 Apr 2023 16:59:32 +0200 Subject: [PATCH 2/4] - removed emit event from remote / standalone struct because they do not cover all cases - added emit into shared.ts file, since it is used for all top tool bar actions --- .../infrastructure/services/struct/remoteStructService.ts | 3 --- .../ketcher-core/src/utilities/emitEventRequestIsFinished.ts | 2 +- packages/ketcher-react/src/script/ui/state/shared.ts | 5 ++++- .../services/struct/standaloneStructService.ts | 5 +---- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/ketcher-core/src/infrastructure/services/struct/remoteStructService.ts b/packages/ketcher-core/src/infrastructure/services/struct/remoteStructService.ts index 4a12809f6e..da0bf411a2 100644 --- a/packages/ketcher-core/src/infrastructure/services/struct/remoteStructService.ts +++ b/packages/ketcher-core/src/infrastructure/services/struct/remoteStructService.ts @@ -40,7 +40,6 @@ import { StructService, StructServiceOptions } from 'domain/services' -import { emitEventRequestIsFinished } from 'utilities' function pollDeferred(process, complete, timeGap, startTimeGap) { return new Promise((resolve, reject) => { @@ -95,8 +94,6 @@ function request( .then((res) => (response.ok ? res : Promise.reject(res.error))) ) } - console.log('remote request') - response.finally(() => emitEventRequestIsFinished()) return response } diff --git a/packages/ketcher-core/src/utilities/emitEventRequestIsFinished.ts b/packages/ketcher-core/src/utilities/emitEventRequestIsFinished.ts index cf46fb161e..a09ca7486b 100644 --- a/packages/ketcher-core/src/utilities/emitEventRequestIsFinished.ts +++ b/packages/ketcher-core/src/utilities/emitEventRequestIsFinished.ts @@ -2,7 +2,7 @@ export const REQUEST_IS_FINISHED = 'REQUEST_IS_FINISHED' /** * Emit event when request is finished - * Used only for autotesters repository to prevent long delays + * Used only for testers to prevent long delays in test cases */ export function emitEventRequestIsFinished(): void { window?.ketcher?.eventBus.emit(REQUEST_IS_FINISHED) diff --git a/packages/ketcher-react/src/script/ui/state/shared.ts b/packages/ketcher-react/src/script/ui/state/shared.ts index 615a515468..8985066bad 100644 --- a/packages/ketcher-react/src/script/ui/state/shared.ts +++ b/packages/ketcher-react/src/script/ui/state/shared.ts @@ -21,7 +21,8 @@ import { getStereoAtomsMap, identifyStructFormat, Struct, - SupportedFormat + SupportedFormat, + emitEventRequestIsFinished } from 'ketcher-core' import { supportedSGroupTypes } from './constants' @@ -160,6 +161,8 @@ export function load(struct: Struct, options?) { } catch (err: any) { dispatch(setAnalyzingFile(false)) err && errorHandler(err.message) + } finally { + emitEventRequestIsFinished() } } } diff --git a/packages/ketcher-standalone/src/infrastructure/services/struct/standaloneStructService.ts b/packages/ketcher-standalone/src/infrastructure/services/struct/standaloneStructService.ts index eee389e534..f47de1f564 100644 --- a/packages/ketcher-standalone/src/infrastructure/services/struct/standaloneStructService.ts +++ b/packages/ketcher-standalone/src/infrastructure/services/struct/standaloneStructService.ts @@ -58,8 +58,7 @@ import { LayoutResult, RecognizeResult, StructService, - StructServiceOptions, - emitEventRequestIsFinished + StructServiceOptions } from 'ketcher-core' // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -186,8 +185,6 @@ class IndigoService implements StructService { if (message.type !== undefined) { const event = messageTypeToEventMapping[message.type] this.EE.emit(event, { data: message }) - console.log('standalone mode') - emitEventRequestIsFinished() } } } From 9f66b99bfb5b48e9aaf59566b434fe70b2cec7c7 Mon Sep 17 00:00:00 2001 From: Konstantin Zharich Date: Thu, 20 Apr 2023 11:59:58 +0200 Subject: [PATCH 3/4] - moved function back to ketcher-react --- packages/ketcher-core/src/utilities/index.ts | 1 - packages/ketcher-react/src/script/ui/state/shared.ts | 4 ++-- .../src/script/ui/utils}/emitEventRequestIsFinished.ts | 10 +++++++++- 3 files changed, 11 insertions(+), 4 deletions(-) rename packages/{ketcher-core/src/utilities => ketcher-react/src/script/ui/utils}/emitEventRequestIsFinished.ts (58%) diff --git a/packages/ketcher-core/src/utilities/index.ts b/packages/ketcher-core/src/utilities/index.ts index c312125eee..c0fd2c2b3e 100644 --- a/packages/ketcher-core/src/utilities/index.ts +++ b/packages/ketcher-core/src/utilities/index.ts @@ -18,4 +18,3 @@ export * from './ifDef' export * from './tfx' export * from './runAsyncAction' export * from './b64toBlob' -export * from './emitEventRequestIsFinished' diff --git a/packages/ketcher-react/src/script/ui/state/shared.ts b/packages/ketcher-react/src/script/ui/state/shared.ts index 8985066bad..be580100cf 100644 --- a/packages/ketcher-react/src/script/ui/state/shared.ts +++ b/packages/ketcher-react/src/script/ui/state/shared.ts @@ -21,14 +21,14 @@ import { getStereoAtomsMap, identifyStructFormat, Struct, - SupportedFormat, - emitEventRequestIsFinished + SupportedFormat } from 'ketcher-core' import { supportedSGroupTypes } from './constants' import { setAnalyzingFile } from './request' import tools from '../action/tools' import { SettingsManager } from '../utils/settingsManager' +import { emitEventRequestIsFinished } from '../utils/emitEventRequestIsFinished' export function onAction(action) { if (action && action.dialog) { diff --git a/packages/ketcher-core/src/utilities/emitEventRequestIsFinished.ts b/packages/ketcher-react/src/script/ui/utils/emitEventRequestIsFinished.ts similarity index 58% rename from packages/ketcher-core/src/utilities/emitEventRequestIsFinished.ts rename to packages/ketcher-react/src/script/ui/utils/emitEventRequestIsFinished.ts index a09ca7486b..4022097c07 100644 --- a/packages/ketcher-core/src/utilities/emitEventRequestIsFinished.ts +++ b/packages/ketcher-react/src/script/ui/utils/emitEventRequestIsFinished.ts @@ -1,4 +1,12 @@ -export const REQUEST_IS_FINISHED = 'REQUEST_IS_FINISHED' +import { Ketcher } from 'ketcher-core' + +const REQUEST_IS_FINISHED = 'REQUEST_IS_FINISHED' + +declare global { + interface Window { + ketcher: Ketcher + } +} /** * Emit event when request is finished From 32b9b5affd6484e3e008a1166773ee1cd5cef668 Mon Sep 17 00:00:00 2001 From: Konstantin Zharich Date: Tue, 16 May 2023 17:21:33 +0200 Subject: [PATCH 4/4] - moved emitEventRequestIsFinished into ketcher-core package --- .../src/utilities}/emitEventRequestIsFinished.ts | 11 +++-------- packages/ketcher-core/src/utilities/index.ts | 1 + packages/ketcher-react/src/script/ui/state/shared.ts | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) rename packages/{ketcher-react/src/script/ui/utils => ketcher-core/src/utilities}/emitEventRequestIsFinished.ts (67%) diff --git a/packages/ketcher-react/src/script/ui/utils/emitEventRequestIsFinished.ts b/packages/ketcher-core/src/utilities/emitEventRequestIsFinished.ts similarity index 67% rename from packages/ketcher-react/src/script/ui/utils/emitEventRequestIsFinished.ts rename to packages/ketcher-core/src/utilities/emitEventRequestIsFinished.ts index 4022097c07..ff76ff28b1 100644 --- a/packages/ketcher-react/src/script/ui/utils/emitEventRequestIsFinished.ts +++ b/packages/ketcher-core/src/utilities/emitEventRequestIsFinished.ts @@ -1,16 +1,11 @@ -import { Ketcher } from 'ketcher-core' - const REQUEST_IS_FINISHED = 'REQUEST_IS_FINISHED' -declare global { - interface Window { - ketcher: Ketcher - } -} - /** * Emit event when request is finished * Used only for testers to prevent long delays in test cases + * Triggers on Add to canvas / Aromatize / Dearomatize + * Clean Up / Calculate CIP / Paste from clipboard + * maybe somewhere else */ export function emitEventRequestIsFinished(): void { window?.ketcher?.eventBus.emit(REQUEST_IS_FINISHED) diff --git a/packages/ketcher-core/src/utilities/index.ts b/packages/ketcher-core/src/utilities/index.ts index c0fd2c2b3e..c312125eee 100644 --- a/packages/ketcher-core/src/utilities/index.ts +++ b/packages/ketcher-core/src/utilities/index.ts @@ -18,3 +18,4 @@ export * from './ifDef' export * from './tfx' export * from './runAsyncAction' export * from './b64toBlob' +export * from './emitEventRequestIsFinished' diff --git a/packages/ketcher-react/src/script/ui/state/shared.ts b/packages/ketcher-react/src/script/ui/state/shared.ts index be580100cf..8985066bad 100644 --- a/packages/ketcher-react/src/script/ui/state/shared.ts +++ b/packages/ketcher-react/src/script/ui/state/shared.ts @@ -21,14 +21,14 @@ import { getStereoAtomsMap, identifyStructFormat, Struct, - SupportedFormat + SupportedFormat, + emitEventRequestIsFinished } from 'ketcher-core' import { supportedSGroupTypes } from './constants' import { setAnalyzingFile } from './request' import tools from '../action/tools' import { SettingsManager } from '../utils/settingsManager' -import { emitEventRequestIsFinished } from '../utils/emitEventRequestIsFinished' export function onAction(action) { if (action && action.dialog) {