From efaf95835ed1742e1374a02e754d5d9fc7ae944e Mon Sep 17 00:00:00 2001 From: tsv2013 Date: Fri, 13 Sep 2024 00:00:02 +0300 Subject: [PATCH] Fixed #5783 - Weird drag behaviour to empty survey in Safari - stop undo/redo transaction on banned drop (#5880) * Fixed #5783 - Weird drag behaviour to empty survey in Safari - stop undo/redo transaction on banned drop * Update .eslintrc.json --------- Co-authored-by: tsv2013 --- .eslintrc.json | 5 ++- .../survey-creator-core/src/creator-base.ts | 3 ++ .../tests/creator-undo-redo.tests.ts | 44 +++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 02d5362142..301b3225d1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -163,6 +163,7 @@ "linebreak-style": [ "off", "windows" - ] + ], + "react/no-is-mounted": "off" } -} \ No newline at end of file +} diff --git a/packages/survey-creator-core/src/creator-base.ts b/packages/survey-creator-core/src/creator-base.ts index 1f51200f45..017823c81c 100644 --- a/packages/survey-creator-core/src/creator-base.ts +++ b/packages/survey-creator-core/src/creator-base.ts @@ -1925,6 +1925,9 @@ export class SurveyCreatorModel extends Base this.setModified({ type: "ADDED_FROM_TOOLBOX", question: options.draggedElement }); } }); + this.dragDropSurveyElements.onDragClear.add((sender, options) => { + this.stopUndoRedoTransaction(); + }); } private initDragDropChoices() { this.dragDropChoices = new DragDropChoices(null, this); diff --git a/packages/survey-creator-core/tests/creator-undo-redo.tests.ts b/packages/survey-creator-core/tests/creator-undo-redo.tests.ts index 7b7dbda93c..3e43150fc0 100644 --- a/packages/survey-creator-core/tests/creator-undo-redo.tests.ts +++ b/packages/survey-creator-core/tests/creator-undo-redo.tests.ts @@ -333,6 +333,50 @@ test("undo/redo DnD ", (): any => { expect(creator.survey.pages[0].elements.map(e => e.name)).toEqual(["question1", "question2"]); expect(creator.survey.pages[0].rows.length).toEqual(1); }); +test("undo/redo DnD stops transaction onDragClear", (): any => { + const creator = new CreatorTester(); + creator.JSON = { + "logoPosition": "right", + "pages": [ + { + "name": "page1", + "elements": [ + { + "type": "radiogroup", + "name": "question1", + "choices": [ + "item1", + "item2", + "item3" + ] + }, + { + "type": "radiogroup", + "name": "question2", + "startWithNewLine": false, + "choices": [ + "item1", + "item2", + "item3" + ] + } + ] + } + ] + }; + + const q1 = creator.survey.pages[0].elements[0]; + const q2 = creator.survey.pages[0].elements[1]; + creator.dragDropSurveyElements.onDragStart.fire({ dropTarget: q2, draggedElement: q1 }, {}); + + expect(creator.undoRedoManager["transactionCounter"]).toEqual(1); + expect(creator.undoRedoManager["_preparingTransaction"]).toBeDefined(); + + creator.dragDropSurveyElements.onDragClear.fire({ dropTarget: q2, draggedElement: q1 }, {}); + + expect(creator.undoRedoManager["transactionCounter"]).toEqual(0); + expect(creator.undoRedoManager["_preparingTransaction"]).toBe(null); +}); test("Undo restore deleted page and question", (): any => { const creator = new CreatorTester(); creator.JSON = {