From 877003d55f0d2fede715af9a003c48f4c36e914e Mon Sep 17 00:00:00 2001 From: Daniil Sloboda Date: Wed, 16 Oct 2024 16:33:10 +0400 Subject: [PATCH] #5761 - updated minimal ket validation distance (#5771) - updated minimal ket validation distance - commented tests with minimal values because they are no longer valid --- DEVNOTES.md | 40 +++++++++++++++++++ .../multi-tailed-arrow-tool.spec.ts | 28 +++++++------ .../src/domain/entities/multitailArrow.ts | 15 ++++--- 3 files changed, 65 insertions(+), 18 deletions(-) diff --git a/DEVNOTES.md b/DEVNOTES.md index bc222224d6..b19ce6e26e 100644 --- a/DEVNOTES.md +++ b/DEVNOTES.md @@ -248,3 +248,43 @@ docker-compose up -d ``` Service with Ketcher will be run under localhost:8080/ketcher.html + +## Custom Buttons + +Custom buttons enable developers who embed Ketcher into their applications to extend its functionality by implementing custom workflows using existing Ketcher APIs. To add custom buttons to the Ketcher top toolbar, follow these steps: + +1. **Provide an Array of Custom Buttons to the Editor Component** + + Pass an array of custom buttons to the `` component using the `customButtons` prop: + + ```jsx + + ``` + + Each custom button should follow this schema: + + ```ts + { + id: string, // unique identifier of the button + title: string, // optional button tooltip + imageLink: string // absolute link to the image icon + } + ``` + + Once added, all the buttons will appear on the top toolbar. + +2. **Subscribe to the `'CUSTOM_BUTTON_PRESSED'` Event on the Ketcher Bus** + + Subscribe to the event using the following code: + + ```js + ketcher.eventBus.on('CUSTOM_BUTTON_PRESSED', (id: string) => { + // Your custom logic here + }); + ``` + + This function receives a single parameter, `id`, which is the identifier of the pressed button. The function is invoked each time a user presses one of the custom buttons. It is up to the developer to use Ketcher APIs to implement the custom workflow logic. + +### Limitations + +Currently, custom buttons have a slightly different visual appearance compared to native buttons. Since images are used via links, it is not possible to change the color of the icons based on user actions like hovering. \ No newline at end of file diff --git a/ketcher-autotests/tests/Reactions/Reaction-tools/Multi-Tailed-Arrow-Tool/multi-tailed-arrow-tool.spec.ts b/ketcher-autotests/tests/Reactions/Reaction-tools/Multi-Tailed-Arrow-Tool/multi-tailed-arrow-tool.spec.ts index 8b26907cd4..b5c387dfa0 100644 --- a/ketcher-autotests/tests/Reactions/Reaction-tools/Multi-Tailed-Arrow-Tool/multi-tailed-arrow-tool.spec.ts +++ b/ketcher-autotests/tests/Reactions/Reaction-tools/Multi-Tailed-Arrow-Tool/multi-tailed-arrow-tool.spec.ts @@ -307,32 +307,36 @@ test.describe('Multi-Tailed Arrow Tool', () => { detailedDescription: `Multi-Tailed Arrow with different x-coordinates of spine can't be added from KET file to Canvas and error message is displayed - "Cannot deserialize input JSON."`, }, - { + // TODO + /* { description: - 'Multi-Tailed Arrow with head less than 0.5 cannot be added from KET file to Canvas', + 'Multi-Tailed Arrow with head less than 0.5 cannot be added from KET file to Canvas - no longer applicable since 0.01 is the new limit', file: 'KET/multi-tailed-arrow-invalid-head-0.49.ket', detailedDescription: `Multi-Tailed Arrow with head less than 0.5 can't be added from KET file to Canvas and error message is displayed - "Cannot deserialize input JSON."`, - }, - { + }, */ + // TODO + /* { description: - 'Multi-Tailed Arrow with head positioned less than 0.15 to top tail cannot be added from KET file', + 'Multi-Tailed Arrow with head positioned less than 0.15 to top tail cannot be added from KET file - no longer applicable since 0.01 is the new limit', file: 'KET/multi-tailed-arrow-invalid-head-position-0.14.ket', detailedDescription: `Multi-Tailed Arrow with head is positioned less than 0.15 to top tail can't be added from KET file to Canvas and error message is displayed - "Cannot deserialize input JSON."`, - }, - { + }, */ + // TODO + /* { description: - 'Multi-Tailed Arrow with tail less than 0.4 cannot be added from KET file to Canvas', + 'Multi-Tailed Arrow with tail less than 0.4 cannot be added from KET file to Canvas - no longer applicable since 0.01 is the new limit', file: 'KET/multi-tailed-arrow-invalid-tails-0.39.ket', detailedDescription: `Multi-Tailed Arrow with tail less than 0.4 can't be added from KET file to Canvas and error message is displayed - "Cannot deserialize input JSON."`, - }, - { + }, */ + // TODO + /* { description: - 'Multi-Tailed Arrow with tail distance less than 0.35 cannot be added from KET file to Canvas', + 'Multi-Tailed Arrow with tail distance less than 0.35 cannot be added from KET file to Canvas - no longer applicable since 0.01 is the new limit', file: 'KET/multi-tailed-arrow-invalid-tails-distance.ket', detailedDescription: `Multi-Tailed Arrow with tail distance less than 0.35 can't be added from KET file to Canvas and error message is displayed - "Cannot deserialize input JSON."`, - }, + }, */ { description: 'Multi-Tailed Arrow with different lengths of tails cannot be added from KET file to Canvas', diff --git a/packages/ketcher-core/src/domain/entities/multitailArrow.ts b/packages/ketcher-core/src/domain/entities/multitailArrow.ts index 76aaa38d9f..01d50402d3 100644 --- a/packages/ketcher-core/src/domain/entities/multitailArrow.ts +++ b/packages/ketcher-core/src/domain/entities/multitailArrow.ts @@ -55,6 +55,9 @@ interface TailDistance { } export class MultitailArrow extends BaseMicromoleculeEntity { + static KET_MIN_DISTANCE = + FixedPrecisionCoordinates.fromFloatingPrecision(0.01); + static MIN_TAIL_DISTANCE = FixedPrecisionCoordinates.fromFloatingPrecision(0.35); @@ -145,14 +148,14 @@ export class MultitailArrow extends BaseMicromoleculeEntity { if ( spineStartX.value !== spineEndX.value || - spineStartY.value < spineEndY.sub(MultitailArrow.MIN_HEIGHT).value + spineStartY.value < spineEndY.sub(MultitailArrow.KET_MIN_DISTANCE).value ) { return MultitailValidationErrors.INCORRECT_SPINE; } if ( - headX.value < spineStartX.add(MultitailArrow.MIN_HEAD_LENGTH).value || - headY.sub(MultitailArrow.MIN_TOP_BOTTOM_OFFSET).value < spineEndY.value || - headY.add(MultitailArrow.MIN_TOP_BOTTOM_OFFSET).value > spineStartY.value + headX.value < spineStartX.add(MultitailArrow.KET_MIN_DISTANCE).value || + headY.sub(MultitailArrow.KET_MIN_DISTANCE).value < spineEndY.value || + headY.add(MultitailArrow.KET_MIN_DISTANCE).value > spineStartY.value ) { return MultitailValidationErrors.INCORRECT_HEAD; } @@ -165,7 +168,7 @@ export class MultitailArrow extends BaseMicromoleculeEntity { const firstTailX = tailsFixedPrecision[0].x; if ( - firstTailX.value > spineStartX.sub(MultitailArrow.MIN_TAIL_LENGTH).value + firstTailX.value > spineStartX.sub(MultitailArrow.KET_MIN_DISTANCE).value ) { return MultitailValidationErrors.INCORRECT_TAILS; } @@ -174,7 +177,7 @@ export class MultitailArrow extends BaseMicromoleculeEntity { if ( index > 0 && allTails[index - 1].y.value < - tail.y.add(MultitailArrow.MIN_TAIL_DISTANCE).value + tail.y.add(MultitailArrow.KET_MIN_DISTANCE).value ) { return false; }