удаление вопросов из списка правильно регулирует результаты

This commit is contained in:
Nastya 2023-12-28 19:09:54 +03:00
parent 237f7f5288
commit 6d2fd7da4f
11 changed files with 47 additions and 21 deletions

@ -128,8 +128,6 @@ function CsComponent({
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
}
@ -140,8 +138,6 @@ function CsComponent({
clearDataAfterAddNode({ parentNodeContentId, targetQuestion, parentNodeChildren })
cy?.data('changed', true)
createResult(quiz.backendId, targetQuestion.content.id)
console.log("Я собираюсь добавить узел из такого вопроса ", targetQuestion)
console.log("Я собираюсь добавить узел у которого папаша вот такой ", parentNodeContentId)
const es = cy?.add([
{
data: {

@ -229,7 +229,11 @@ export const usePopper = ({
updateOpenedModalSettingsId(item.id());
});
console.log("собираюсь анализировать папашу")
console.log("Тип папаши ", parentQuestion.type)
if (parentQuestion?.type === "date" || parentQuestion?.type === "text" || parentQuestion?.type === "number" || parentQuestion?.type === "page") {
console.log("Шестерня должна быть невидимая")
console.log("Тип папаши ", parentQuestion.type)
gearElement.classList.add("popper-gear-none");
}

@ -283,7 +283,6 @@ export default function ButtonsOptions({
sx={{ borderRadius: "6px", padding: "2px" }}
onClick={() => {
if (question.type === null) {
console.log("удаление безтипового")
deleteQuestion(question.id);
}
if (question.content.rule.parentId.length !== 0) {

@ -316,7 +316,6 @@ export default function ButtonsOptionsAndPict({
sx={{ borderRadius: "6px", padding: "2px" }}
onClick={() => {
if (question.type === null) {
console.log("удаление безтипового")
deleteQuestion(question.id);
}
if(question.content.rule.parentId.length !== 0) {

@ -278,7 +278,6 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging
}}
onClick={() => {
if (question.type === null) {
console.log("удаление безтипового")
deleteQuestion(question.id);
}
if (question.content.rule.parentId.length !== 0) {

@ -20,7 +20,6 @@ export const QuestionSwitchWindowTool = ({ openBranchingPage, setOpenBranchingPa
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down(600));
const quiz = useCurrentQuiz();
console.log("Я компонент в котором отвечала");
const openBranchingPageHC = () => {
if (!openBranchingPage) {

@ -187,8 +187,6 @@ export default function EditPage() {
}
};
console.log(quiz?.status);
return (
<>
{/*хедер*/}

@ -488,7 +488,6 @@ export const clearRuleForAll = () => {
|| question.content.rule.default.length > 0
|| question.content.rule.parentId.length > 0)
&& question.type !== "result") {
console.log("вызываю очистку рул вопросов")
updateQuestion(question.content.id, question => {
question.content.rule.parentId = "";
question.content.rule.main = [];
@ -510,8 +509,6 @@ export const createResult = async (
//Мы получили запрос на создание резулта. Анализируем существует ли такой. Если да - просто делаем его активным
const question = useQuestionsStore.getState().questions.find(q => q.type !== null && q?.content.rule.parentId === parentContentId)
console.log("Получил запрос на создание результа родителю ", parentContentId)
console.log("Ищу такой же результ в списке ", question)
if (question) {//существует, делаем активным
updateQuestion(question.id, (q) => {
@ -539,6 +536,7 @@ export const createResult = async (
type: "createBackResult",
createdQuestion,
});
return createdQuestion
} catch (error) {
devlog("Error creating question", error);
enqueueSnackbar("Не удалось создать вопрос");

@ -8,7 +8,6 @@ interface Props {
}
export default function Page({ question }: Props) {
console.log(question);
return (
<Box
sx={{

@ -1,5 +1,5 @@
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
import { clearRuleForAll, deleteQuestion, getQuestionByContentId, updateQuestion } from "@root/questions/actions";
import { clearRuleForAll, createResult, deleteQuestion, getQuestionByContentId, updateQuestion } from "@root/questions/actions";
import { updateRootContentId } from "@root/quizes/actions";
//Всё здесь нужно сделать последовательно. И пусть весь мир ждёт.
@ -11,11 +11,13 @@ export const DeleteFunction = async (questions: any, question: any, quiz: any) =
if (question.content.rule.parentId === "root") { //удалить из стора root и очистить rule всем вопросам
updateRootContentId(quiz.id, "");
await clearRuleForAll();
console.log("очистка рулов закончилась")
await deleteQuestion(question.id);
} else if (question.content.rule.parentId.length > 0) { //удалить из стора вопрос из дерева и очистить его потомков
const clearQuestions = [] as string[];
const parentQuestion = getQuestionByContentId(question.content.rule.parentId);
let startCountParentChildren = parentQuestion.content.rule.children
//записываем потомков , а их результаты удаляем
const getChildren = (parentQuestion: AnyTypedQuizQuestion) => {
questions.forEach((targetQuestion) => {
@ -41,18 +43,54 @@ export const DeleteFunction = async (questions: any, question: any, quiz: any) =
)
//чистим rule родителя
const parentQuestion = getQuestionByContentId(question.content.rule.parentId);
const newRule = {};
const parentChildren = [...parentQuestion.content.rule.children];
console.log("_________________УДАЛЯЕМЫЙ ВОПРОС_________________", question.content.id)
console.log(parentChildren)
console.log(question.content.id)
console.log(parentChildren.includes(question.content.id))
if (parentChildren.includes(question.content.id))
parentChildren.splice(parentQuestion.content.rule.children.indexOf(question.content.id), 1)
console.log("получившийся массив ", parentChildren)
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);
newRule.children = parentChildren
await updateQuestion(question.content.rule.parentId, (PQ) => {
PQ.content.rule = newRule;
});
await deleteQuestion(question.id);
const parentResult = questions.find(q => q.type === "result" && q.content.rule.parentId === parentQuestion.content.id)
//сделать результ родителя видимым если у него не осталось потомков
console.log("пришло время анализировать сделать ли результат родителя видимым")
console.log("количество детей ", startCountParentChildren.length)
if (startCountParentChildren.length === 1) {
if (parentResult) {
console.log("я нашел результат родителя")
await updateQuestion(parentResult.content.id, q => {
q.content.usage = true
})
} else { //почему-то не существует результа у родителя. Создаём. Новосозданные результы видны сразу
console.log("я не нашел результат родителя")
await createResult(quiz.backendId, parentQuestion.content.id)
}
}
}
await deleteQuestion(question.id);

@ -6,12 +6,10 @@ import { DeleteFunction } from "@utils/deleteFunc";
type allQuestionsTypes = AnyTypedQuizQuestion | UntypedQuizQuestion
export const deleteTimeoutedQuestions = async (questions: allQuestionsTypes[], quiz: Quiz|undefined) => {
console.log("Я отвечаю за удаление неудалёнышей при переключении. Привет, буде знакомы")
const questionsForDeletion = questions.filter(
({ type, deleted }) => type && type !== "result" && deleted
) as AnyTypedQuizQuestion[];
if (questionsForDeletion.length > 0) {
console.log("меняю занятость беком на true")
updateSomeWorkBackend(true)
@ -19,7 +17,6 @@ export const deleteTimeoutedQuestions = async (questions: allQuestionsTypes[], q
questionsForDeletion.map(question => DeleteFunction(questions, question, quiz))
)
console.log("______________меняю на 'можно редактировать дальше'______________")
updateSomeWorkBackend(false)
}
};