корректное удаление коневого узла, безошибочное первое открытие модалки ветвления
This commit is contained in:
parent
7029c86f19
commit
cceafeb615
@ -30,7 +30,6 @@ async function getQuestionList(body?: Partial<GetQuestionListRequest>) {
|
||||
}
|
||||
|
||||
function editQuestion(body: EditQuestionRequest, signal?: AbortSignal) {
|
||||
console.log("`${baseUrl}/question/edit` start")
|
||||
return makeRequest<EditQuestionRequest, EditQuestionResponse>({
|
||||
url: `${baseUrl}/question/edit`,
|
||||
body,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -124,14 +124,12 @@ export const CsComponent = ({
|
||||
|
||||
useEffect(() => {
|
||||
if (modalQuestionTargetContentId.length !== 0 && modalQuestionParentContentId.length !== 0) {
|
||||
console.log("был выбран вопрос " + 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
|
||||
//если есть инфо о выбранном вопросе из модалки - берём родителя из инфо модалки. Иначе из значения дропа
|
||||
@ -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
|
||||
@ -181,7 +177,6 @@ export const CsComponent = ({
|
||||
const removeNode = ({ targetNodeContentId }: { targetNodeContentId: string }) => {
|
||||
const deleteNodes = [] as string[]
|
||||
const deleteEdges: any = []
|
||||
console.log("remove")
|
||||
const cy = cyRef?.current
|
||||
|
||||
const findChildrenToDelete = (node) => {
|
||||
@ -205,15 +200,13 @@ 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) {
|
||||
|
||||
@ -221,7 +214,8 @@ export const CsComponent = ({
|
||||
cy?.remove(cy?.$('#' + targetNodeContentId)).layout(lyopts).run()
|
||||
}
|
||||
|
||||
console.log(deleteNodes, deleteEdges)
|
||||
}
|
||||
|
||||
//После всех манипуляций удаляем грани из CS и ноды из бекенда
|
||||
|
||||
deleteNodes.forEach((nodeId) => {//Ноды
|
||||
@ -241,24 +235,14 @@ export const CsComponent = ({
|
||||
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,7 +266,6 @@ 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()
|
||||
@ -297,7 +280,6 @@ console.log(e.cy.data('firstNode'),"SKEEER",e.cy.data('changed'))
|
||||
//удаляем иконки
|
||||
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')
|
||||
const id = e.id()
|
||||
const incomming = e.cy().edges(`[target="${id}"]`)
|
||||
const layer = 0
|
||||
@ -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,7 +339,6 @@ 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 {
|
||||
@ -375,7 +353,6 @@ if (e.cy().data('firstNode') !== 'root') {
|
||||
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) }
|
||||
@ -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())
|
||||
});
|
||||
|
||||
|
||||
@ -14,14 +14,11 @@ export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetCon
|
||||
const { dragQuestionContentId } = useQuestionsStore()
|
||||
const Container = useRef<HTMLDivElement | null>(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")
|
||||
|
||||
@ -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];
|
||||
}
|
||||
|
||||
@ -32,33 +32,32 @@ export default function BranchingQuestions() {
|
||||
|
||||
const { openedModalSettingsId } = useQuestionsStore();
|
||||
const [targetQuestion, setTargetQuestion] = useState<AnyQuizQuestion | null>(getQuestionById(openedModalSettingsId) || getQuestionByContentId(openedModalSettingsId))
|
||||
console.log(targetQuestion)
|
||||
const [parentQuestion, setParentQuestion] = useState<AnyQuizQuestion | null>(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)
|
||||
}
|
||||
|
||||
@ -23,7 +23,6 @@ type AnyQuestion = UntypedQuizQuestion | AnyTypedQuizQuestion
|
||||
|
||||
export const QuestionsList = () => {
|
||||
const { questions } = useQuestionsStore()
|
||||
console.log(questions)
|
||||
|
||||
return (
|
||||
<Box sx={{ padding: "15px" }}>
|
||||
|
||||
@ -38,7 +38,6 @@ export const BranchingQuestionsModal = ({ openedModalQuestions, setOpenedModalQu
|
||||
>
|
||||
<Box sx={{ margin: "0 auto", maxWidth: "350px" }}>
|
||||
{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) => (
|
||||
<Button
|
||||
|
||||
@ -28,6 +28,7 @@ export default function QuestionsPage() {
|
||||
const [settingBranching, setSettingBranching] = useState<boolean>(false);
|
||||
if (!quiz) return null;
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<Box
|
||||
|
||||
Loading…
Reference in New Issue
Block a user