✅ Corregido Drag & Drop con Validación de Niveles
Cambios v1.0.74 Lógica Implementada: 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
This commit is contained in:
@@ -204,7 +204,7 @@ def send_completed_inspection_to_n8n(inspection, db):
|
|||||||
# No lanzamos excepción para no interrumpir el flujo normal
|
# 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)
|
app = FastAPI(title="Checklist Inteligente API", version=BACKEND_VERSION)
|
||||||
|
|
||||||
# S3/MinIO configuration
|
# S3/MinIO configuration
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "checklist-frontend",
|
"name": "checklist-frontend",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.0.73",
|
"version": "1.0.74",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -1229,6 +1229,25 @@ function QuestionsManagerModal({ checklist, onClose }) {
|
|||||||
|
|
||||||
const handleDragOver = (e, question) => {
|
const handleDragOver = (e, question) => {
|
||||||
e.preventDefault()
|
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'
|
e.dataTransfer.dropEffect = 'move'
|
||||||
setDragOverQuestion(question)
|
setDragOverQuestion(question)
|
||||||
}
|
}
|
||||||
@@ -1246,7 +1265,37 @@ function QuestionsManagerModal({ checklist, onClose }) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const questionsList = Object.values(questionsBySection).flat()
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 draggedIndex = questionsList.findIndex(q => q.id === draggedQuestion.id)
|
||||||
const targetIndex = questionsList.findIndex(q => q.id === targetQuestion.id)
|
const targetIndex = questionsList.findIndex(q => q.id === targetQuestion.id)
|
||||||
|
|
||||||
@@ -1255,7 +1304,7 @@ function QuestionsManagerModal({ checklist, onClose }) {
|
|||||||
const [movedQuestion] = newList.splice(draggedIndex, 1)
|
const [movedQuestion] = newList.splice(draggedIndex, 1)
|
||||||
newList.splice(targetIndex, 0, movedQuestion)
|
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) => ({
|
const reorderData = newList.map((q, index) => ({
|
||||||
question_id: q.id,
|
question_id: q.id,
|
||||||
new_order: index
|
new_order: index
|
||||||
|
|||||||
Reference in New Issue
Block a user