удаление резултов при удалении и добавлении узов (ошибка при удалении корневого вопроса)
This commit is contained in:
parent
9fa9e426d7
commit
efbc3384c5
@ -187,19 +187,31 @@ function CsComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const clearDataAfterAddNode = ({ parentNodeContentId, targetQuestion, parentNodeChildren }: { parentNodeContentId: string, targetQuestion: AnyTypedQuizQuestion, parentNodeChildren: number }) => {
|
const clearDataAfterAddNode = ({ parentNodeContentId, targetQuestion, parentNodeChildren }: { parentNodeContentId: string, targetQuestion: AnyTypedQuizQuestion, parentNodeChildren: number }) => {
|
||||||
|
|
||||||
|
const parentQuestion = { ...getQuestionByContentId(parentNodeContentId) } as AnyTypedQuizQuestion
|
||||||
|
|
||||||
|
|
||||||
|
//смотрим не добавлен ли родителю result. Если да - убираем его. Веточкам result не нужен
|
||||||
|
trashQuestions.forEach((targetQuestion) => {
|
||||||
|
if (targetQuestion.type === "result" && targetQuestion.content.rule.parentId === parentQuestion.content.id) {
|
||||||
|
deleteQuestion(targetQuestion.id);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
//предупреждаем добавленный вопрос о том, кто его родитель
|
//предупреждаем добавленный вопрос о том, кто его родитель
|
||||||
updateQuestion(targetQuestion.content.id, question => {
|
updateQuestion(targetQuestion.content.id, question => {
|
||||||
question.content.rule.parentId = parentNodeContentId
|
question.content.rule.parentId = parentNodeContentId
|
||||||
question.content.rule.main = []
|
question.content.rule.main = []
|
||||||
})
|
})
|
||||||
//предупреждаем родителя о новом потомке
|
//предупреждаем родителя о новом потомке (если он ещё не знает о нём)
|
||||||
updateQuestion(parentNodeContentId, question => {
|
if (!parentQuestion.content.rule.children.includes(targetQuestion.content.id)) updateQuestion(parentNodeContentId, question => {
|
||||||
question.content.rule.children = [...question.content.rule.children, targetQuestion.content.id]
|
question.content.rule.children = [...question.content.rule.children, targetQuestion.content.id]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
//Если детей больше 1 - предупреждаем стор вопросов об открытии модалки ветвления
|
//Если детей больше 1 - предупреждаем стор вопросов об открытии модалки ветвления
|
||||||
if (parentNodeChildren >= 1) {
|
if (parentQuestion.content.rule.children >= 1) {
|
||||||
updateOpenedModalSettingsId(targetQuestion.content.id)
|
updateOpenedModalSettingsId(targetQuestion.content.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,7 +249,7 @@ function CsComponent({
|
|||||||
question.content.rule.children = []
|
question.content.rule.children = []
|
||||||
question.content.rule.default = ""
|
question.content.rule.default = ""
|
||||||
})
|
})
|
||||||
questions.forEach(q => {
|
trashQuestions.forEach(q => {
|
||||||
if (q.type === "result") {
|
if (q.type === "result") {
|
||||||
deleteQuestion(q.id);
|
deleteQuestion(q.id);
|
||||||
}
|
}
|
||||||
@ -266,6 +278,8 @@ function CsComponent({
|
|||||||
question.content.rule.default = ""
|
question.content.rule.default = ""
|
||||||
question.content.rule.children = []
|
question.content.rule.children = []
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
deleteEdges.forEach((edge: any) => {//Грани
|
deleteEdges.forEach((edge: any) => {//Грани
|
||||||
@ -277,10 +291,10 @@ function CsComponent({
|
|||||||
cy?.layout(lyopts).run()
|
cy?.layout(lyopts).run()
|
||||||
|
|
||||||
//удаляем result всех потомков
|
//удаляем result всех потомков
|
||||||
questions.forEach((targetQuestion) => {
|
trashQuestions.forEach((qr) => {
|
||||||
if (deleteNodes.includes(targetQuestion.content.rule.parentId)) {
|
if (qr.type === "result") {
|
||||||
if (targetQuestion.type === "result") {
|
if (deleteNodes.includes(qr.content.rule.parentId) || qr.content.rule.parentId === targetQuestion.content.id) {
|
||||||
deleteQuestion(targetQuestion.id);
|
deleteQuestion(qr.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -299,13 +313,17 @@ function CsComponent({
|
|||||||
question.content.rule.default = ""
|
question.content.rule.default = ""
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
//чистим rule родителя
|
//чистим rule родителя
|
||||||
const parentQuestion = getQuestionByContentId(targetQuestionContentId)
|
const parentQuestion = getQuestionByContentId(parentQuestionContentId)
|
||||||
|
console.log(parentQuestion.content.rule.parentId)
|
||||||
const newRule = {}
|
const newRule = {}
|
||||||
|
const newChildren = [...parentQuestion.content.rule.children]
|
||||||
|
newChildren.splice(parentQuestion.content.rule.children.indexOf(targetQuestionContentId), 1);
|
||||||
newRule.main = parentQuestion.content.rule.main.filter((data) => data.next !== targetQuestionContentId) //удаляем условия перехода от родителя к этому вопросу
|
newRule.main = parentQuestion.content.rule.main.filter((data) => data.next !== targetQuestionContentId) //удаляем условия перехода от родителя к этому вопросу
|
||||||
newRule.parentId = parentQuestion.content.rule.parentId
|
newRule.parentId = parentQuestion.content.rule.parentId
|
||||||
newRule.default = parentQuestion.content.rule.parentId === targetQuestionContentId ? "" : parentQuestion.content.rule.parentId
|
newRule.default = parentQuestion.content.rule.default === targetQuestionContentId ? "" : parentQuestion.content.rule.default
|
||||||
newRule.children = [...parentQuestion.content.rule.children].splice(parentQuestion.content.rule.children.indexOf(question.content.id), 1);
|
newRule.children = newChildren
|
||||||
|
|
||||||
updateQuestion(parentQuestionContentId, (PQ) => {
|
updateQuestion(parentQuestionContentId, (PQ) => {
|
||||||
PQ.content.rule = newRule
|
PQ.content.rule = newRule
|
||||||
|
@ -262,12 +262,12 @@ console.log(question.type)
|
|||||||
if (question.content.rule.parentId === "root") { //удалить из стора root и очистить rule всем вопросам
|
if (question.content.rule.parentId === "root") { //удалить из стора root и очистить rule всем вопросам
|
||||||
updateRootContentId(quiz.id, "")
|
updateRootContentId(quiz.id, "")
|
||||||
clearRuleForAll()
|
clearRuleForAll()
|
||||||
|
deleteQuestion(question.id);
|
||||||
questions.forEach(q => {
|
questions.forEach(q => {
|
||||||
if (q.type === "result") {
|
if (q.type === "result") {
|
||||||
deleteQuestion(q.id);
|
deleteQuestion(q.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
deleteQuestion(question.id);
|
|
||||||
} else if (question.content.rule.parentId.length > 0) { //удалить из стора вопрос из дерева и очистить его потомков
|
} else if (question.content.rule.parentId.length > 0) { //удалить из стора вопрос из дерева и очистить его потомков
|
||||||
const clearQuestions = [] as string[]
|
const clearQuestions = [] as string[]
|
||||||
|
|
||||||
|
@ -16,12 +16,17 @@ export const FirstEntry = () => {
|
|||||||
|
|
||||||
const create = () => {
|
const create = () => {
|
||||||
if (quiz?.config.haveRoot) {
|
if (quiz?.config.haveRoot) {
|
||||||
|
console.log("createFrontResult")
|
||||||
questions
|
questions
|
||||||
.filter((question:AnyTypedQuizQuestion) => question.type !== null && question.content.rule.parentId.length !== 0 && question.content.rule.children.length === 0)
|
.filter((question:AnyTypedQuizQuestion) => {
|
||||||
|
console.log(question)
|
||||||
|
return question.type !== null && question.content.rule.parentId.length !== 0 && question.content.rule.children.length === 0
|
||||||
|
})
|
||||||
.forEach(question => {
|
.forEach(question => {
|
||||||
createFrontResult(quiz.id, question.content.id)
|
createFrontResult(quiz.id, question.content.id)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
console.log("createFrontResult")
|
||||||
createFrontResult(quiz.id, "line")
|
createFrontResult(quiz.id, "line")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,11 @@ export const ResultSettings = () => {
|
|||||||
const { questions } = useQuestionsStore()
|
const { questions } = useQuestionsStore()
|
||||||
const quiz = useCurrentQuiz()
|
const quiz = useCurrentQuiz()
|
||||||
const results = questions.filter((question: AnyTypedQuizQuestion) => question.type === "result")
|
const results = questions.filter((question: AnyTypedQuizQuestion) => question.type === "result")
|
||||||
console.log("опросник ", quiz)
|
|
||||||
const [quizExpand, setQuizExpand] = useState(true)
|
const [quizExpand, setQuizExpand] = useState(true)
|
||||||
const [resultContract, setResultContract] = useState(true)
|
const [resultContract, setResultContract] = useState(true)
|
||||||
const [readyLeave, setReadyLeave] = useState(true)
|
const [readyLeave, setReadyLeave] = useState(true)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const setAlertLeave = () => {
|
const setAlertLeave = () => {
|
||||||
if (readyLeave) setReadyLeave(false)
|
if (readyLeave) setReadyLeave(false)
|
||||||
console.log(readyLeave)
|
console.log(readyLeave)
|
||||||
@ -36,7 +33,6 @@ export const ResultSettings = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
console.log(readyLeave)
|
|
||||||
if (!readyLeave) alert("Пожалуйста, проверьте, что вы заполнили все результаты")
|
if (!readyLeave) alert("Пожалуйста, проверьте, что вы заполнили все результаты")
|
||||||
}
|
}
|
||||||
}, [readyLeave])
|
}, [readyLeave])
|
||||||
@ -47,6 +43,7 @@ export const ResultSettings = () => {
|
|||||||
if (quiz?.config.haveRoot) {
|
if (quiz?.config.haveRoot) {
|
||||||
//проверяем, что в довесок к бековским результатам нам хватает фронтовых
|
//проверяем, что в довесок к бековским результатам нам хватает фронтовых
|
||||||
if (questions.length !== results.length) {
|
if (questions.length !== results.length) {
|
||||||
|
console.log("results", results)
|
||||||
questions
|
questions
|
||||||
.forEach((q) => {
|
.forEach((q) => {
|
||||||
if (
|
if (
|
||||||
@ -66,6 +63,13 @@ export const ResultSettings = () => {
|
|||||||
console.log("q.content.id", q.content.id)
|
console.log("q.content.id", q.content.id)
|
||||||
console.log("questions", questions)
|
console.log("questions", questions)
|
||||||
createFrontResult(quiz.id, q.content.id)
|
createFrontResult(quiz.id, q.content.id)
|
||||||
|
} else {
|
||||||
|
console.log("НОВОГО РЕЗУЛЬТАТА НЕ БУДЕТ")
|
||||||
|
console.log(results)
|
||||||
|
console.log(results.includes(q.content.id))
|
||||||
|
console.log("q.content.id", q.content.id)
|
||||||
|
console.log("questions", questions)
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user