feat: add file manager context actions (#3027)
* feat(app): add file manager context actions * fix: reshape file context actions --------- Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
This commit is contained in:
co-authored by
Mohamed Boudra
parent
a98d154b6b
commit
ca2b633286
@@ -6,6 +6,7 @@ import {
|
||||
type ExplorerDirectory,
|
||||
} from "@/stores/session-store";
|
||||
import { explorerFileFromReadResult } from "@/file-explorer/read-result";
|
||||
import { parentExplorerPath } from "@/utils/explorer-paths";
|
||||
|
||||
function createExplorerState(): AgentFileExplorerState {
|
||||
return {
|
||||
@@ -252,6 +253,80 @@ export function useFileExplorerActions(params: { serverId: string } & FileExplor
|
||||
[client, normalizedWorkspaceRoot, t],
|
||||
);
|
||||
|
||||
const createEntry = useCallback(
|
||||
async (input: { parentPath: string; name: string; kind: "file" | "directory" }) => {
|
||||
if (!client || !normalizedWorkspaceRoot) {
|
||||
return null;
|
||||
}
|
||||
const payload = await client.createFileEntry({
|
||||
cwd: normalizedWorkspaceRoot,
|
||||
...input,
|
||||
});
|
||||
if (payload.success) {
|
||||
await requestDirectoryListing(input.parentPath, {
|
||||
recordHistory: false,
|
||||
setCurrentPath: false,
|
||||
});
|
||||
}
|
||||
return payload;
|
||||
},
|
||||
[client, normalizedWorkspaceRoot, requestDirectoryListing],
|
||||
);
|
||||
|
||||
const renameEntry = useCallback(
|
||||
async (input: { path: string; name: string }) => {
|
||||
if (!client || !normalizedWorkspaceRoot) {
|
||||
return null;
|
||||
}
|
||||
const payload = await client.renameFileEntry({
|
||||
cwd: normalizedWorkspaceRoot,
|
||||
...input,
|
||||
});
|
||||
if (payload.success) {
|
||||
await requestDirectoryListing(parentExplorerPath(input.path), {
|
||||
recordHistory: false,
|
||||
setCurrentPath: false,
|
||||
});
|
||||
}
|
||||
return payload;
|
||||
},
|
||||
[client, normalizedWorkspaceRoot, requestDirectoryListing],
|
||||
);
|
||||
|
||||
const duplicateEntry = useCallback(
|
||||
async (path: string) => {
|
||||
if (!client || !normalizedWorkspaceRoot) {
|
||||
return null;
|
||||
}
|
||||
const payload = await client.duplicateFileEntry({ cwd: normalizedWorkspaceRoot, path });
|
||||
if (payload.success) {
|
||||
await requestDirectoryListing(parentExplorerPath(path), {
|
||||
recordHistory: false,
|
||||
setCurrentPath: false,
|
||||
});
|
||||
}
|
||||
return payload;
|
||||
},
|
||||
[client, normalizedWorkspaceRoot, requestDirectoryListing],
|
||||
);
|
||||
|
||||
const deleteEntry = useCallback(
|
||||
async (path: string) => {
|
||||
if (!client || !normalizedWorkspaceRoot) {
|
||||
return null;
|
||||
}
|
||||
const payload = await client.deleteFileEntry({ cwd: normalizedWorkspaceRoot, path });
|
||||
if (payload.success) {
|
||||
await requestDirectoryListing(parentExplorerPath(path), {
|
||||
recordHistory: false,
|
||||
setCurrentPath: false,
|
||||
});
|
||||
}
|
||||
return payload;
|
||||
},
|
||||
[client, normalizedWorkspaceRoot, requestDirectoryListing],
|
||||
);
|
||||
|
||||
const selectExplorerEntry = useCallback(
|
||||
(path: string | null) => {
|
||||
updateExplorerState((state) => ({
|
||||
@@ -267,6 +342,10 @@ export function useFileExplorerActions(params: { serverId: string } & FileExplor
|
||||
requestDirectoryListing,
|
||||
requestFilePreview,
|
||||
requestFileDownloadToken,
|
||||
createEntry,
|
||||
renameEntry,
|
||||
duplicateEntry,
|
||||
deleteEntry,
|
||||
selectExplorerEntry,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user