From 3f95f32ec90917014d6e11239e50a600eb99171a Mon Sep 17 00:00:00 2001 From: Nastya Date: Thu, 28 Dec 2023 00:51:20 +0300 Subject: [PATCH 1/9] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B1=D0=B5=D0=B7=D1=82=D0=B8=D0=BF=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=B2=D0=BE=D0=BF=D1=80=D0=BE=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Questions/ButtonsOptions.tsx | 230 +++++++++--------- src/pages/Questions/ButtonsOptionsAndPict.tsx | 4 + .../DraggableList/QuestionPageCard.tsx | 208 ++++++++-------- src/utils/deleteFunc.ts | 2 - 4 files changed, 227 insertions(+), 217 deletions(-) diff --git a/src/pages/Questions/ButtonsOptions.tsx b/src/pages/Questions/ButtonsOptions.tsx index f6eba2ac..caeab9d1 100644 --- a/src/pages/Questions/ButtonsOptions.tsx +++ b/src/pages/Questions/ButtonsOptions.tsx @@ -26,7 +26,7 @@ import { useQuestionsStore } from "@root/questions/store"; import { updateOpenedModalSettingsId } from "@root/uiTools/actions"; import { updateRootContentId } from "@root/quizes/actions"; import { useUiTools } from "@root/uiTools/store"; -import {useState} from "react"; +import { useState } from "react"; import { updateSomeWorkBackend } from "@root/uiTools/actions"; import { DeleteFunction } from "@utils/deleteFunc"; @@ -118,116 +118,116 @@ export default function ButtonsOptions({ > {buttonSetting.map(({ icon, title, value, myFunc }) => ( - {value === "branching" ? - question.type === "page" || question.type === "text" || question.type === "date" || question.type === "number" ? - <> - : - ( - // - // - // Будет показан при условии - // - // - // Название - // - // - // Условие 1, Условие 2 - // - // - // Все условия обязательны - // - // - // } - // > - { - openedModal(); - // SSHC(value); - // myFunc(question); - }} - sx={{ - display: quiz.config.type === "form" ? "none" : "flex", - backgroundColor: - switchState === value - ? theme.palette.brightPurple.main - : "transparent", - color: - switchState === value - ? "#ffffff" - : theme.palette.grey3.main, - minWidth: isWrappMiniButtonSetting ? "30px" : "64px", - height: "30px", - "&:hover": { - color: theme.palette.grey3.main, - "& path": { stroke: theme.palette.grey3.main }, - }, - }} - > - {icon} - {isWrappMiniButtonSetting ? null : title} - - // - ) : ( - <> - { - SSHC(value); - myFunc(); - }} - sx={{ - backgroundColor: - switchState === value - ? theme.palette.brightPurple.main - : "transparent", - color: - switchState === value - ? "#ffffff" - : theme.palette.grey3.main, - minWidth: isWrappMiniButtonSetting ? "30px" : "64px", - height: "30px", - "&:hover": { - color: theme.palette.grey3.main, - "& path": { stroke: theme.palette.grey3.main }, - }, - }} - > - {icon} - {isWrappMiniButtonSetting ? null : title} - - - )} + {value === "branching" ? + question.type === "page" || question.type === "text" || question.type === "date" || question.type === "number" ? + <> + : + ( + // + // + // Будет показан при условии + // + // + // Название + // + // + // Условие 1, Условие 2 + // + // + // Все условия обязательны + // + // + // } + // > + { + openedModal(); + // SSHC(value); + // myFunc(question); + }} + sx={{ + display: quiz.config.type === "form" ? "none" : "flex", + backgroundColor: + switchState === value + ? theme.palette.brightPurple.main + : "transparent", + color: + switchState === value + ? "#ffffff" + : theme.palette.grey3.main, + minWidth: isWrappMiniButtonSetting ? "30px" : "64px", + height: "30px", + "&:hover": { + color: theme.palette.grey3.main, + "& path": { stroke: theme.palette.grey3.main }, + }, + }} + > + {icon} + {isWrappMiniButtonSetting ? null : title} + + // + ) : ( + <> + { + SSHC(value); + myFunc(); + }} + sx={{ + backgroundColor: + switchState === value + ? theme.palette.brightPurple.main + : "transparent", + color: + switchState === value + ? "#ffffff" + : theme.palette.grey3.main, + minWidth: isWrappMiniButtonSetting ? "30px" : "64px", + height: "30px", + "&:hover": { + color: theme.palette.grey3.main, + "& path": { stroke: theme.palette.grey3.main }, + }, + }} + > + {icon} + {isWrappMiniButtonSetting ? null : title} + + + )} ))} {/* <> @@ -282,7 +282,11 @@ export default function ButtonsOptions({ { - if(question.content.rule.parentId.length !== 0) { + if (question.type === null) { + console.log("удаление безтипового") + deleteQuestion(question.id); + } + if (question.content.rule.parentId.length !== 0) { setOpenDelete(true) } else { deleteQuestionWithTimeout(question.id, () => DeleteFunction(questions, question, quiz)); @@ -305,7 +309,7 @@ export default function ButtonsOptions({ background: "#FFFFFF", }} > - + Вы удаляете вопрос, участвующий в ветвлении. Все его потомки потеряют данные ветвления. Вы уверены, что хотите удалить вопрос? { + if (question.type === null) { + console.log("удаление безтипового") + deleteQuestion(question.id); + } if(question.content.rule.parentId.length !== 0) { setOpenDelete(true) } else { diff --git a/src/pages/Questions/DraggableList/QuestionPageCard.tsx b/src/pages/Questions/DraggableList/QuestionPageCard.tsx index eb5e4830..6315b5de 100644 --- a/src/pages/Questions/DraggableList/QuestionPageCard.tsx +++ b/src/pages/Questions/DraggableList/QuestionPageCard.tsx @@ -59,35 +59,35 @@ import { updateSomeWorkBackend } from "@root/uiTools/actions"; import { DeleteFunction } from "@utils/deleteFunc"; interface Props { - question: AnyTypedQuizQuestion | UntypedQuizQuestion; - draggableProps: DraggableProvidedDragHandleProps | null | undefined; - isDragging: boolean; - index: number; + question: AnyTypedQuizQuestion | UntypedQuizQuestion; + draggableProps: DraggableProvidedDragHandleProps | null | undefined; + isDragging: boolean; + index: number; } export default function QuestionsPageCard({ question, draggableProps, isDragging, index }: Props) { -const maxLengthTextField = 225; + const maxLengthTextField = 225; - const { questions } = useQuestionsStore(); - const [plusVisible, setPlusVisible] = useState(false); - const [open, setOpen] = useState(false); + const { questions } = useQuestionsStore(); + const [plusVisible, setPlusVisible] = useState(false); + const [open, setOpen] = useState(false); const [isTextFieldtActive, setIsTextFieldtActive] = useState(false); - const [openDelete, setOpenDelete] = useState(false); - const theme = useTheme(); - const isTablet = useMediaQuery(theme.breakpoints.down(1000)); - const isMobile = useMediaQuery(theme.breakpoints.down(790)); - const anchorRef = useRef(null); - const quiz = useCurrentQuiz(); + const [openDelete, setOpenDelete] = useState(false); + const theme = useTheme(); + const isTablet = useMediaQuery(theme.breakpoints.down(1000)); + const isMobile = useMediaQuery(theme.breakpoints.down(790)); + const anchorRef = useRef(null); + const quiz = useCurrentQuiz(); - const setTitle = useDebouncedCallback((title) => { - const updateQuestionFn = question.type === null ? updateUntypedQuestion : updateQuestion; + const setTitle = useDebouncedCallback((title) => { + const updateQuestionFn = question.type === null ? updateUntypedQuestion : updateQuestion; - updateQuestionFn(question.id, question => { - question.title = title; - }); - }, 200); + updateQuestionFn(question.id, question => { + question.title = title; + }); + }, 200); const handleInputFocus = () => { setIsTextFieldtActive(true); @@ -98,7 +98,7 @@ const maxLengthTextField = 225; }; - return ( + return ( <> { + if (question.type === null) { + console.log("удаление безтипового") + deleteQuestion(question.id); + } if (question.content.rule.parentId.length !== 0) { setOpenDelete(true); } else { @@ -417,85 +421,85 @@ const maxLengthTextField = 225; } const IconAndrom = (isExpanded: boolean, questionType: QuestionType | null) => { - switch (questionType) { - case "variant": - return ( - - ); - case "images": - return ( - - ); - case "varimg": - return ( - - ); - case "emoji": - return ( - - ); - case "text": - return ( - - ); - case "select": - return ( - - ); - case "date": - return ( - - ); - case "number": - return ( - - ); - case "file": - return ( - - ); - case "page": - return ( - - ); - case "rating": - return ( - - ); - default: - return <>; - } + switch (questionType) { + case "variant": + return ( + + ); + case "images": + return ( + + ); + case "varimg": + return ( + + ); + case "emoji": + return ( + + ); + case "text": + return ( + + ); + case "select": + return ( + + ); + case "date": + return ( + + ); + case "number": + return ( + + ); + case "file": + return ( + + ); + case "page": + return ( + + ); + case "rating": + return ( + + ); + default: + return <>; + } }; diff --git a/src/utils/deleteFunc.ts b/src/utils/deleteFunc.ts index 27098b9d..abe57e85 100644 --- a/src/utils/deleteFunc.ts +++ b/src/utils/deleteFunc.ts @@ -60,8 +60,6 @@ export const DeleteFunction = async (questions: any, question: any, quiz: any) = const result = questions.find(q => q.type === "result" && q.content.rule.parentId === question.content.id) if (result) await deleteQuestion(result.id); - } else { - await deleteQuestion(question.id); } } \ No newline at end of file From 237f7f52884f0849858684948c3360e937d3dddd Mon Sep 17 00:00:00 2001 From: Nastya Date: Thu, 28 Dec 2023 02:28:44 +0300 Subject: [PATCH 2/9] =?UTF-8?q?=D0=BE=D0=B1=D1=8F=D0=B7=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B2=D1=8B=D0=B1?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=20=D1=81=D1=82=D0=B0=D1=80=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=BE=D0=B9=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B?= =?UTF-8?q?=20=D1=83=20=D0=BA=D0=B2=D0=B8=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/startPage/EditPage.tsx | 2 +- src/pages/startPage/ModalInfoWhyCantCreate.tsx | 2 +- src/utils/checkQuestionHint.ts | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pages/startPage/EditPage.tsx b/src/pages/startPage/EditPage.tsx index 397c6f17..61528276 100755 --- a/src/pages/startPage/EditPage.tsx +++ b/src/pages/startPage/EditPage.tsx @@ -130,7 +130,7 @@ export default function EditPage() { ); const updateQuestionHint = useDebouncedCallback((questions: AnyTypedQuizQuestion[]) => { - const problems = checkQuestionHint(questions); + const problems = checkQuestionHint(questions, quiz); useUiTools.setState({ whyCantCreatePublic: problems }); if (Object.keys(problems).length > 0) { updateQuiz(quiz?.id, (state) => { diff --git a/src/pages/startPage/ModalInfoWhyCantCreate.tsx b/src/pages/startPage/ModalInfoWhyCantCreate.tsx index 51ea68a1..57c98c7c 100644 --- a/src/pages/startPage/ModalInfoWhyCantCreate.tsx +++ b/src/pages/startPage/ModalInfoWhyCantCreate.tsx @@ -30,7 +30,7 @@ export const ModalInfoWhyCantCreate = () => { {Object.values(whyCantCreatePublic).map((data) => { return ( - У вопроса "{data.name}" + {data.name === "quiz" ? "У квиза" : `У вопроса "${data.name}"`} {data.problems.map((problem) => ( {problem} ))} diff --git a/src/utils/checkQuestionHint.ts b/src/utils/checkQuestionHint.ts index 51a19eb1..95378457 100644 --- a/src/utils/checkQuestionHint.ts +++ b/src/utils/checkQuestionHint.ts @@ -1,11 +1,14 @@ import { AnyTypedQuizQuestion, QuestionBranchingRuleMain } from "@model/questionTypes/shared"; import { WhyCantCreatePublic } from "@root/uiTools/store"; import { getQuestionByContentId, updateQuestion } from "@root/questions/actions"; +import { Quiz } from "@model/quiz/quiz"; -export const checkQuestionHint = (questions: AnyTypedQuizQuestion): Record => { +export const checkQuestionHint = (questions: AnyTypedQuizQuestion, quiz:Quiz): Record => { const problems: any = {} + if (quiz.config.startpageType === null) problems.quiz = {name: "quiz", problems: ["Не выбран тип стартовой страницы"]} + const pushProblem = (id: string, problem: string, title: string) => { //Если первый вопрос с проблемой - создаём запись. Если не первый - добавляем проблему if (id in problems) { From 327bb657f4de302a7ecf421ab44bd18329d7f26d Mon Sep 17 00:00:00 2001 From: IlyaDoronin Date: Thu, 28 Dec 2023 13:07:50 +0300 Subject: [PATCH 3/9] feat: replaceSpacesToEmptyLines --- src/api/question.ts | 3 ++- src/utils/replaceSpacesToEmptyLines.ts | 29 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/utils/replaceSpacesToEmptyLines.ts diff --git a/src/api/question.ts b/src/api/question.ts index 56983d76..74a46745 100644 --- a/src/api/question.ts +++ b/src/api/question.ts @@ -5,6 +5,7 @@ import { GetQuestionListRequest, GetQuestionListResponse } from "@model/question import { EditQuestionRequest, EditQuestionResponse } from "@model/question/edit"; import { DeleteQuestionRequest, DeleteQuestionResponse } from "@model/question/delete"; import { CopyQuestionRequest, CopyQuestionResponse } from "@model/question/copy"; +import { replaceSpacesToEmptyLines } from "../utils/replaceSpacesToEmptyLines"; const baseUrl = process.env.NODE_ENV === "production" ? "/squiz" : "https://squiz.pena.digital/squiz"; @@ -26,7 +27,7 @@ async function getQuestionList(body?: Partial) { method: "POST", }); - return response.items; + return replaceSpacesToEmptyLines(response.items); } function editQuestion(body: EditQuestionRequest, signal?: AbortSignal) { diff --git a/src/utils/replaceSpacesToEmptyLines.ts b/src/utils/replaceSpacesToEmptyLines.ts new file mode 100644 index 00000000..e6310b3b --- /dev/null +++ b/src/utils/replaceSpacesToEmptyLines.ts @@ -0,0 +1,29 @@ +export const replaceSpacesToEmptyLines = (object: T): T => { + if (Array.isArray(object)) { + return object.map(replaceSpacesToEmptyLines) as T; + } + + if (!object || typeof object !== "object") { + return object; + } + + const result: Record = {}; + + for (const [key, value] of Object.entries(object)) { + if (typeof value === "string") { + result[key] = value.replace(/ /g, ""); + + continue; + } + + if (typeof value === "object") { + result[key] = replaceSpacesToEmptyLines(value); + + continue; + } + + result[key] = value; + } + + return result as T; +}; From 5b29c42ac1c6fcbc61ab733c0c4bd122defb8689 Mon Sep 17 00:00:00 2001 From: IlyaDoronin Date: Thu, 28 Dec 2023 15:54:04 +0300 Subject: [PATCH 4/9] feat: replaceEmptyLinesToSpace --- src/stores/questions/actions.ts | 3 ++- src/utils/replaceEmptyLinesToSpace.ts | 33 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/utils/replaceEmptyLinesToSpace.ts diff --git a/src/stores/questions/actions.ts b/src/stores/questions/actions.ts index a5dcd65c..eac65731 100644 --- a/src/stores/questions/actions.ts +++ b/src/stores/questions/actions.ts @@ -16,6 +16,7 @@ import { QuestionsStore, useQuestionsStore } from "./store"; import { useUiTools } from "../uiTools/store"; import { withErrorBoundary } from "react-error-boundary"; import { QuizQuestionResult } from "@model/questionTypes/result"; +import { replaceEmptyLinesToSpace } from "../../utils/replaceEmptyLinesToSpace"; export const setQuestions = (questions: RawQuestion[] | null) => setProducedState(state => { @@ -202,7 +203,7 @@ export const updateQuestion = async ( if (q.type === null) throw new Error("Cannot send update request for untyped question"); try { - const response = await questionApi.edit(questionToEditQuestionRequest(q)); + const response = await questionApi.edit(questionToEditQuestionRequest(replaceEmptyLinesToSpace(q))); //Если мы делаем листочек веточкой - удаляем созданный к нему результ const questionResult = useQuestionsStore.getState().questions.find(questionResult => questionResult.type === "result" && questionResult.content.rule.parentId === q.content.id); diff --git a/src/utils/replaceEmptyLinesToSpace.ts b/src/utils/replaceEmptyLinesToSpace.ts new file mode 100644 index 00000000..0ac97782 --- /dev/null +++ b/src/utils/replaceEmptyLinesToSpace.ts @@ -0,0 +1,33 @@ +export const replaceEmptyLinesToSpace = (object: T): T => { + if (Array.isArray(object)) { + return object.map(replaceEmptyLinesToSpace) as T; + } + + if (!object || typeof object !== "object") { + return object; + } + + const result: Record = {}; + + for (const [key, value] of Object.entries(object)) { + if (typeof value === "string") { + if (value === "") { + result[key] = " "; + } else { + result[key] = value; + } + + continue; + } + + if (typeof value === "object") { + result[key] = replaceEmptyLinesToSpace(value); + + continue; + } + + result[key] = value; + } + + return result as T; +}; From ceaab812a687d7e6935f502ef3c0f2876adb0def Mon Sep 17 00:00:00 2001 From: IlyaDoronin Date: Thu, 28 Dec 2023 17:10:21 +0300 Subject: [PATCH 5/9] fix: publication result logic --- src/pages/ViewPublicationPage/ResultForm.tsx | 113 ++++++++++--------- 1 file changed, 60 insertions(+), 53 deletions(-) diff --git a/src/pages/ViewPublicationPage/ResultForm.tsx b/src/pages/ViewPublicationPage/ResultForm.tsx index fffc3c18..8520f828 100644 --- a/src/pages/ViewPublicationPage/ResultForm.tsx +++ b/src/pages/ViewPublicationPage/ResultForm.tsx @@ -5,9 +5,9 @@ import { useCurrentQuiz } from "@root/quizes/hooks"; import { useQuestionsStore } from "@root/questions/store"; import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared"; -import YoutubeEmbedIframe from "../../ui_kit/StartPagePreview/YoutubeEmbedIframe.tsx" +import YoutubeEmbedIframe from "../../ui_kit/StartPagePreview/YoutubeEmbedIframe.tsx"; import { NameplateLogo } from "@icons/NameplateLogo"; -import {modes} from "../../utils/themes/Publication/themePublication"; +import { modes } from "../../utils/themes/Publication/themePublication"; type ResultFormProps = { currentQuestion: AnyTypedQuizQuestion; @@ -21,25 +21,25 @@ export const ResultForm = ({ showContactForm, setShowContactForm, setShowResultForm, - }: ResultFormProps) => { const quiz = useCurrentQuiz(); const mode = modes; const { questions } = useQuestionsStore(); - const resultQuestion = questions.find( + const resultQuestion = (questions.find( (question) => question.type === "result" && - (question.content.rule.parentId === "line" || currentQuestion.content.id) - ); - - - + question.content.rule.parentId === currentQuestion.content.id + ) || + questions.find( + (question) => + question.type === "result" && question.content.rule.parentId === "line" + )) as AnyTypedQuizQuestion; const followNextForm = () => { setShowResultForm(false); setShowContactForm(true); }; - if (resultQuestion === undefined) return <> + if (resultQuestion === undefined) return <>; return ( - - { - !resultQuestion?.content.useImage && - resultQuestion.content.video && + {!resultQuestion?.content.useImage && resultQuestion.content.video && ( - } - { - resultQuestion?.content.useImage && - resultQuestion.content.back && + )} + {resultQuestion?.content.useImage && resultQuestion.content.back && ( - - } - {resultQuestion.description !== "" && resultQuestion.description !== " " && {resultQuestion.description}} + > + )} + {resultQuestion.description !== "" && + resultQuestion.description !== " " && ( + + {resultQuestion.description} + + )} {resultQuestion.title || "Форма результатов"} + > + {resultQuestion.title || "Форма результатов"} - {resultQuestion.content.text !== "" && resultQuestion.content.text !== " " && {resultQuestion.content.text}} - - + {resultQuestion.content.text !== "" && + resultQuestion.content.text !== " " && ( + + {resultQuestion.content.text} + + )} @@ -117,24 +120,30 @@ export const ResultForm = ({ display: "flex", width: "100%", justifyContent: "end", - px: "20px" + px: "20px", }} > - Сделано на PenaQuiz + + Сделано на PenaQuiz + - - { - quiz?.config.resultInfo.when === "before" && + {quiz?.config.resultInfo.when === "before" && ( <> - } + )} - - ); }; From 6d2fd7da4f997fea771dc4873db577e9d85706dd Mon Sep 17 00:00:00 2001 From: Nastya Date: Thu, 28 Dec 2023 19:09:54 +0300 Subject: [PATCH 6/9] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B2=D0=BE=D0=BF=D1=80=D0=BE=D1=81=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B8=D0=B7=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D1=8C=D0=BD=D0=BE=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B3=D1=83=D0=BB=D0=B8=D1=80=D1=83=D0=B5=D1=82=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Questions/BranchingMap/CsComponent.tsx | 4 -- .../Questions/BranchingMap/hooks/usePopper.ts | 4 ++ src/pages/Questions/ButtonsOptions.tsx | 1 - src/pages/Questions/ButtonsOptionsAndPict.tsx | 1 - .../DraggableList/QuestionPageCard.tsx | 1 - .../Questions/QuestionSwitchWindowTool.tsx | 1 - src/pages/startPage/EditPage.tsx | 2 - src/stores/questions/actions.ts | 4 +- .../QuizPreviewQuestionTypes/Page.tsx | 1 - src/utils/deleteFunc.ts | 46 +++++++++++++++++-- src/utils/deleteTimeoutedQuestions.ts | 3 -- 11 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/pages/Questions/BranchingMap/CsComponent.tsx b/src/pages/Questions/BranchingMap/CsComponent.tsx index 3ecb1118..bee882cd 100644 --- a/src/pages/Questions/BranchingMap/CsComponent.tsx +++ b/src/pages/Questions/BranchingMap/CsComponent.tsx @@ -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: { diff --git a/src/pages/Questions/BranchingMap/hooks/usePopper.ts b/src/pages/Questions/BranchingMap/hooks/usePopper.ts index b022755a..de2a078b 100644 --- a/src/pages/Questions/BranchingMap/hooks/usePopper.ts +++ b/src/pages/Questions/BranchingMap/hooks/usePopper.ts @@ -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"); } diff --git a/src/pages/Questions/ButtonsOptions.tsx b/src/pages/Questions/ButtonsOptions.tsx index caeab9d1..7ab1b537 100644 --- a/src/pages/Questions/ButtonsOptions.tsx +++ b/src/pages/Questions/ButtonsOptions.tsx @@ -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) { diff --git a/src/pages/Questions/ButtonsOptionsAndPict.tsx b/src/pages/Questions/ButtonsOptionsAndPict.tsx index f29225f5..01a4da9e 100644 --- a/src/pages/Questions/ButtonsOptionsAndPict.tsx +++ b/src/pages/Questions/ButtonsOptionsAndPict.tsx @@ -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) { diff --git a/src/pages/Questions/DraggableList/QuestionPageCard.tsx b/src/pages/Questions/DraggableList/QuestionPageCard.tsx index 6315b5de..bdcaf1c4 100644 --- a/src/pages/Questions/DraggableList/QuestionPageCard.tsx +++ b/src/pages/Questions/DraggableList/QuestionPageCard.tsx @@ -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) { diff --git a/src/pages/Questions/QuestionSwitchWindowTool.tsx b/src/pages/Questions/QuestionSwitchWindowTool.tsx index e60f50ca..a56d3bd2 100644 --- a/src/pages/Questions/QuestionSwitchWindowTool.tsx +++ b/src/pages/Questions/QuestionSwitchWindowTool.tsx @@ -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) { diff --git a/src/pages/startPage/EditPage.tsx b/src/pages/startPage/EditPage.tsx index 61528276..7ca5e54e 100755 --- a/src/pages/startPage/EditPage.tsx +++ b/src/pages/startPage/EditPage.tsx @@ -187,8 +187,6 @@ export default function EditPage() { } }; - console.log(quiz?.status); - return ( <> {/*хедер*/} diff --git a/src/stores/questions/actions.ts b/src/stores/questions/actions.ts index a5dcd65c..58dd2347 100644 --- a/src/stores/questions/actions.ts +++ b/src/stores/questions/actions.ts @@ -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("Не удалось создать вопрос"); diff --git a/src/ui_kit/QuizPreview/QuizPreviewQuestionTypes/Page.tsx b/src/ui_kit/QuizPreview/QuizPreviewQuestionTypes/Page.tsx index 1f4559e1..bae35d8b 100644 --- a/src/ui_kit/QuizPreview/QuizPreviewQuestionTypes/Page.tsx +++ b/src/ui_kit/QuizPreview/QuizPreviewQuestionTypes/Page.tsx @@ -8,7 +8,6 @@ interface Props { } export default function Page({ question }: Props) { - console.log(question); return ( 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); diff --git a/src/utils/deleteTimeoutedQuestions.ts b/src/utils/deleteTimeoutedQuestions.ts index 19c18322..134faafb 100644 --- a/src/utils/deleteTimeoutedQuestions.ts +++ b/src/utils/deleteTimeoutedQuestions.ts @@ -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) } }; \ No newline at end of file From 2deae1bab2a3f386ae559402a8d3ed567b06e4f3 Mon Sep 17 00:00:00 2001 From: Nastya Date: Thu, 28 Dec 2023 19:34:23 +0300 Subject: [PATCH 7/9] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=BE=D0=B4=20=D0=BD=D0=BE=D1=80=D0=BC=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE=20=D1=80=D0=B5=D0=B3=D1=83=D0=BB=D0=B8?= =?UTF-8?q?=D1=80=D1=83=D0=B5=D1=82=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=82?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Questions/BranchingMap/hooks/useRemoveNode.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pages/Questions/BranchingMap/hooks/useRemoveNode.ts b/src/pages/Questions/BranchingMap/hooks/useRemoveNode.ts index 60997905..2c293147 100644 --- a/src/pages/Questions/BranchingMap/hooks/useRemoveNode.ts +++ b/src/pages/Questions/BranchingMap/hooks/useRemoveNode.ts @@ -72,8 +72,8 @@ export const useRemoveNode = ({ //Ищём родителя const parentQuestion = getQuestionByContentId(parentQuestionContentId); - - //Делаем результат родителя активным + if (parentQuestion.content.rule.children.length === 1) { //если у родителя больше нет потомков + //Делаем результат родителя активным const parentResult = trashQuestions.find(q => q.type === "result" && q.content.rule.parentId === parentQuestionContentId) if (parentResult) { updateQuestion(parentResult.content.id, q => { @@ -83,6 +83,9 @@ export const useRemoveNode = ({ createResult(quiz?.backendId, parentQuestionContentId) } + } + + //чистим rule родителя if (!parentQuestion?.type) { return; From b76d8ee3e9cba6c272e7e1bdb81cc31b5f704fea Mon Sep 17 00:00:00 2001 From: Nastya Date: Thu, 28 Dec 2023 20:10:38 +0300 Subject: [PATCH 8/9] =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D0=BE=D0=B2=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D0=BE=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=87=D0=B5=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Questions/AnswerDraggableList/AnswerItem.tsx | 8 ++++---- src/utils/hooks/useAddAnswer.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx b/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx index 841728a8..da351340 100644 --- a/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx +++ b/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx @@ -82,11 +82,11 @@ export const AnswerItem = ({ setQuestionVariantAnswer(target.value || " "); }} onKeyDown={(event: KeyboardEvent) => { - if (disableKeyDown) { - enqueueSnackbar("100 максимальное количество вопросов"); - } else if (event.code === "Enter" && !largeCheck) { + // if (disableKeyDown) { + // enqueueSnackbar("100 максимальное количество вопросов"); + // } else if (event.code === "Enter" && !largeCheck) { addQuestionVariant(questionId); - } + // } }} InputProps={{ startAdornment: ( diff --git a/src/utils/hooks/useAddAnswer.ts b/src/utils/hooks/useAddAnswer.ts index e73cb096..d37c1e6a 100644 --- a/src/utils/hooks/useAddAnswer.ts +++ b/src/utils/hooks/useAddAnswer.ts @@ -6,11 +6,11 @@ export const useAddAnswer = () => { const { enqueueSnackbar } = useSnackbar(); const onClickAddAnAnswer = (question: QuizQuestionsWithVariants) => { - if (question.content.variants.length >= 10) { - enqueueSnackbar("100 максимальное количество вопросов"); - } else { + // if (question.content.variants.length >= 10) { + // enqueueSnackbar("100 максимальное количество вопросов"); + // } else { addQuestionVariant(question.id); - } + // } }; return onClickAddAnAnswer; From 3bbf8343c2e1adba014baf97286c0a76f5560ba1 Mon Sep 17 00:00:00 2001 From: Nastya Date: Thu, 28 Dec 2023 23:08:41 +0300 Subject: [PATCH 9/9] =?UTF-8?q?=D0=BF=D1=80=D0=B5=D0=B2=D1=8C=D1=8E=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D1=83=D1=87=D0=B8=D1=82=D1=8B=D0=B2=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Questions/BranchingMap/CsComponent.tsx | 7 +++++- src/pages/startPage/EditPage.tsx | 8 ++++++- .../startPage/ModalInfoWhyCantCreate.tsx | 8 +++++++ src/pages/startPage/StartPageSettings.tsx | 23 ++++++++++--------- src/ui_kit/CustomTextField.tsx | 10 +++++++- src/ui_kit/QuizPreview/QuizPreviewLayout.tsx | 4 ++-- 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/pages/Questions/BranchingMap/CsComponent.tsx b/src/pages/Questions/BranchingMap/CsComponent.tsx index bee882cd..c2cb3168 100644 --- a/src/pages/Questions/BranchingMap/CsComponent.tsx +++ b/src/pages/Questions/BranchingMap/CsComponent.tsx @@ -264,7 +264,12 @@ function CsComponent({ return ( <> + sx={{ + mb:"20px", + display:'flex', + justifyContent:"space-between" + }} + >