From 25ce62509bb2bc1ca51b8c47af5eccbf17d86c99 Mon Sep 17 00:00:00 2001 From: Nastya Date: Mon, 4 Dec 2023 10:50:55 +0300 Subject: [PATCH 1/6] -- --- .../Questions/BranchingMap/CsComponent.tsx | 6 +++- .../BranchingQuestionsModal.tsx | 30 +++++++++---------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/pages/Questions/BranchingMap/CsComponent.tsx b/src/pages/Questions/BranchingMap/CsComponent.tsx index 6cdc66d9..d7c8e75f 100644 --- a/src/pages/Questions/BranchingMap/CsComponent.tsx +++ b/src/pages/Questions/BranchingMap/CsComponent.tsx @@ -684,10 +684,14 @@ if (e.cy().data('firstNode') !== 'root') { }} /> + ); diff --git a/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx b/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx index 0c140f52..ed16971d 100644 --- a/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx +++ b/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx @@ -38,20 +38,20 @@ export default function BranchingQuestions() { useLayoutEffect(() => { if (parentQuestion.content.rule.main.length === 0) updateQuestion(parentQuestion.id, question => question.content.rule.main.push({ - next: targetQuestion.content.id, - or: true, - rules: [{ - question: parentQuestion.content.id, - answers: [] - }] - })) + next: targetQuestion.content.id, + or: true, + rules: [{ + question: parentQuestion.content.id, + answers: [] + }] + })) }) - + if (targetQuestion === null || parentQuestion === null) { - console.log(openedModalSettingsId) + console.log(openedModalSettingsId) enqueueSnackbar("Невозможно найти данные ветвления для этого вопроса") return <> } @@ -59,7 +59,7 @@ export default function BranchingQuestions() { const saveData = () => { console.log(parentQuestion) if (parentQuestion !== null) { - updateQuestion(parentQuestion.content.id, question => question.content = parentQuestion.content) + updateQuestion(parentQuestion.content.id, question => question.content = parentQuestion.content) } handleClose() @@ -148,11 +148,11 @@ export default function BranchingQuestions() { marginBottom: "10px", cursor: "pointer" }} - onClick={() => { - const mutate = JSON.parse(JSON.stringify(parentQuestion)) - mutate.content.rule.main.push(createBranchingRuleMain(targetQuestion.content.id, parentQuestion.content.id)) - setParentQuestion(mutate) - }} + onClick={() => { + const mutate = JSON.parse(JSON.stringify(parentQuestion)) + mutate.content.rule.main.push(createBranchingRuleMain(targetQuestion.content.id, parentQuestion.content.id)) + setParentQuestion(mutate) + }} > Добавить условие From cceafeb61533430453b042f29c6a2926703f4456 Mon Sep 17 00:00:00 2001 From: Nastya Date: Mon, 4 Dec 2023 12:30:14 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BE=D0=BD=D0=B5=D0=B2=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D1=83=D0=B7=D0=BB=D0=B0,=20=D0=B1=D0=B5=D0=B7=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BE=D1=87=D0=BD=D0=BE=D0=B5=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B2=D0=BE=D0=B5=20=D0=BE=D1=82=D0=BA=D1=80=D1=8B=D1=82=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BC=D0=BE=D0=B4=D0=B0=D0=BB=D0=BA=D0=B8=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=82=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/question.ts | 1 - .../AnswerDraggableList/AnswerItem.tsx | 2 +- .../Questions/BranchingMap/CsComponent.tsx | 152 ++++++++---------- .../Questions/BranchingMap/FirstNodeField.tsx | 3 - src/pages/Questions/BranchingMap/helper.ts | 3 - .../BranchingQuestionsModal.tsx | 13 +- .../BranchingPanel/QuestionsList.tsx | 1 - .../BranchingQuestionsModal/index.tsx | 1 - src/pages/Questions/QuestionsPage.tsx | 1 + 9 files changed, 72 insertions(+), 105 deletions(-) diff --git a/src/api/question.ts b/src/api/question.ts index 0bae585f..56983d76 100644 --- a/src/api/question.ts +++ b/src/api/question.ts @@ -30,7 +30,6 @@ async function getQuestionList(body?: Partial) { } function editQuestion(body: EditQuestionRequest, signal?: AbortSignal) { - console.log("`${baseUrl}/question/edit` start") return makeRequest({ url: `${baseUrl}/question/edit`, body, diff --git a/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx b/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx index 6cb8562e..ac1e03c6 100644 --- a/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx +++ b/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx @@ -1,7 +1,7 @@ import { MessageIcon } from "@icons/messagIcon"; import { PointsIcon } from "@icons/questionsPage/PointsIcon"; import { DeleteIcon } from "@icons/questionsPage/deleteIcon"; -import { TextareaAutosize } from "@mui/base/TextareaAutosize"; +import TextareaAutosize from "@mui/base/TextareaAutosize"; import { Box, FormControl, diff --git a/src/pages/Questions/BranchingMap/CsComponent.tsx b/src/pages/Questions/BranchingMap/CsComponent.tsx index a99ada79..2b7db982 100644 --- a/src/pages/Questions/BranchingMap/CsComponent.tsx +++ b/src/pages/Questions/BranchingMap/CsComponent.tsx @@ -124,14 +124,12 @@ export const CsComponent = ({ useEffect(() => { if (modalQuestionTargetContentId.length !== 0 && modalQuestionParentContentId.length !== 0) { - console.log("был выбран вопрос " + modalQuestionTargetContentId) - addNode({ parentNodeContentId:modalQuestionParentContentId, targetNodeContentId:modalQuestionTargetContentId }) + addNode({ parentNodeContentId: modalQuestionParentContentId, targetNodeContentId: modalQuestionTargetContentId }) } }, [modalQuestionTargetContentId]) const addNode = ({ parentNodeContentId, targetNodeContentId }: { parentNodeContentId: string, targetNodeContentId?: string }) => { - console.log("dragQuestionContentId " + dragQuestionContentId) const cy = cyRef?.current const parentNodeChildren = cy?.$('edge[source = "' + parentNodeContentId + '"]')?.length //если есть инфо о выбранном вопросе из модалки - берём родителя из инфо модалки. Иначе из значения дропа @@ -139,7 +137,7 @@ export const CsComponent = ({ if (Object.keys(targetQuestion).length !== 0 && Object.keys(targetQuestion).length !== 0 && parentNodeContentId && parentNodeChildren !== undefined) { clearDataAfterAddNode({ parentNodeContentId, targetQuestion, parentNodeChildren }) - cy?.data('changed',true) + cy?.data('changed', true) cy?.add([ { data: { @@ -161,8 +159,6 @@ export const CsComponent = ({ } const clearDataAfterAddNode = ({ parentNodeContentId, targetQuestion, parentNodeChildren }: { parentNodeContentId: string, targetQuestion: AnyQuizQuestion, parentNodeChildren: number }) => { - console.log("записываю на бек ид родителя") - console.log({ parentNodeContentId, targetQuestion, parentNodeChildren }) //предупреждаем добавленный вопрос о том, кто его родитель updateQuestion(targetQuestion.content.id, question => { question.content.rule.parentId = parentNodeContentId @@ -179,9 +175,8 @@ export const CsComponent = ({ } const removeNode = ({ targetNodeContentId }: { targetNodeContentId: string }) => { - const deleteNodes = [] as string[] - const deleteEdges:any = [] - console.log("remove") + const deleteNodes = [] as string[] + const deleteEdges: any = [] const cy = cyRef?.current const findChildrenToDelete = (node) => { @@ -205,60 +200,49 @@ export const CsComponent = ({ const targetQuestion = getQuestionByContentId(targetNodeContentId) if (targetQuestion.content.rule.parentId === "root" && quiz) { - console.log("click ROOT") + updateRootContentId(quiz?.id, "") updateQuestion(targetNodeContentId, question => { question.content.rule.parentId = "" question.content.rule.main = [] question.content.rule.default = "" }) - updateRootContentId(quiz?.id, false) } else { - console.log("click not ROOT") const parentQuestionContentId = cy?.$('edge[target = "' + targetNodeContentId + '"]')?.toArray()?.[0]?.data()?.source if (targetNodeContentId && parentQuestionContentId) { - clearDataAfterRemoveNode({ targetQuestionContentId: targetNodeContentId, parentQuestionContentId }) - cy?.remove(cy?.$('#' + targetNodeContentId)).layout(lyopts).run() + clearDataAfterRemoveNode({ targetQuestionContentId: targetNodeContentId, parentQuestionContentId }) + cy?.remove(cy?.$('#' + targetNodeContentId)).layout(lyopts).run() } - console.log(deleteNodes, deleteEdges) - //После всех манипуляций удаляем грани из CS и ноды из бекенда - - deleteNodes.forEach((nodeId) => {//Ноды - cy?.remove(cy?.$("#" + nodeId)) - removeButtons(nodeId) - updateQuestion(nodeId, question => { - question.content.rule.parentId = "" - question.content.rule.main = [] - question.content.rule.default = "" - }) - }) - - deleteEdges.forEach((edge:any) => {//Грани - cy?.remove(edge) - }) - - removeButtons(targetNodeContentId) - cy?.data('changed',true) - cy?.layout(lyopts).run() - } + + //После всех манипуляций удаляем грани из CS и ноды из бекенда + + deleteNodes.forEach((nodeId) => {//Ноды + cy?.remove(cy?.$("#" + nodeId)) + removeButtons(nodeId) + updateQuestion(nodeId, question => { + question.content.rule.parentId = "" + question.content.rule.main = [] + question.content.rule.default = "" + }) + }) + + deleteEdges.forEach((edge: any) => {//Грани + cy?.remove(edge) + }) + + removeButtons(targetNodeContentId) + cy?.data('changed', true) + cy?.layout(lyopts).run() } const clearDataAfterRemoveNode = ({ targetQuestionContentId, parentQuestionContentId }: { targetQuestionContentId: string, parentQuestionContentId: string }) => { - - - - console.log({ targetQuestionContentId, parentQuestionContentId }) - updateQuestion(targetQuestionContentId, question => { question.content.rule.parentId = "" question.content.rule.main = [] question.content.rule.default = "" }) updateQuestion(parentQuestionContentId, question => { - console.log("parent default " + question.content.rule.default) - console.log("target ID " + targetQuestionContentId) - console.log(question.content.rule.default === targetQuestionContentId) if (question.content.rule.default === targetQuestionContentId) question.content.rule.default = "" }) @@ -282,22 +266,20 @@ export const CsComponent = ({ const readyLO = (e) => { -console.log(e.cy.data('firstNode'),"SKEEER",e.cy.data('changed')) if (e.cy.data('firstNode') === 'nonroot') { - e.cy.data('firstNode','root') - e.cy.nodes().sort((a,b) => (a.data('root')?1:-1)).layout(lyopts).run() - - } else { + e.cy.data('firstNode', 'root') + e.cy.nodes().sort((a, b) => (a.data('root') ? 1 : -1)).layout(lyopts).run() - - e.cy.data('changed', false) - e.cy.removeData('firstNode') - } + } else { + + + e.cy.data('changed', false) + e.cy.removeData('firstNode') + } //удаляем иконки e.cy.nodes().forEach((ele: any) => { const data = ele.data() - console.log(data) data.id && removeButtons(data.id); }) initialPopperIcons(e) @@ -307,11 +289,9 @@ console.log(e.cy.data('firstNode'),"SKEEER",e.cy.data('changed')) name: 'preset', positions: (e) => { - console.log('BBBBBBBBBBBBBBB', e.cy().data('changed')) if (!e.cy().data('changed')) { return e.data('oldPos') - } else {e.removeData('oldPos')} - console.log('POSITIIIIIIIONS') + } else { e.removeData('oldPos') } const id = e.id() const incomming = e.cy().edges(`[target="${id}"]`) const layer = 0 @@ -319,7 +299,7 @@ console.log(e.cy.data('firstNode'),"SKEEER",e.cy.data('changed')) if (incomming.length === 0) { if (e.cy().data('firstNode') === undefined) - e.cy().data('firstNode','root') + e.cy().data('firstNode', 'root') e.data('root', true) const children = e.cy().edges(`[source="${id}"]`).targets() e.data('layer', layer) @@ -341,7 +321,6 @@ console.log(e.cy.data('firstNode'),"SKEEER",e.cy.data('changed')) queue.push({ parent: e, children: children }) while (queue.length) { const task = queue.pop() -console.log('WIIIING',task.parent.data(),task.children.length) if (task.children.length === 0) { task.parent.data('subtreeWidth', task.parent.height()) continue @@ -360,22 +339,20 @@ console.log('WIIIING',task.parent.data(),task.children.length) task?.parent.data('subtreeWidth', task.children.reduce((p, n) => p + n.data('subtreeWidth'), 0)) } const pos = { x: 0, y: 0 } - console.log(e.data()) e.data('oldPos', pos) return pos } else { -if (e.cy().data('firstNode') !== 'root') { - e.cy().data('firstNode','nonroot') - return {x:0,y:0} + if (e.cy().data('firstNode') !== 'root') { + e.cy().data('firstNode', 'nonroot') + return { x: 0, y: 0 } } if (e.cy().data('firstNode') === undefined) - e.cy().data('firstNode','nonroot') + e.cy().data('firstNode', 'nonroot') const parent = e.cy().edges(`[target="${e.id()}"]`)[0].source() const wing = (parent.data('children') === 1) ? 0 : parent.data('subtreeWidth') / 2 + 50 const lastOffset = parent.data('lastChild') const step = wing * 2 / (parent.data('children') - 1) //e.removeData('subtreeWidth') - console.log('AAAAAAAAAAa', e.data(), lastOffset, step, parent.position().y, wing) if (lastOffset !== undefined) { parent.data('lastChild', lastOffset + step) const pos = { x: 250 * e.data('layer'), y: (lastOffset + step) } @@ -386,7 +363,7 @@ if (e.cy().data('firstNode') !== 'root') { const pos = { x: 250 * e.data('layer'), y: (parent.position().y - wing) } e.data('oldPos', pos) return pos - } + } } }, // map of (node id) => (position obj); or function(node){ return somPos; } zoom: undefined, // the zoom level to set (prob want fit = false if set) @@ -502,7 +479,7 @@ if (e.cy().data('firstNode') !== 'root') { layoutElement.classList.add("popper-layout"); layoutElement.setAttribute("data-id", item.id()); layoutElement.addEventListener("mouseup", () => { - //Узнаём грани, идущие от этой ноды + //Узнаём грани, идущие от этой ноды setModalQuestionParentContentId(item.id()) setOpenedModalQuestions(true) }); @@ -533,7 +510,7 @@ if (e.cy().data('firstNode') !== 'root') { plusElement.addEventListener("mouseup", () => { setStartCreate(node.id()); }); - + plusesContainer.current?.appendChild(plusElement); return plusElement; @@ -594,7 +571,6 @@ if (e.cy().data('firstNode') !== 'root') { gearElement.style.zIndex = "1" gearsContainer.current?.appendChild(gearElement); gearElement.addEventListener("mouseup", (e) => { - console.log(item.id()) updateOpenedModalSettingsId(item.id()) }); @@ -672,27 +648,27 @@ if (e.cy().data('firstNode') !== 'root') { return ( <> - { - cyRef.current = cy; - }} - /> - - + + }}>elements ); }; diff --git a/src/pages/Questions/BranchingMap/FirstNodeField.tsx b/src/pages/Questions/BranchingMap/FirstNodeField.tsx index 3ae599d7..16c789e6 100644 --- a/src/pages/Questions/BranchingMap/FirstNodeField.tsx +++ b/src/pages/Questions/BranchingMap/FirstNodeField.tsx @@ -14,14 +14,11 @@ export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetCon const { dragQuestionContentId } = useQuestionsStore() const Container = useRef(null); const quiz = useCurrentQuiz(); - console.log(dragQuestionContentId) const modalOpen = () => setOpenedModalQuestions(true) const newRootNode = () => { if (quiz) { - console.log(dragQuestionContentId) - if (dragQuestionContentId) { updateRootContentId(quiz?.id, dragQuestionContentId) updateQuestion(dragQuestionContentId, (question) => question.content.rule.parentId = "root") diff --git a/src/pages/Questions/BranchingMap/helper.ts b/src/pages/Questions/BranchingMap/helper.ts index 9a335c27..049b44d6 100644 --- a/src/pages/Questions/BranchingMap/helper.ts +++ b/src/pages/Questions/BranchingMap/helper.ts @@ -15,11 +15,9 @@ interface Edges { } export const storeToNodes = (questions: AnyQuizQuestion[]) => { - console.log(questions) const nodes: Nodes[] = [] const edges: Edges[] = [] questions.forEach((question) => { - console.log(question) if (question.content.rule.parentId) { nodes.push({data: { id: question.content.id, @@ -38,6 +36,5 @@ export const storeToNodes = (questions: AnyQuizQuestion[]) => { }}) } }) - console.log([...nodes, ...edges]) return [...nodes, ...edges]; } diff --git a/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx b/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx index b352dc66..017816f3 100644 --- a/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx +++ b/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx @@ -32,33 +32,32 @@ export default function BranchingQuestions() { const { openedModalSettingsId } = useQuestionsStore(); const [targetQuestion, setTargetQuestion] = useState(getQuestionById(openedModalSettingsId) || getQuestionByContentId(openedModalSettingsId)) - console.log(targetQuestion) const [parentQuestion, setParentQuestion] = useState(getQuestionByContentId(targetQuestion?.content.rule.parentId)) - console.log(parentQuestion) useLayoutEffect(() => { if (parentQuestion === null) return - if (parentQuestion.content.rule.main.length === 0) updateQuestion(parentQuestion.id, question => question.content.rule.main.push({ + if (parentQuestion.content.rule.main.length === 0) { + let mutate = JSON.parse(JSON.stringify(parentQuestion)) + mutate.content.rule.main = [{ next: targetQuestion.content.id, or: true, rules: [{ question: parentQuestion.content.id, answers: [] }] - })) + }] + setParentQuestion(mutate) + } }) if (targetQuestion === null || parentQuestion === null) { - - console.log(openedModalSettingsId) enqueueSnackbar("Невозможно найти данные ветвления для этого вопроса") return <> } const saveData = () => { - console.log(parentQuestion) if (parentQuestion !== null) { updateQuestion(parentQuestion.content.id, question => question.content = parentQuestion.content) } diff --git a/src/pages/Questions/BranchingPanel/QuestionsList.tsx b/src/pages/Questions/BranchingPanel/QuestionsList.tsx index 62896cad..dfde30c6 100644 --- a/src/pages/Questions/BranchingPanel/QuestionsList.tsx +++ b/src/pages/Questions/BranchingPanel/QuestionsList.tsx @@ -23,7 +23,6 @@ type AnyQuestion = UntypedQuizQuestion | AnyTypedQuizQuestion export const QuestionsList = () => { const { questions } = useQuestionsStore() - console.log(questions) return ( diff --git a/src/pages/Questions/BranchingQuestionsModal/index.tsx b/src/pages/Questions/BranchingQuestionsModal/index.tsx index 1dfdbee3..9099e3f9 100644 --- a/src/pages/Questions/BranchingQuestionsModal/index.tsx +++ b/src/pages/Questions/BranchingQuestionsModal/index.tsx @@ -38,7 +38,6 @@ export const BranchingQuestionsModal = ({ openedModalQuestions, setOpenedModalQu > {questions.filter((q:AnyQuestion) => { -console.log(q.content) if (q.content === null) return true return (q.type && !q.content.rule.parentId)}).map((question: AnyTypedQuizQuestion, index:number) => (