feat: rename
ci-front / build (push) Successful in 2m24s

This commit is contained in:
nikita
2026-04-05 03:59:08 +03:00
parent 178c3b53f7
commit f14490c076
2 changed files with 49 additions and 7 deletions
@@ -72,4 +72,15 @@ export const scriptsApi = {
deleteFolder: async (path: string): Promise<void> => {
await apiClient.delete(`/scripts/folder`, { data: { path } });
},
rename: async (payload: {
old_path: string;
new_path: string;
}): Promise<{ path: string }> => {
const res = await apiClient.post<{ path: string }>(
"/scripts/rename",
payload,
);
return res.data;
},
};
+38 -7
View File
@@ -476,14 +476,45 @@ export const useIDEStore = create<IDEState>((set, get) => ({
alert(`"${value}" already exists.`);
return;
}
const newFiles = renameNode(
files!,
dialog.node.path || dialog.node.name,
value,
);
if (newFiles) {
set({ files: newFiles });
const oldPath = dialog.node.path || dialog.node.name;
const newPath = parentPath ? `${parentPath}/${value}` : value;
// Сохраняем раскрытые папки
const savedExpandedFolders = new Set(get().expandedFolders);
try {
await scriptsApi.rename({ old_path: oldPath, new_path: newPath });
await get().fetchTree();
// Восстанавливаем раскрытые папки
set({ expandedFolders: savedExpandedFolders });
// Раскрываем родительскую цепочку
const allParentPaths: string[] = [];
let current = parentPath;
while (current) {
allParentPaths.push(current);
const parts = current.split("/");
parts.pop();
current = parts.join("/");
}
autoExpandPaths(new Set(allParentPaths));
// Если переименованный файл был открыт — обновим его в openFiles
const { openFiles, activeFile } = get();
const updatedOpenFiles = openFiles.map((f) =>
f.path === oldPath ? { ...f, name: value, path: newPath } : f,
);
set({ openFiles: updatedOpenFiles });
if (activeFile?.path === oldPath) {
set({ activeFile: { ...activeFile, name: value, path: newPath } });
}
} catch (e) {
console.error("Failed to rename:", e);
}
set({ dialog: null });
return;
}