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 () => { fetchTree: async () => {
try { try {
const data = await scriptsApi.getTree(); const data = await scriptsApi.getTree();
const nodeMap = new Map<string, FileNode>();
data.forEach((item) => { const convertItem = (item: any): FileNode => {
nodeMap.set(item.name, { const node: FileNode = {
id: item.id, id: item.id,
name: item.name, name: item.name,
type: item.type === "folder" ? "folder" : "file", type: item.type === "folder" ? "folder" : "file",
content: item.content || "", content: item.content || "",
path: item.name, path: item.name,
interpreter_id: item.interpreter_id, interpreter_id: item.interpreter_id,
children: item.type === "folder" ? [] : undefined, };
});
});
const hasParent = new Set<string>(); if (item.type === "folder") {
data.forEach((item) => { node.children = [];
if (item.children) { if (item.children && Array.isArray(item.children)) {
item.children.forEach((childName: string) => { node.children = item.children.map((child: any) => {
hasParent.add(childName); const childNode = convertItem(child);
const parent = nodeMap.get(item.name); childNode.path = `${item.name}/${child.name}`;
const child = nodeMap.get(childName); return childNode;
if (parent?.children && child) { });
parent.children.push(child); }
}
});
} }
});
const roots = [...nodeMap.entries()] return node;
.filter(([name]) => !hasParent.has(name)) };
.map(([, node]) => node);
const roots = data.map((item) => convertItem(item));
set({ set({
files: { files: {
+15 -35
View File
@@ -7,54 +7,34 @@ import type { FileNode } from "../modules/ide";
import { scriptsApi } from "../modules/ide/api/scripts.api"; import { scriptsApi } from "../modules/ide/api/scripts.api";
const convertTreeToFileNode = (data: any[]): FileNode => { const convertTreeToFileNode = (data: any[]): FileNode => {
const nodeMap = new Map<string, FileNode>(); const convertItem = (item: any): FileNode => {
const childrenMap = new Map<string, string[]>(); const node: FileNode = {
// Создаём все узлы
data.forEach((item) => {
nodeMap.set(item.name, {
id: item.id, id: item.id,
name: item.name, name: item.name,
type: item.type === "folder" ? "folder" : "file", type: item.type === "folder" ? "folder" : "file",
content: item.content || "", content: item.content || "",
path: item.name, path: item.name,
interpreter_id: item.interpreter_id, interpreter_id: item.interpreter_id,
children: item.type === "folder" ? [] : undefined, };
});
if (item.children && item.children.length > 0) { if (item.type === "folder") {
childrenMap.set(item.name, item.children); 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}`;
const roots: FileNode[] = []; return childNode;
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);
} }
});
});
// Корневые элементы — те у кого нет родителя
nodeMap.forEach((node, name) => {
if (!hasParent.has(name)) {
roots.push(node);
} }
});
return node;
};
return { return {
name: "templates", name: "templates",
type: "folder", type: "folder",
children: roots, children: data.map((item) => convertItem(item)),
}; };
}; };