From ce151631ab248d51854f64572a40174d8e02b91b Mon Sep 17 00:00:00 2001 From: gitea Date: Thu, 27 Nov 2025 16:47:05 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Corregido=20Drag=20&=20Drop=20con?= =?UTF-8?q?=20Validaci=C3=B3n=20de=20Niveles=20Cambios=20v1.0.74=20L=C3=B3?= =?UTF-8?q?gica=20Implementada:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Preguntas padre solo se pueden reordenar entre sí Subpreguntas solo se pueden reordenar con otras subpreguntas del mismo padre No se permite arrastrar una pregunta padre dentro de subpreguntas o viceversa Validaciones: ✅ En handleDragOver: Cursor none si intentas arrastrar entre diferentes niveles ✅ En handleDrop: Mensajes de error claros si intentas mezclar niveles ✅ Filtrado inteligente: Solo reordena el grupo correcto de preguntas --- backend/app/main.py | 2 +- frontend/package.json | 2 +- frontend/src/App.jsx | 53 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/backend/app/main.py b/backend/app/main.py index 3d37819..aa5e19a 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -204,7 +204,7 @@ def send_completed_inspection_to_n8n(inspection, db): # No lanzamos excepción para no interrumpir el flujo normal -BACKEND_VERSION = "1.0.73" +BACKEND_VERSION = "1.0.74" app = FastAPI(title="Checklist Inteligente API", version=BACKEND_VERSION) # S3/MinIO configuration diff --git a/frontend/package.json b/frontend/package.json index 1d103a8..44da8bc 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "checklist-frontend", "private": true, - "version": "1.0.73", + "version": "1.0.74", "type": "module", "scripts": { "dev": "vite", diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index ddcc8c1..6933f57 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1229,6 +1229,25 @@ function QuestionsManagerModal({ checklist, onClose }) { const handleDragOver = (e, question) => { e.preventDefault() + + // Validar que ambas preguntas sean del mismo nivel (padre-padre o hijo-hijo del mismo padre) + if (draggedQuestion) { + const draggedIsChild = !!draggedQuestion.parent_question_id + const targetIsChild = !!question.parent_question_id + + // No permitir mezclar niveles + if (draggedIsChild !== targetIsChild) { + e.dataTransfer.dropEffect = 'none' + return + } + + // Si son hijos, deben ser del mismo padre + if (draggedIsChild && draggedQuestion.parent_question_id !== question.parent_question_id) { + e.dataTransfer.dropEffect = 'none' + return + } + } + e.dataTransfer.dropEffect = 'move' setDragOverQuestion(question) } @@ -1245,8 +1264,38 @@ function QuestionsManagerModal({ checklist, onClose }) { setDragOverQuestion(null) return } + + // Validar que sean del mismo nivel + const draggedIsChild = !!draggedQuestion.parent_question_id + const targetIsChild = !!targetQuestion.parent_question_id + + if (draggedIsChild !== targetIsChild) { + alert('⚠️ Solo puedes reordenar preguntas del mismo nivel') + setDraggedQuestion(null) + setDragOverQuestion(null) + return + } + + // Si son hijos, validar que sean del mismo padre + if (draggedIsChild && draggedQuestion.parent_question_id !== targetQuestion.parent_question_id) { + alert('⚠️ Solo puedes reordenar subpreguntas del mismo padre') + setDraggedQuestion(null) + setDragOverQuestion(null) + return + } - const questionsList = Object.values(questionsBySection).flat() + // Filtrar solo las preguntas del mismo nivel/grupo + let questionsList + if (draggedIsChild) { + // Solo subpreguntas del mismo padre + questionsList = questions.filter(q => + q.parent_question_id === draggedQuestion.parent_question_id + ) + } else { + // Solo preguntas padre (sin parent_question_id) + questionsList = questions.filter(q => !q.parent_question_id) + } + const draggedIndex = questionsList.findIndex(q => q.id === draggedQuestion.id) const targetIndex = questionsList.findIndex(q => q.id === targetQuestion.id) @@ -1255,7 +1304,7 @@ function QuestionsManagerModal({ checklist, onClose }) { const [movedQuestion] = newList.splice(draggedIndex, 1) newList.splice(targetIndex, 0, movedQuestion) - // Preparar datos para el backend + // Preparar datos para el backend (solo las preguntas afectadas) const reorderData = newList.map((q, index) => ({ question_id: q.id, new_order: index