From 7a3997472cc1078c355fa8a494f23e12a4d0624b Mon Sep 17 00:00:00 2001 From: Senthil Athiban Date: Tue, 23 Jul 2024 08:58:27 +0530 Subject: [PATCH 1/2] (fix): fix the dnd destination --- .../interactive-builder/interactive-builder.component.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/interactive-builder/interactive-builder.component.tsx b/src/components/interactive-builder/interactive-builder.component.tsx index cb4eafff..74a4ab21 100644 --- a/src/components/interactive-builder/interactive-builder.component.tsx +++ b/src/components/interactive-builder/interactive-builder.component.tsx @@ -242,7 +242,7 @@ const InteractiveBuilder: React.FC = ({ ); const handleDragEnd = (event: DragEndEvent) => { - const { active, delta } = event; + const { active, over } = event; if (active) { // Get the source information @@ -251,11 +251,15 @@ const InteractiveBuilder: React.FC = ({ const sourceSectionIndex = parseInt(activeIdParts[2]); const sourceQuestionIndex = parseInt(activeIdParts[3]); + // Get the destination information + const destination = over.id.toString().split('-'); + const destinationQuestionIndex = parseInt(destination[4]); + // Move the question within the same section const questions = schema.pages[sourcePageIndex].sections[sourceSectionIndex].questions; const questionToMove = questions[sourceQuestionIndex]; questions.splice(sourceQuestionIndex, 1); - questions.splice(sourceQuestionIndex + delta.y, 0, questionToMove); + questions.splice(destinationQuestionIndex, 0, questionToMove); const updatedSchema = { ...schema, From 9c8131af47939e628168eeebf9b1ebe83957cf17 Mon Sep 17 00:00:00 2001 From: Dennis Kigen Date: Tue, 23 Jul 2024 11:46:40 +0300 Subject: [PATCH 2/2] Subtle tweaks --- .../draggable-question.component.tsx | 29 ++++++++++++------- .../draggable-question.scss | 8 +++-- .../droppable-container.scss | 4 +-- translations/en.json | 2 +- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/components/interactive-builder/draggable-question.component.tsx b/src/components/interactive-builder/draggable-question.component.tsx index e082b04e..d2dce558 100644 --- a/src/components/interactive-builder/draggable-question.component.tsx +++ b/src/components/interactive-builder/draggable-question.component.tsx @@ -1,4 +1,5 @@ import React, { useCallback } from 'react'; +import classNames from 'classnames'; import { useDraggable } from '@dnd-kit/core'; import { CSS } from '@dnd-kit/utilities'; import { useTranslation } from 'react-i18next'; @@ -29,8 +30,8 @@ const DraggableQuestion: React.FC = ({ schema, sectionIndex, }) => { - const defaultEnterDelayInMs = 300; const { t } = useTranslation(); + const defaultEnterDelayInMs = 300; const draggableId = `question-${pageIndex}-${sectionIndex}-${questionIndex}`; const launchEditQuestionModal = useCallback(() => { @@ -57,25 +58,31 @@ const DraggableQuestion: React.FC = ({ }); }, [onSchemaChange, pageIndex, question, questionIndex, schema, sectionIndex]); - const { attributes, listeners, transform, isDragging, setNodeRef } = useDraggable({ + const { attributes, listeners, transform, isDragging, over, setNodeRef } = useDraggable({ id: draggableId, disabled: questionCount <= 1, }); - const style = { - transform: CSS.Translate.toString(transform), - }; - - const dragStyles = isDragging ? styles.isDragged : styles.normal; + const handleDuplicate = useCallback(() => { + if (!isDragging) { + handleDuplicateQuestion(question, pageIndex, sectionIndex); + } + }, [handleDuplicateQuestion, isDragging, question, pageIndex, sectionIndex]); return ( -
+
@@ -91,7 +98,7 @@ const DraggableQuestion: React.FC = ({ feedback={t('duplicated', 'Duplicated') + '!'} iconDescription={t('duplicateQuestion', 'Duplicate question')} kind="ghost" - onClick={() => !isDragging && handleDuplicateQuestion(question, pageIndex, sectionIndex)} + onClick={handleDuplicate} />