можно удалять корневой узел
This commit is contained in:
parent
e792c85771
commit
a15e697f91
@ -3,6 +3,7 @@ import Cytoscape from "cytoscape";
|
||||
import CytoscapeComponent from "react-cytoscapejs";
|
||||
import popper from "cytoscape-popper";
|
||||
import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||
import { updateRootInfo } from "@root/quizes/actions"
|
||||
import { AnyQuizQuestion } from "@model/questionTypes/shared"
|
||||
import { useQuestionsStore } from "@root/questions/store";
|
||||
import { cleardragQuestionContentId, getQuestionById, updateQuestion, updateOpenedModalSettingsId, getQuestionByContentId } from "@root/questions/actions";
|
||||
@ -174,27 +175,50 @@ useEffect(() =>{
|
||||
}
|
||||
|
||||
const removeNode = ({ targetNodeContentId }: { targetNodeContentId: string }) => {
|
||||
console.log("remove")
|
||||
const cy = cyRef?.current
|
||||
//
|
||||
const parentQuestion = cy?.$('edge[target = "' + targetNodeContentId + '"]').toArray()[0].data()
|
||||
const targetQuestion = cy?.$('#'+targetNodeContentId)?.data()
|
||||
|
||||
const targetQuestionContentId = cy?.$('#' + targetNodeContentId)?.data().id
|
||||
|
||||
if (targetQuestion && parentQuestion) {
|
||||
clearDataAfterRemoveNode({targetQuestionId: targetQuestion.id, parentQuestionId: parentQuestion.source})
|
||||
const a = getQuestionByContentId(targetNodeContentId)
|
||||
console.log(a)
|
||||
console.log(a)
|
||||
console.log(targetQuestionContentId)
|
||||
console.log(targetNodeContentId)
|
||||
|
||||
cy?.remove(cy?.$('#'+targetNodeContentId)).layout(lyopts).run()
|
||||
}
|
||||
}
|
||||
const clearDataAfterRemoveNode = ({targetQuestionId, parentQuestionId}:{targetQuestionId:string, parentQuestionId:string}) => {
|
||||
console.log({targetQuestionId, parentQuestionId})
|
||||
updateQuestion(targetQuestionId, question => {
|
||||
if (a.content.rule.parentId === "root" && quiz) {
|
||||
console.log("click ROOT")
|
||||
updateQuestion(targetQuestionContentId, question => {
|
||||
question.content.rule.parentId = ""
|
||||
question.content.rule.main = []
|
||||
question.content.rule.default = ""
|
||||
})
|
||||
updateQuestion(parentQuestionId, question => {
|
||||
if (question.content.rule.parentId === parentQuestionId) question.content.rule.parentId = ""
|
||||
updateRootInfo(quiz?.id, false)
|
||||
} else {
|
||||
console.log("click not ROOT")
|
||||
const parentQuestionContentId = cy?.$('edge[target = "' + targetNodeContentId + '"]')?.toArray()?.[0]?.data()?.source
|
||||
if (targetQuestionContentId && parentQuestionContentId) {
|
||||
|
||||
clearDataAfterRemoveNode({ targetQuestionContentId, parentQuestionContentId })
|
||||
cy?.remove(cy?.$('#' + targetNodeContentId)).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 => {
|
||||
if (question.content.rule.parentId === parentQuestionContentId) question.content.rule.parentId = ""
|
||||
})
|
||||
|
||||
}
|
||||
|
@ -438,10 +438,16 @@ export const getQuestionById = (questionId: string | null) => {
|
||||
return useQuestionsStore.getState().questions.find(q => q.id === questionId) || null;
|
||||
};
|
||||
export const getQuestionByContentId = (questionContentId: string | null) => {
|
||||
console.log("questionContentId " + questionContentId)
|
||||
if (questionContentId === null) return null;
|
||||
return useQuestionsStore.getState().questions.find(q => q.content.id === questionContentId) || null;
|
||||
return useQuestionsStore.getState().questions.find(q => {
|
||||
console.log(q.content.id)
|
||||
console.log(q.content.id === questionContentId)
|
||||
return ( q.content.id === questionContentId)}) || null;
|
||||
};
|
||||
|
||||
export const updateOpenedModalSettingsId = (id?: string) => useQuestionsStore.setState({openedModalSettingsId: id ? id : null});
|
||||
export const updateDragQuestionContentId = (contentId?: string) => useQuestionsStore.setState({dragQuestionContentId: contentId ? contentId : null});
|
||||
|
||||
export const updateDragQuestionContentId = (contentId?: string) => {
|
||||
console.log("contentId " + contentId)
|
||||
useQuestionsStore.setState({dragQuestionContentId: contentId ? contentId : null});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user