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