fix: render files
ci-front / build (push) Successful in 2m5s

This commit is contained in:
nikita
2026-04-05 01:07:03 +03:00
parent 8f5558fdb7
commit e024f91111
2 changed files with 31 additions and 56 deletions
+16 -21
View File
@@ -299,37 +299,32 @@ export const useIDEStore = create<IDEState>((set, get) => ({
fetchTree: async () => {
try {
const data = await scriptsApi.getTree();
const nodeMap = new Map<string, FileNode>();
data.forEach((item) => {
nodeMap.set(item.name, {
const convertItem = (item: any): FileNode => {
const node: FileNode = {
id: item.id,
name: item.name,
type: item.type === "folder" ? "folder" : "file",
content: item.content || "",
path: item.name,
interpreter_id: item.interpreter_id,
children: item.type === "folder" ? [] : undefined,
});
});
};
const hasParent = new Set<string>();
data.forEach((item) => {
if (item.children) {
item.children.forEach((childName: string) => {
hasParent.add(childName);
const parent = nodeMap.get(item.name);
const child = nodeMap.get(childName);
if (parent?.children && child) {
parent.children.push(child);
}
});
if (item.type === "folder") {
node.children = [];
if (item.children && Array.isArray(item.children)) {
node.children = item.children.map((child: any) => {
const childNode = convertItem(child);
childNode.path = `${item.name}/${child.name}`;
return childNode;
});
}
}
});
const roots = [...nodeMap.entries()]
.filter(([name]) => !hasParent.has(name))
.map(([, node]) => node);
return node;
};
const roots = data.map((item) => convertItem(item));
set({
files: {
+15 -35
View File
@@ -7,54 +7,34 @@ import type { FileNode } from "../modules/ide";
import { scriptsApi } from "../modules/ide/api/scripts.api";
const convertTreeToFileNode = (data: any[]): FileNode => {
const nodeMap = new Map<string, FileNode>();
const childrenMap = new Map<string, string[]>();
// Создаём все узлы
data.forEach((item) => {
nodeMap.set(item.name, {
const convertItem = (item: any): FileNode => {
const node: FileNode = {
id: item.id,
name: item.name,
type: item.type === "folder" ? "folder" : "file",
content: item.content || "",
path: item.name,
interpreter_id: item.interpreter_id,
children: item.type === "folder" ? [] : undefined,
});
};
if (item.children && item.children.length > 0) {
childrenMap.set(item.name, item.children);
}
});
// Строим дерево
const roots: FileNode[] = [];
const hasParent = new Set<string>();
childrenMap.forEach((children, parentName) => {
const parentNode = nodeMap.get(parentName);
if (!parentNode) return;
children.forEach((childName: string) => {
hasParent.add(childName);
const childNode = nodeMap.get(childName);
if (childNode && parentNode.children) {
parentNode.children.push(childNode);
if (item.type === "folder") {
node.children = [];
if (item.children && Array.isArray(item.children)) {
node.children = item.children.map((child: any) => {
const childNode = convertItem(child);
childNode.path = `${item.name}/${child.name}`;
return childNode;
});
}
});
});
// Корневые элементы — те у кого нет родителя
nodeMap.forEach((node, name) => {
if (!hasParent.has(name)) {
roots.push(node);
}
});
return node;
};
return {
name: "templates",
type: "folder",
children: roots,
children: data.map((item) => convertItem(item)),
};
};