56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
|
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[]) => {
|
||
|
const nodes: Nodes[] = []
|
||
|
const edges: Edges[] = []
|
||
|
questions.forEach((question) => {
|
||
|
if (question.content.rule.parentId) {
|
||
|
nodes.push({data: {
|
||
|
id: question.id,
|
||
|
label: question.title ? question.title : "noname"
|
||
|
}})
|
||
|
nodes.push({data:{
|
||
|
id: "111",
|
||
|
label: "111"
|
||
|
}})
|
||
|
nodes.push({data:{
|
||
|
id: "222",
|
||
|
label: "222"
|
||
|
}})
|
||
|
edges.push({data: {
|
||
|
source: question.id,
|
||
|
target: "111"
|
||
|
}})
|
||
|
nodes.push({data:{
|
||
|
id: "333",
|
||
|
label: "333"
|
||
|
}})
|
||
|
edges.push({data: {
|
||
|
source: "111",
|
||
|
target: "333"
|
||
|
}})
|
||
|
edges.push({data: {
|
||
|
source: question.id,
|
||
|
target: "222"
|
||
|
}})
|
||
|
if (question.content.rule.parentId !== "root") edges.push({data: {
|
||
|
source: question.content.rule.parentId,
|
||
|
target: question.id
|
||
|
}})
|
||
|
}
|
||
|
})
|
||
|
return [...nodes, ...edges];
|
||
|
}
|