From de5f09a3519116bb46f1451ff285b975a2c20974 Mon Sep 17 00:00:00 2001 From: ronalds Date: Tue, 2 Dec 2025 15:50:22 -0300 Subject: [PATCH] Frontend (v1.0.95) Ordenamiento consistente de preguntas (App.jsx): MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Las preguntas ahora se ordenan por el campo order antes de agruparse por sección Esto asegura que el orden se mantenga exactamente como está en el backend Ordenamiento de secciones (App.jsx): Las secciones se ordenan por el order mínimo de sus preguntas Garantiza que las secciones aparezcan en orden lógico y consistente Mejora en drag-and-drop (App.jsx): Al reordenar, ahora se ordenan las preguntas por order antes de calcular nuevas posiciones Los nuevos valores de order se asignan correctamente preservando el orden relativo Funciona correctamente con una sola sección y con subpreguntas Ordenamiento en modo inspección (App.jsx): getVisibleQuestions() ahora ordena las preguntas visibles por su campo order Mantiene el orden correcto durante la ejecución de inspecciones Backend (v1.0.92) No se requirieron cambios en el backend (ya estaba ordenando correctamente con order_by(models.Question.order)) --- backend/app/main.py | 2 +- frontend/package.json | 2 +- frontend/public/service-worker.js | 2 +- frontend/src/App.jsx | 47 ++++++++++++++++++++----------- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/backend/app/main.py b/backend/app/main.py index 230f509..cb20675 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -209,7 +209,7 @@ def send_completed_inspection_to_n8n(inspection, db): # No lanzamos excepción para no interrumpir el flujo normal -BACKEND_VERSION = "1.0.91" +BACKEND_VERSION = "1.0.92" app = FastAPI(title="Checklist Inteligente API", version=BACKEND_VERSION) # S3/MinIO configuration diff --git a/frontend/package.json b/frontend/package.json index f8ab1f1..80f2e78 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "checklist-frontend", "private": true, - "version": "1.0.94", + "version": "1.0.95", "type": "module", "scripts": { "dev": "vite", diff --git a/frontend/public/service-worker.js b/frontend/public/service-worker.js index 78a1ed5..8569123 100644 --- a/frontend/public/service-worker.js +++ b/frontend/public/service-worker.js @@ -1,6 +1,6 @@ // Service Worker para PWA con detección de actualizaciones // IMPORTANTE: Actualizar esta versión cada vez que se despliegue una nueva versión -const CACHE_NAME = 'ayutec-v1.0.94'; +const CACHE_NAME = 'ayutec-v1.0.95'; const urlsToCache = [ '/', '/index.html' diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 8d2f7a0..e381aa2 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1459,10 +1459,11 @@ function QuestionsManagerModal({ checklist, onClose }) { // Solo subpreguntas del mismo padre questionsList = questions.filter(q => q.parent_question_id === draggedQuestion.parent_question_id - ) + ).sort((a, b) => a.order - b.order) // Ordenar por order actual } else { // Solo preguntas padre (sin parent_question_id) questionsList = questions.filter(q => !q.parent_question_id) + .sort((a, b) => a.order - b.order) // Ordenar por order actual } const draggedIndex = questionsList.findIndex(q => q.id === draggedQuestion.id) @@ -1473,10 +1474,11 @@ function QuestionsManagerModal({ checklist, onClose }) { const [movedQuestion] = newList.splice(draggedIndex, 1) newList.splice(targetIndex, 0, movedQuestion) - // Preparar datos para el backend (solo las preguntas afectadas) + // Preparar datos para el backend usando los valores de 'order' originales + // Esto mantiene el orden relativo correcto con respecto a otras preguntas const reorderData = newList.map((q, index) => ({ question_id: q.id, - new_order: index + new_order: questionsList[index].order // Usar el order de la posición correspondiente })) try { @@ -1506,7 +1508,11 @@ function QuestionsManagerModal({ checklist, onClose }) { setDragOverQuestion(null) } - const questionsBySection = questions.reduce((acc, q) => { + // Primero ordenar todas las preguntas por el campo 'order' para mantener el orden del backend + const sortedQuestions = [...questions].sort((a, b) => a.order - b.order) + + // Luego agrupar por sección manteniendo el orden + const questionsBySection = sortedQuestions.reduce((acc, q) => { const section = q.section || 'Sin sección' if (!acc[section]) acc[section] = [] acc[section].push(q) @@ -1867,7 +1873,14 @@ function QuestionsManagerModal({ checklist, onClose }) { ) : (
- {Object.entries(questionsBySection).map(([section, sectionQuestions]) => ( + {Object.entries(questionsBySection) + .sort(([, questionsA], [, questionsB]) => { + // Ordenar secciones por el 'order' mínimo de sus preguntas + const minOrderA = Math.min(...questionsA.map(q => q.order)) + const minOrderB = Math.min(...questionsB.map(q => q.order)) + return minOrderA - minOrderB + }) + .map(([section, sectionQuestions]) => (

{section}

@@ -4333,17 +4346,19 @@ function InspectionModal({ checklist, existingInspection, user, onClose, onCompl // Get visible questions based on conditional logic const getVisibleQuestions = () => { - return questions.filter(q => { - // If no parent, always visible - if (!q.parent_question_id) return true - - // Check parent answer - const parentAnswer = answers[q.parent_question_id] - if (!parentAnswer) return false - - // Show if parent answer matches trigger - return parentAnswer.value === q.show_if_answer - }) + return questions + .filter(q => { + // If no parent, always visible + if (!q.parent_question_id) return true + + // Check parent answer + const parentAnswer = answers[q.parent_question_id] + if (!parentAnswer) return false + + // Show if parent answer matches trigger + return parentAnswer.value === q.show_if_answer + }) + .sort((a, b) => a.order - b.order) // Mantener orden del backend } // Move to signatures step