2023-12-31 02:53:25 +00:00
|
|
|
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
2024-01-13 16:04:05 +00:00
|
|
|
import { nameCutter } from "./nameCutter";
|
2023-11-29 15:45:15 +00:00
|
|
|
|
|
|
|
interface Nodes {
|
2023-12-31 02:53:25 +00:00
|
|
|
data: {
|
|
|
|
id: string;
|
|
|
|
label: string;
|
|
|
|
parent?: string;
|
|
|
|
};
|
2023-11-29 15:45:15 +00:00
|
|
|
}
|
|
|
|
interface Edges {
|
2023-12-31 02:53:25 +00:00
|
|
|
data: {
|
|
|
|
source: string;
|
|
|
|
target: string;
|
|
|
|
};
|
2023-11-29 15:45:15 +00:00
|
|
|
}
|
|
|
|
|
2023-12-03 13:09:57 +00:00
|
|
|
export const storeToNodes = (questions: AnyTypedQuizQuestion[]) => {
|
2023-12-31 02:53:25 +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.page
|
2024-01-13 16:04:05 +00:00
|
|
|
: nameCutter(question.title),
|
2023-12-31 02:53:25 +00:00
|
|
|
parentType: question.content.rule.parentId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
// nodes.push({
|
|
|
|
// data: {
|
|
|
|
// id: "delete" + question.content.id,
|
|
|
|
// label: "X",
|
|
|
|
// parent: question.content.id,
|
|
|
|
// }
|
|
|
|
// },)
|
|
|
|
if (question.content.rule.parentId !== "root")
|
|
|
|
edges.push({
|
|
|
|
data: {
|
|
|
|
source: question.content.rule.parentId,
|
|
|
|
target: question.content.id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return [...nodes, ...edges];
|
|
|
|
};
|