2023-12-03 13:09:57 +00:00
|
|
|
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared"
|
2023-11-29 15:45:15 +00:00
|
|
|
|
|
|
|
interface Nodes {
|
|
|
|
data: {
|
|
|
|
id: string;
|
|
|
|
label: string;
|
2023-12-02 09:59:31 +00:00
|
|
|
parent?: string;
|
2023-11-29 15:45:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
interface Edges {
|
|
|
|
data: {
|
|
|
|
source: string;
|
|
|
|
target: string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-03 13:09:57 +00:00
|
|
|
export const storeToNodes = (questions: AnyTypedQuizQuestion[]) => {
|
2023-11-29 15:45:15 +00:00
|
|
|
const nodes: Nodes[] = []
|
|
|
|
const edges: Edges[] = []
|
|
|
|
questions.forEach((question) => {
|
|
|
|
if (question.content.rule.parentId) {
|
|
|
|
nodes.push({data: {
|
2023-12-01 19:56:13 +00:00
|
|
|
id: question.content.id,
|
2023-11-29 15:45:15 +00:00
|
|
|
label: question.title ? question.title : "noname"
|
|
|
|
}})
|
2023-12-02 09:59:31 +00:00
|
|
|
// nodes.push({
|
|
|
|
// data: {
|
|
|
|
// id: "delete" + question.content.id,
|
|
|
|
// label: "X",
|
|
|
|
// parent: question.content.id,
|
|
|
|
// }
|
|
|
|
// },)
|
2023-11-29 15:45:15 +00:00
|
|
|
if (question.content.rule.parentId !== "root") edges.push({data: {
|
|
|
|
source: question.content.rule.parentId,
|
2023-12-01 19:56:13 +00:00
|
|
|
target: question.content.id
|
2023-11-29 15:45:15 +00:00
|
|
|
}})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return [...nodes, ...edges];
|
2023-12-02 09:59:31 +00:00
|
|
|
}
|