diff --git a/src/pages/Questions/BranchingMap/CsComponent.tsx b/src/pages/Questions/BranchingMap/CsComponent.tsx index 127af77d..7a1b2942 100644 --- a/src/pages/Questions/BranchingMap/CsComponent.tsx +++ b/src/pages/Questions/BranchingMap/CsComponent.tsx @@ -187,19 +187,31 @@ function CsComponent({ } 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 => { question.content.rule.parentId = parentNodeContentId 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] }) //Если детей больше 1 - предупреждаем стор вопросов об открытии модалки ветвления - if (parentNodeChildren >= 1) { + if (parentQuestion.content.rule.children >= 1) { updateOpenedModalSettingsId(targetQuestion.content.id) } } @@ -237,7 +249,7 @@ function CsComponent({ question.content.rule.children = [] question.content.rule.default = "" }) - questions.forEach(q => { + trashQuestions.forEach(q => { if (q.type === "result") { deleteQuestion(q.id); } @@ -266,6 +278,8 @@ function CsComponent({ question.content.rule.default = "" question.content.rule.children = [] }) + + }) deleteEdges.forEach((edge: any) => {//Грани @@ -277,10 +291,10 @@ function CsComponent({ cy?.layout(lyopts).run() //удаляем result всех потомков - questions.forEach((targetQuestion) => { - if (deleteNodes.includes(targetQuestion.content.rule.parentId)) { - if (targetQuestion.type === "result") { - deleteQuestion(targetQuestion.id); + trashQuestions.forEach((qr) => { + if (qr.type === "result") { + if (deleteNodes.includes(qr.content.rule.parentId) || qr.content.rule.parentId === targetQuestion.content.id) { + deleteQuestion(qr.id); } } }) @@ -299,13 +313,17 @@ function CsComponent({ question.content.rule.default = "" }) + //чистим rule родителя - const parentQuestion = getQuestionByContentId(targetQuestionContentId) + const parentQuestion = getQuestionByContentId(parentQuestionContentId) + console.log(parentQuestion.content.rule.parentId) 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.parentId = parentQuestion.content.rule.parentId - newRule.default = parentQuestion.content.rule.parentId === targetQuestionContentId ? "" : parentQuestion.content.rule.parentId - newRule.children = [...parentQuestion.content.rule.children].splice(parentQuestion.content.rule.children.indexOf(question.content.id), 1); + newRule.default = parentQuestion.content.rule.default === targetQuestionContentId ? "" : parentQuestion.content.rule.default + newRule.children = newChildren updateQuestion(parentQuestionContentId, (PQ) => { PQ.content.rule = newRule diff --git a/src/pages/Questions/DraggableList/QuestionPageCard.tsx b/src/pages/Questions/DraggableList/QuestionPageCard.tsx index 847cd16a..807c1132 100644 --- a/src/pages/Questions/DraggableList/QuestionPageCard.tsx +++ b/src/pages/Questions/DraggableList/QuestionPageCard.tsx @@ -262,12 +262,12 @@ console.log(question.type) if (question.content.rule.parentId === "root") { //удалить из стора root и очистить rule всем вопросам updateRootContentId(quiz.id, "") clearRuleForAll() + deleteQuestion(question.id); questions.forEach(q => { if (q.type === "result") { deleteQuestion(q.id); } }); - deleteQuestion(question.id); } else if (question.content.rule.parentId.length > 0) { //удалить из стора вопрос из дерева и очистить его потомков const clearQuestions = [] as string[] diff --git a/src/pages/ResultPage/FirstEntry.tsx b/src/pages/ResultPage/FirstEntry.tsx index 627dd200..c12968fb 100644 --- a/src/pages/ResultPage/FirstEntry.tsx +++ b/src/pages/ResultPage/FirstEntry.tsx @@ -16,12 +16,17 @@ export const FirstEntry = () => { const create = () => { if (quiz?.config.haveRoot) { + console.log("createFrontResult") 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 => { createFrontResult(quiz.id, question.content.id) }) } else { + console.log("createFrontResult") createFrontResult(quiz.id, "line") } } diff --git a/src/pages/ResultPage/ResultSettings.tsx b/src/pages/ResultPage/ResultSettings.tsx index 6b88ca27..bc4b66ef 100644 --- a/src/pages/ResultPage/ResultSettings.tsx +++ b/src/pages/ResultPage/ResultSettings.tsx @@ -21,14 +21,11 @@ export const ResultSettings = () => { const { questions } = useQuestionsStore() const quiz = useCurrentQuiz() const results = questions.filter((question: AnyTypedQuizQuestion) => question.type === "result") - console.log("опросник ", quiz) const [quizExpand, setQuizExpand] = useState(true) const [resultContract, setResultContract] = useState(true) const [readyLeave, setReadyLeave] = useState(true) - - const setAlertLeave = () => { if (readyLeave) setReadyLeave(false) console.log(readyLeave) @@ -36,7 +33,6 @@ export const ResultSettings = () => { useEffect(() => { return () => { - console.log(readyLeave) if (!readyLeave) alert("Пожалуйста, проверьте, что вы заполнили все результаты") } }, [readyLeave]) @@ -47,6 +43,7 @@ export const ResultSettings = () => { if (quiz?.config.haveRoot) { //проверяем, что в довесок к бековским результатам нам хватает фронтовых if (questions.length !== results.length) { + console.log("results", results) questions .forEach((q) => { if ( @@ -66,6 +63,13 @@ export const ResultSettings = () => { console.log("q.content.id", q.content.id) console.log("questions", questions) 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) + } }) }