frontPanel/src/pages/Questions/BranchingMap/helper.ts

35 lines
919 B
TypeScript
Raw Normal View History

2023-11-29 15:45:15 +00:00
import { AnyQuizQuestion } from "@model/questionTypes/shared"
interface Nodes {
data: {
id: string;
label: string;
}
}
interface Edges {
data: {
source: string;
target: string;
}
}
export const storeToNodes = (questions: AnyQuizQuestion[]) => {
2023-12-01 08:12:59 +00:00
console.log(questions)
2023-11-29 15:45:15 +00:00
const nodes: Nodes[] = []
const edges: Edges[] = []
questions.forEach((question) => {
2023-12-01 08:12:59 +00:00
console.log(question)
2023-11-29 15:45:15 +00:00
if (question.content.rule.parentId) {
nodes.push({data: {
id: question.id,
label: question.title ? question.title : "noname"
}})
if (question.content.rule.parentId !== "root") edges.push({data: {
source: question.content.rule.parentId,
target: question.id
}})
}
})
2023-12-01 08:12:59 +00:00
console.log([...nodes, ...edges])
2023-11-29 15:45:15 +00:00
return [...nodes, ...edges];
}