fix: force remove questions
This commit is contained in:
parent
372300ead9
commit
3584d32820
@ -58,7 +58,7 @@ function CsComponent({
|
|||||||
|
|
||||||
const { dragQuestionContentId, desireToOpenABranchingModal, canCreatePublic } = useUiTools()
|
const { dragQuestionContentId, desireToOpenABranchingModal, canCreatePublic } = useUiTools()
|
||||||
const trashQuestions = useQuestionsStore().questions
|
const trashQuestions = useQuestionsStore().questions
|
||||||
const questions = trashQuestions.filter((question) => question.type !== "result" && question.type !== null)
|
const questions = trashQuestions.filter((question) => question.type !== "result" && question.type !== null && !question.deleted)
|
||||||
const [startCreate, setStartCreate] = useState("");
|
const [startCreate, setStartCreate] = useState("");
|
||||||
const [startRemove, setStartRemove] = useState("");
|
const [startRemove, setStartRemove] = useState("");
|
||||||
|
|
||||||
|
@ -1,26 +1,135 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
import {
|
import { Box, useMediaQuery, useTheme } from "@mui/material";
|
||||||
Box, useMediaQuery, useTheme,
|
|
||||||
} from "@mui/material";
|
|
||||||
import { DraggableList } from "./DraggableList";
|
import { DraggableList } from "./DraggableList";
|
||||||
import { SwitchBranchingPanel } from "./SwitchBranchingPanel";
|
import { SwitchBranchingPanel } from "./SwitchBranchingPanel";
|
||||||
import { BranchingMap } from "./BranchingMap";
|
import { BranchingMap } from "./BranchingMap";
|
||||||
import {useQuestionsStore} from "@root/questions/store";
|
import { useQuestionsStore } from "@root/questions/store";
|
||||||
import { useUiTools } from "@root/uiTools/store";
|
import { useUiTools } from "@root/uiTools/store";
|
||||||
|
import { useQuestions } from "@root/questions/hooks";
|
||||||
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||||
|
|
||||||
|
import {
|
||||||
|
copyQuestion,
|
||||||
|
deleteQuestion,
|
||||||
|
deleteQuestionWithTimeout,
|
||||||
|
clearRuleForAll,
|
||||||
|
updateQuestion,
|
||||||
|
getQuestionByContentId,
|
||||||
|
} from "@root/questions/actions";
|
||||||
|
import { updateRootContentId } from "@root/quizes/actions";
|
||||||
|
|
||||||
|
import type { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
||||||
|
|
||||||
export const QuestionSwitchWindowTool = () => {
|
export const QuestionSwitchWindowTool = () => {
|
||||||
const {questions} = useQuestionsStore.getState()
|
const { questions } = useQuestionsStore.getState();
|
||||||
const {openBranchingPanel} = useUiTools()
|
const { openBranchingPanel } = useUiTools();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down(600));
|
const isMobile = useMediaQuery(theme.breakpoints.down(600));
|
||||||
return (
|
const quiz = useCurrentQuiz();
|
||||||
<Box sx={{ display: "flex", gap: "20px", flexWrap: "wrap", marginBottom: isMobile ? "20px" : undefined }}>
|
|
||||||
<Box sx={{ flexBasis: "796px" }}>
|
const deleteFn = (question: AnyTypedQuizQuestion) => {
|
||||||
{openBranchingPanel? <BranchingMap /> : <DraggableList />}
|
if (question.type !== null) {
|
||||||
</Box>
|
if (question.content.rule.parentId === "root") {
|
||||||
<SwitchBranchingPanel
|
//удалить из стора root и очистить rule всем вопросам
|
||||||
/>
|
updateRootContentId(quiz?.id || "", "");
|
||||||
</Box>
|
clearRuleForAll();
|
||||||
)
|
deleteQuestion(question.id);
|
||||||
}
|
} else if (question.content.rule.parentId.length > 0) {
|
||||||
|
//удалить из стора вопрос из дерева и очистить его потомков
|
||||||
|
const clearQuestions = [] as string[];
|
||||||
|
|
||||||
|
//записываем потомков , а их результаты удаляем
|
||||||
|
const getChildren = (parentQuestion: AnyTypedQuizQuestion) => {
|
||||||
|
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);
|
||||||
|
//чистим потомков от инфы ветвления
|
||||||
|
clearQuestions.forEach((id) => {
|
||||||
|
updateQuestion(id, (question) => {
|
||||||
|
question.content.rule.parentId = "";
|
||||||
|
question.content.rule.main = [];
|
||||||
|
question.content.rule.default = "";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//чистим rule родителя
|
||||||
|
const parentQuestion = getQuestionByContentId(
|
||||||
|
question.content.rule.parentId
|
||||||
|
);
|
||||||
|
const newRule = {};
|
||||||
|
newRule.main = parentQuestion.content.rule.main.filter(
|
||||||
|
(data) => data.next !== question.content.id
|
||||||
|
); //удаляем условия перехода от родителя к этому вопросу
|
||||||
|
newRule.parentId = parentQuestion.content.rule.parentId;
|
||||||
|
newRule.default =
|
||||||
|
parentQuestion.content.rule.parentId === question.content.id
|
||||||
|
? ""
|
||||||
|
: parentQuestion.content.rule.parentId;
|
||||||
|
newRule.children = [...parentQuestion.content.rule.children].splice(
|
||||||
|
parentQuestion.content.rule.children.indexOf(question.content.id),
|
||||||
|
1
|
||||||
|
);
|
||||||
|
|
||||||
|
updateQuestion(question.content.rule.parentId, (PQ) => {
|
||||||
|
PQ.content.rule = newRule;
|
||||||
|
});
|
||||||
|
deleteQuestion(question.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteQuestion(question.id);
|
||||||
|
|
||||||
|
const result = questions.find(
|
||||||
|
(q) =>
|
||||||
|
q.type === "result" && q.content.rule.parentId === question.content.id
|
||||||
|
);
|
||||||
|
if (result) deleteQuestion(result.id);
|
||||||
|
} else {
|
||||||
|
deleteQuestion(question.id);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteTimeoutedQuestions = () => {
|
||||||
|
const questionsForDeletion = questions.filter(
|
||||||
|
({ type, deleted }) => type && type !== "result" && deleted
|
||||||
|
) as AnyTypedQuizQuestion[];
|
||||||
|
|
||||||
|
questionsForDeletion.forEach(deleteFn);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (openBranchingPanel) {
|
||||||
|
deleteTimeoutedQuestions();
|
||||||
|
}
|
||||||
|
}, [openBranchingPanel]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
gap: "20px",
|
||||||
|
flexWrap: "wrap",
|
||||||
|
marginBottom: isMobile ? "20px" : undefined,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box sx={{ flexBasis: "796px" }}>
|
||||||
|
{openBranchingPanel ? <BranchingMap /> : <DraggableList />}
|
||||||
|
</Box>
|
||||||
|
<SwitchBranchingPanel />
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
@ -1,23 +1,27 @@
|
|||||||
|
import {
|
||||||
|
Box,
|
||||||
import {Box, Typography, Switch, useTheme, Button, useMediaQuery} from "@mui/material";
|
Typography,
|
||||||
|
Switch,
|
||||||
|
useTheme,
|
||||||
|
Button,
|
||||||
|
useMediaQuery,
|
||||||
|
} from "@mui/material";
|
||||||
|
|
||||||
import { QuestionsList } from "./QuestionsList";
|
import { QuestionsList } from "./QuestionsList";
|
||||||
import { updateOpenBranchingPanel } from "@root/uiTools/actions";
|
import { updateOpenBranchingPanel } from "@root/uiTools/actions";
|
||||||
import {useQuestionsStore} from "@root/questions/store";
|
import { useQuestionsStore } from "@root/questions/store";
|
||||||
import {useRef} from "react";
|
import { useRef } from "react";
|
||||||
import { useUiTools } from "@root/uiTools/store";
|
import { useUiTools } from "@root/uiTools/store";
|
||||||
|
|
||||||
|
|
||||||
export const SwitchBranchingPanel = () => {
|
export const SwitchBranchingPanel = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
||||||
const isTablet = useMediaQuery(theme.breakpoints.down(1446));
|
const isTablet = useMediaQuery(theme.breakpoints.down(1446));
|
||||||
|
const { openBranchingPanel } = useUiTools();
|
||||||
const {openBranchingPanel} = useUiTools()
|
const ref = useRef();
|
||||||
const ref = useRef()
|
|
||||||
|
return !isTablet || openBranchingPanel ? (
|
||||||
return ( !isTablet || openBranchingPanel ?
|
|
||||||
<Box sx={{ userSelect: "none", maxWidth: "350px", width: "100%" }}>
|
<Box sx={{ userSelect: "none", maxWidth: "350px", width: "100%" }}>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@ -31,10 +35,10 @@ export const SwitchBranchingPanel = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Switch
|
<Switch
|
||||||
checked={openBranchingPanel}
|
checked={openBranchingPanel}
|
||||||
onChange={
|
onChange={({ target }) => {
|
||||||
(e) => updateOpenBranchingPanel(e.target.checked)
|
updateOpenBranchingPanel(target.checked);
|
||||||
}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
width: 50,
|
width: 50,
|
||||||
height: 30,
|
height: 30,
|
||||||
@ -87,11 +91,10 @@ export const SwitchBranchingPanel = () => {
|
|||||||
Настройте связи между вопросами
|
Настройте связи между вопросами
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
{ openBranchingPanel && <QuestionsList /> }
|
{openBranchingPanel && <QuestionsList />}
|
||||||
</Box>
|
</Box>
|
||||||
:
|
) : (
|
||||||
<></>
|
<></>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user