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

41 lines
1.1 KiB
TypeScript
Raw Normal View History

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;
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: {
id: question.content.id,
label: question.title === "" || question.title === " " ? "noname" : question.title
2023-11-29 15:45:15 +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,
target: question.content.id
2023-11-29 15:45:15 +00:00
}})
}
})
return [...nodes, ...edges];
}