Merge branch 'fixQ' into dev
This commit is contained in:
commit
ce5fea6a7e
@ -125,9 +125,11 @@ function CsComponent({
|
|||||||
|
|
||||||
const parentQuestion = getQuestionByContentId(parentNodeContentId)
|
const parentQuestion = getQuestionByContentId(parentNodeContentId)
|
||||||
//Нельзя добавлять больше 1 ребёнка вопросам типа страница, ползунок, своё поле для ввода и дата
|
//Нельзя добавлять больше 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
|
&& 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 потомок")
|
enqueueSnackbar("у вопроса этого типа может быть только 1 потомок")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,13 @@ import {
|
|||||||
Typography,
|
Typography,
|
||||||
useTheme,
|
useTheme,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { changeQuestionType } from "@root/questions/actions";
|
import { changeQuestionType, updateQuestion } from "@root/questions/actions";
|
||||||
import type { RefObject } from "react";
|
import type { RefObject } from "react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import type { AnyTypedQuizQuestion, UntypedQuizQuestion } from "../../../model/questionTypes/shared";
|
import type { AnyTypedQuizQuestion, UntypedQuizQuestion } from "../../../model/questionTypes/shared";
|
||||||
import { BUTTON_TYPE_QUESTIONS } from "../TypeQuestions";
|
import { BUTTON_TYPE_QUESTIONS } from "../TypeQuestions";
|
||||||
|
import { useQuestionsStore } from "@root/questions/store";
|
||||||
|
import { updateSomeWorkBackend } from "@root/uiTools/actions";
|
||||||
|
|
||||||
|
|
||||||
type ChooseAnswerModalProps = {
|
type ChooseAnswerModalProps = {
|
||||||
@ -36,6 +38,7 @@ export const ChooseAnswerModal = ({
|
|||||||
}: ChooseAnswerModalProps) => {
|
}: ChooseAnswerModalProps) => {
|
||||||
const [openModal, setOpenModal] = useState<boolean>(false);
|
const [openModal, setOpenModal] = useState<boolean>(false);
|
||||||
const [selectedValue, setSelectedValue] = useState<QuestionType>("text");
|
const [selectedValue, setSelectedValue] = useState<QuestionType>("text");
|
||||||
|
const { questions } = useQuestionsStore()
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -94,8 +97,8 @@ export const ChooseAnswerModal = ({
|
|||||||
background: "#FFFFFF",
|
background: "#FFFFFF",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography variant="h6" sx={{textAlign: "center"}}>
|
<Typography variant="h6" sx={{ textAlign: "center" }}>
|
||||||
Все настройки, кроме заголовка вопроса будут сброшены <br/>
|
Все настройки, кроме заголовка вопроса будут сброшены <br />
|
||||||
(вопрос всё ещё будет участвовать в ветвлении, но его условия будут сброшены)
|
(вопрос всё ещё будет участвовать в ветвлении, но его условия будут сброшены)
|
||||||
</Typography>
|
</Typography>
|
||||||
<Box
|
<Box
|
||||||
@ -116,9 +119,44 @@ export const ChooseAnswerModal = ({
|
|||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
sx={{ minWidth: "150px" }}
|
sx={{ minWidth: "150px" }}
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
|
|
||||||
|
updateSomeWorkBackend(true)
|
||||||
setOpenModal(false);
|
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);
|
changeQuestionType(question.id, selectedValue);
|
||||||
|
updateSomeWorkBackend(false)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Подтвердить
|
Подтвердить
|
||||||
|
@ -40,6 +40,7 @@ import {
|
|||||||
updateCanCreatePublic,
|
updateCanCreatePublic,
|
||||||
updateModalInfoWhyCantCreate,
|
updateModalInfoWhyCantCreate,
|
||||||
setShowConfirmLeaveModal,
|
setShowConfirmLeaveModal,
|
||||||
|
updateSomeWorkBackend,
|
||||||
} from "@root/uiTools/actions";
|
} from "@root/uiTools/actions";
|
||||||
import { BranchingPanel } from "../Questions/BranchingPanel";
|
import { BranchingPanel } from "../Questions/BranchingPanel";
|
||||||
import { useQuestionsStore } from "@root/questions/store";
|
import { useQuestionsStore } from "@root/questions/store";
|
||||||
@ -123,6 +124,7 @@ export default function EditPage() {
|
|||||||
resetEditConfig();
|
resetEditConfig();
|
||||||
cleanQuestions();
|
cleanQuestions();
|
||||||
updateModalInfoWhyCantCreate(false);
|
updateModalInfoWhyCantCreate(false);
|
||||||
|
updateSomeWorkBackend(false)
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
@ -33,6 +33,7 @@ export const DeleteFunction = async (questions: any, question: any, quiz: any) =
|
|||||||
clearQuestions.map((id) => {
|
clearQuestions.map((id) => {
|
||||||
updateQuestion(id, question => {
|
updateQuestion(id, question => {
|
||||||
question.content.rule.parentId = "";
|
question.content.rule.parentId = "";
|
||||||
|
question.content.rule.children = [];
|
||||||
question.content.rule.main = [];
|
question.content.rule.main = [];
|
||||||
question.content.rule.default = "";
|
question.content.rule.default = "";
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user