Merge branch 'fixQ' into dev

This commit is contained in:
Nastya 2023-12-28 00:31:30 +03:00
commit ce5fea6a7e
4 changed files with 48 additions and 5 deletions

@ -125,9 +125,11 @@ function CsComponent({
const parentQuestion = getQuestionByContentId(parentNodeContentId)
//Нельзя добавлять больше 1 ребёнка вопросам типа страница, ползунок, своё поле для ввода и дата
if (parentQuestion?.type === "date" || parentQuestion?.type === "text" || parentQuestion?.type === "number" || parentQuestion?.type === "page"
if ((parentQuestion?.type === "date" || parentQuestion?.type === "text" || parentQuestion?.type === "number" || parentQuestion?.type === "page")
&& parentQuestion.content.rule.children.length === 1
) {
console.log(parentQuestion.content.rule.children)
console.log("parentQuestion.content.rule.children.length === 1",parentQuestion.content.rule.children.length === 1)
enqueueSnackbar("у вопроса этого типа может быть только 1 потомок")
return
}

@ -12,11 +12,13 @@ import {
Typography,
useTheme,
} from "@mui/material";
import { changeQuestionType } from "@root/questions/actions";
import { changeQuestionType, updateQuestion } from "@root/questions/actions";
import type { RefObject } from "react";
import { useState } from "react";
import type { AnyTypedQuizQuestion, UntypedQuizQuestion } from "../../../model/questionTypes/shared";
import { BUTTON_TYPE_QUESTIONS } from "../TypeQuestions";
import { useQuestionsStore } from "@root/questions/store";
import { updateSomeWorkBackend } from "@root/uiTools/actions";
type ChooseAnswerModalProps = {
@ -36,6 +38,7 @@ export const ChooseAnswerModal = ({
}: ChooseAnswerModalProps) => {
const [openModal, setOpenModal] = useState<boolean>(false);
const [selectedValue, setSelectedValue] = useState<QuestionType>("text");
const { questions } = useQuestionsStore()
const theme = useTheme();
return (
@ -94,8 +97,8 @@ export const ChooseAnswerModal = ({
background: "#FFFFFF",
}}
>
<Typography variant="h6" sx={{textAlign: "center"}}>
Все настройки, кроме заголовка вопроса будут сброшены <br/>
<Typography variant="h6" sx={{ textAlign: "center" }}>
Все настройки, кроме заголовка вопроса будут сброшены <br />
(вопрос всё ещё будет участвовать в ветвлении, но его условия будут сброшены)
</Typography>
<Box
@ -116,9 +119,44 @@ export const ChooseAnswerModal = ({
<Button
variant="contained"
sx={{ minWidth: "150px" }}
onClick={() => {
onClick={async () => {
updateSomeWorkBackend(true)
setOpenModal(false);
const clearQuestions = [] as string[];
//записываем потомков , а их результаты удаляем
const getChildren = (parentQuestion: any) => {
questions.forEach((targetQuestion) => {
if (targetQuestion.type !== null && targetQuestion.content.rule.parentId === parentQuestion.content.id) {//если у вопроса совпал родитель с родителем => он потомок, в кучу его
if (targetQuestion.type !== "result" && targetQuestion.type !== null) {
if (!clearQuestions.includes(targetQuestion.content.id)) clearQuestions.push(targetQuestion.content.id);
getChildren(targetQuestion); //и ищем его потомков
}
}
});
};
getChildren(question);
updateQuestion(question.id, q => {
q.content.rule.parentId = "";
q.content.rule.main = [];
q.content.rule.children = [];
q.content.rule.default = "";
});
//чистим потомков от инфы ветвления
await Promise.allSettled(
clearQuestions.map((id) => {
updateQuestion(id, question => {
question.content.rule.parentId = "";
question.content.rule.main = [];
question.content.rule.children = [];
question.content.rule.default = "";
});
})
)
changeQuestionType(question.id, selectedValue);
updateSomeWorkBackend(false)
}}
>
Подтвердить

@ -40,6 +40,7 @@ import {
updateCanCreatePublic,
updateModalInfoWhyCantCreate,
setShowConfirmLeaveModal,
updateSomeWorkBackend,
} from "@root/uiTools/actions";
import { BranchingPanel } from "../Questions/BranchingPanel";
import { useQuestionsStore } from "@root/questions/store";
@ -123,6 +124,7 @@ export default function EditPage() {
resetEditConfig();
cleanQuestions();
updateModalInfoWhyCantCreate(false);
updateSomeWorkBackend(false)
},
[]
);

@ -33,6 +33,7 @@ export const DeleteFunction = async (questions: any, question: any, quiz: any) =
clearQuestions.map((id) => {
updateQuestion(id, question => {
question.content.rule.parentId = "";
question.content.rule.children = [];
question.content.rule.main = [];
question.content.rule.default = "";
});