feat(sql-library): add new query option to folder and panel context menus

This commit is contained in:
t8y2
2026-06-21 23:43:12 +08:00
parent fa59281ef4
commit c9cd80fc79
8 changed files with 33 additions and 1 deletions
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed, nextTick, onBeforeUnmount, reactive, ref } from "vue";
import { useI18n } from "vue-i18n";
import { Download, FileInput, FileText, FolderCog, FolderClosed, FolderOpen, FolderPlus, Library, LocateFixed, Pencil, Search, Trash2, Upload, X } from "@lucide/vue";
import { Download, FileInput, FilePlus, FileText, FolderCog, FolderClosed, FolderOpen, FolderPlus, Library, LocateFixed, Pencil, Search, Trash2, Upload, X } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import CustomContextMenu, { type ContextMenuItem as CtxMenuItem } from "@/components/ui/CustomContextMenu.vue";
@@ -394,6 +394,29 @@ async function openNewFolderInput(parentFolderId?: string) {
startRenameFolder(folder);
}
async function openNewQueryInFolder(folder?: SavedSqlFolder) {
const connectionId = folder?.connectionId || connectionStore.activeConnectionId || connectionStore.connections[0]?.id;
if (!connectionId) return;
const takenNames = folder
? new Set(savedSqlStore.filesInFolder(folder.id).map((f) => f.name))
: new Set(
savedSqlStore
.filesWithoutFolder()
.filter((file) => !orphanedIds.value.has(file.id))
.map((f) => f.name),
);
const name = uniqueImportedName("new_query.sql", takenNames);
const file = await savedSqlStore.saveFile({
connectionId,
folderId: folder?.id,
name,
database: "",
sql: "",
});
queryStore.openSavedSql(file);
}
const renamingTarget = ref<{ type: "folder" | "file"; id: string } | null>(null);
const renameValue = ref("");
const renameInputRef = ref<HTMLInputElement | null>(null);
@@ -473,6 +496,7 @@ const contextMenuItems = computed<CtxMenuItem[]>(() => {
if (target === "panel") {
return [
{ label: t("savedSql.newFolder"), action: openNewFolderInput, icon: FolderPlus },
{ label: t("savedSql.newQuery"), action: () => openNewQueryInFolder(), icon: FilePlus },
{ label: t("sqlLibrary.importDirectory"), action: () => importDirectoryIntoLibrary(), icon: Upload },
{ label: t("sqlLibrary.exportLibrary"), action: () => exportFolderContents(), icon: Download },
{ label: "", separator: true },
@@ -503,6 +527,7 @@ const contextMenuItems = computed<CtxMenuItem[]>(() => {
}
return [
{ label: t("savedSql.newFolder"), action: () => openNewFolderInput(target.id), icon: FolderPlus },
{ label: t("savedSql.newQuery"), action: () => openNewQueryInFolder(target), icon: FilePlus },
{ label: t("sqlLibrary.importIntoFolder"), action: () => importDirectoryIntoLibrary(target), icon: Upload },
{ label: t("sqlLibrary.exportFolder"), action: () => exportFolderContents(target), icon: Download },
{ label: "", separator: true },
+1
View File
@@ -98,6 +98,7 @@ export default {
fileName: "File name",
folder: "Folder",
rootFolder: "SQL Library",
newQuery: "New Query",
newFolder: "New SQL Folder",
newFolderDefault: "New Folder",
renameFolder: "Rename Folder",
+1
View File
@@ -96,6 +96,7 @@ export default {
fileName: "Nombre de archivo",
folder: "Carpeta",
rootFolder: "Biblioteca SQL",
newQuery: "Nueva consulta",
newFolder: "Nueva carpeta SQL",
newFolderDefault: "Nueva carpeta",
renameFolder: "Renombrar carpeta",
+1
View File
@@ -96,6 +96,7 @@ export default {
fileName: "Nome file",
folder: "Cartella",
rootFolder: "Libreria SQL",
newQuery: "Nuova query",
newFolder: "Nuova Cartella SQL",
newFolderDefault: "Nuova Cartella",
renameFolder: "Rinomina Cartella",
+1
View File
@@ -98,6 +98,7 @@ export default {
fileName: "ファイル名",
folder: "フォルダ",
rootFolder: "SQLライブラリ",
newQuery: "新規クエリ",
newFolder: "新しいSQLフォルダ",
newFolderDefault: "新しいフォルダ",
renameFolder: "フォルダ名を変更",
+1
View File
@@ -96,6 +96,7 @@ export default {
fileName: "Nome do arquivo",
folder: "Pasta",
rootFolder: "Biblioteca SQL",
newQuery: "Nova Consulta",
newFolder: "Nova Pasta SQL",
newFolderDefault: "Nova Pasta",
renameFolder: "Renomear Pasta",
+1
View File
@@ -98,6 +98,7 @@ export default {
fileName: "文件名",
folder: "文件夹",
rootFolder: "SQL 库",
newQuery: "新建查询",
newFolder: "新建 SQL 文件夹",
newFolderDefault: "新建文件夹",
renameFolder: "重命名文件夹",
+1
View File
@@ -96,6 +96,7 @@ export default {
fileName: "檔案名稱",
folder: "資料夾",
rootFolder: "SQL 庫",
newQuery: "新建查詢",
newFolder: "建立 SQL 資料夾",
newFolderDefault: "建立資料夾",
renameFolder: "重新命名資料夾",