feat(sql-library): add move to folder action
This commit is contained in:
1 parent
69f880fdf1
commit
614daa5b19
11 files changed
+234
-6
No files matched your search
@@ -51,6 +51,19 @@ function getConnectionLabel(connectionId: string) {
|
||||
return conn?.name || connectionId;
|
||||
}
|
||||
|
||||
function folderPath(folder: SavedSqlFolder) {
|
||||
const folderById = new Map(savedSqlStore.allFolders.map((item) => [item.id, item]));
|
||||
const parts: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
let current: SavedSqlFolder | undefined = folder;
|
||||
while (current && !seen.has(current.id)) {
|
||||
seen.add(current.id);
|
||||
parts.unshift(current.name);
|
||||
current = current.parentFolderId ? folderById.get(current.parentFolderId) : undefined;
|
||||
}
|
||||
return parts.join(" / ");
|
||||
}
|
||||
|
||||
function activeImportConnectionId() {
|
||||
return connectionStore.activeConnectionId || connectionStore.connections[0]?.id || "";
|
||||
}
|
||||
@@ -586,6 +599,14 @@ async function executeBatchDelete() {
|
||||
toast(t("sqlLibrary.batchDeleteSuccess", { count: fileIds.length + folderIds.length }), 2000);
|
||||
}
|
||||
|
||||
async function moveFilesToFolder(fileIds: string[], folderId?: string) {
|
||||
const movableIds = [...new Set(fileIds)].filter((id) => savedSqlStore.getFile(id));
|
||||
if (movableIds.length === 0) return;
|
||||
await savedSqlStore.moveFilesToFolder(movableIds, folderId);
|
||||
clearSelection();
|
||||
toast(t("sqlLibrary.moveSuccess", { count: movableIds.length }), 2000);
|
||||
}
|
||||
|
||||
async function openFile(file: SavedSqlFile) {
|
||||
if (suppressNextRowClick.value) return;
|
||||
const loadedFile = await savedSqlStore.ensureFileContent(file.id);
|
||||
@@ -717,13 +738,52 @@ function handleFolderClick(folder: SavedSqlFolder, event: MouseEvent) {
|
||||
|
||||
const contextTarget = ref<SavedSqlFolder | SavedSqlFile | "panel" | null>(null);
|
||||
|
||||
function folderMoveMenuItems(fileIds: string[]): CtxMenuItem[] {
|
||||
const files = [...new Set(fileIds)].map((id) => savedSqlStore.getFile(id)).filter((file): file is SavedSqlFile => Boolean(file));
|
||||
const allInUnfiled = files.length > 0 && files.every((file) => !file.folderId);
|
||||
const folderItems = savedSqlStore.allFoldersTreeOrder
|
||||
.filter((folder) => isConnectionVisible(folder.connectionId))
|
||||
.map((folder) => ({
|
||||
label: folderPath(folder),
|
||||
action: () =>
|
||||
moveFilesToFolder(
|
||||
files.map((file) => file.id),
|
||||
folder.id,
|
||||
),
|
||||
disabled: files.every((file) => file.folderId === folder.id),
|
||||
icon: FolderClosed,
|
||||
}));
|
||||
|
||||
return [
|
||||
{
|
||||
label: t("sqlLibrary.unfiled"),
|
||||
action: () =>
|
||||
moveFilesToFolder(
|
||||
files.map((file) => file.id),
|
||||
undefined,
|
||||
),
|
||||
disabled: files.length === 0 || allInUnfiled,
|
||||
icon: FolderOpen,
|
||||
},
|
||||
...(folderItems.length > 0 ? [{ label: "", separator: true }, ...folderItems] : []),
|
||||
];
|
||||
}
|
||||
|
||||
const contextMenuItems = computed<CtxMenuItem[]>(() => {
|
||||
const target = contextTarget.value;
|
||||
if (!target) return [];
|
||||
|
||||
// If there's selection, show batch delete option
|
||||
if (hasSelection.value) {
|
||||
const selectedFiles = Array.from(selectedFileIds.value);
|
||||
return [
|
||||
{
|
||||
label: t("sqlLibrary.moveSelectedToFolder", { count: selectedFiles.length }),
|
||||
icon: FolderClosed,
|
||||
children: folderMoveMenuItems(selectedFiles),
|
||||
visible: selectedFiles.length > 0,
|
||||
},
|
||||
{ label: "", separator: true, visible: selectedFiles.length > 0 },
|
||||
{
|
||||
label: t("sqlLibrary.batchDelete", { count: selectedCount.value }),
|
||||
action: confirmBatchDelete,
|
||||
@@ -756,6 +816,7 @@ const contextMenuItems = computed<CtxMenuItem[]>(() => {
|
||||
return [
|
||||
{ label: t("savedSql.open"), action: () => openFile(target), icon: FileText },
|
||||
{ label: t("sqlLibrary.exportFile"), action: () => exportSingleFile(target), icon: FileInput },
|
||||
{ label: t("sqlLibrary.moveToFolder"), icon: FolderClosed, children: folderMoveMenuItems([target.id]) },
|
||||
{ label: "", separator: true },
|
||||
{ label: t("savedSql.renameFile"), action: () => startRenameFile(target), icon: Pencil },
|
||||
{ label: "", separator: true },
|
||||
|
||||
Reference in new issue
Block a user