feat(sql): add folder search and creation to save dialog
This commit is contained in:
1 parent
bb613b1712
commit
7165ec8911
10 files changed
+200
-18
No files matched your search
+61
-18
@@ -32,6 +32,7 @@ import { useVisibilityChange } from "@/composables/useVisibilityChange";
|
||||
import { useWebDavAutoUpload } from "@/composables/useWebDavAutoUpload";
|
||||
import { useScheduledDatabaseBackups } from "@/composables/useScheduledDatabaseBackups";
|
||||
import { shouldDrawDesktopWindowFrame } from "@/composables/useWindowControls";
|
||||
import { useSaveSqlFolderSelection } from "@/composables/useSaveSqlFolderSelection";
|
||||
import "@/i18n";
|
||||
import { translateBackendError } from "@/i18n/backend-errors";
|
||||
import * as api from "@/lib/backend/api";
|
||||
@@ -92,7 +93,7 @@ import { ensureJdbcxRuntimeDrivers } from "@/lib/database/jdbcxBuiltinDriver";
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { SearchableSelect } from "@/components/ui/searchable-select";
|
||||
import type { HistoryEntry } from "@/lib/backend/tauri";
|
||||
import type { AiAction } from "@/lib/ai/ai";
|
||||
|
||||
@@ -169,13 +170,13 @@ const queryEditorDdlTarget = ref<{ connectionId: string; database: string; catal
|
||||
const queryEditorObjectSourceTarget = ref<{ connectionId: string; database: string; schema?: string; name: string; objectType: ObjectSourceKind; initialEditing: boolean } | null>(null);
|
||||
const showSaveSqlDialog = ref(false);
|
||||
const saveSqlName = ref("");
|
||||
const saveSqlFolderId = ref("");
|
||||
const ROOT_SAVED_SQL_FOLDER = "__root__";
|
||||
const { selection: saveSqlFolderId, pending: saveSqlFolderCreationPending, reset: resetSaveSqlFolderSelection, invalidate: invalidateSaveSqlFolderSelection, select: selectSaveSqlFolder } = useSaveSqlFolderSelection(ROOT_SAVED_SQL_FOLDER);
|
||||
const pendingSaveAndCloseTabId = ref<string | null>(null);
|
||||
const pendingPrevActiveTabId = ref<string | null>(null);
|
||||
const pendingSaveShouldCloseTab = ref(true);
|
||||
const pendingAppCloseAction = ref<AppCloseAction | null>(null);
|
||||
const pendingCloseActionChoice = ref(false);
|
||||
const ROOT_SAVED_SQL_FOLDER = "__root__";
|
||||
|
||||
const activeTab = computed(() => queryStore.tabs.find((t) => t.id === queryStore.activeTabId));
|
||||
|
||||
@@ -637,6 +638,7 @@ function closePendingSavedTab() {
|
||||
}
|
||||
|
||||
function cancelPendingSaveAndClose() {
|
||||
invalidateSaveSqlFolderSelection();
|
||||
showSaveSqlDialog.value = false;
|
||||
pendingSaveAndCloseTabId.value = null;
|
||||
pendingPrevActiveTabId.value = null;
|
||||
@@ -825,7 +827,7 @@ async function handleSaveTab(tabId: string) {
|
||||
const prevActive = queryStore.activeTabId;
|
||||
queryStore.activeTabId = tabId;
|
||||
saveSqlName.value = defaultSavedSqlName(tab.title);
|
||||
saveSqlFolderId.value = ROOT_SAVED_SQL_FOLDER;
|
||||
resetSaveSqlFolderSelection(ROOT_SAVED_SQL_FOLDER);
|
||||
pendingSaveAndCloseTabId.value = tabId;
|
||||
pendingPrevActiveTabId.value = prevActive;
|
||||
showSaveSqlDialog.value = true;
|
||||
@@ -857,7 +859,7 @@ async function openSaveSqlDialog() {
|
||||
}
|
||||
|
||||
saveSqlName.value = defaultSavedSqlName(tab.title);
|
||||
saveSqlFolderId.value = ROOT_SAVED_SQL_FOLDER;
|
||||
resetSaveSqlFolderSelection(ROOT_SAVED_SQL_FOLDER);
|
||||
showSaveSqlDialog.value = true;
|
||||
}
|
||||
|
||||
@@ -900,7 +902,36 @@ async function saveActiveObjectSource(tab: QueryTab): Promise<boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
function saveSqlFolderDisplayName(id: string) {
|
||||
if (id === ROOT_SAVED_SQL_FOLDER) return t("savedSql.rootFolder");
|
||||
const folder = saveSqlFolders.value.find((f) => f.id === id);
|
||||
return folder?.displayName ?? id;
|
||||
}
|
||||
|
||||
function saveSqlFolderNormalizeCustom(value: string) {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) return trimmed;
|
||||
const folder = saveSqlFolders.value.find((f) => f.displayName === trimmed);
|
||||
return folder ? folder.id : trimmed;
|
||||
}
|
||||
|
||||
async function handleSaveSqlFolderSelect(value: string) {
|
||||
const isExisting = value === ROOT_SAVED_SQL_FOLDER || saveSqlFolders.value.some((f) => f.id === value);
|
||||
if (isExisting) {
|
||||
await selectSaveSqlFolder(value);
|
||||
return;
|
||||
}
|
||||
const tab = activeTab.value;
|
||||
if (!tab) return;
|
||||
await selectSaveSqlFolder(
|
||||
value,
|
||||
async () => (await savedSqlStore.createFolder(tab.connectionId, value)).id,
|
||||
(error: any) => toast(t("savedSql.createFolderFailed", { message: error?.message || String(error) }), 5000),
|
||||
);
|
||||
}
|
||||
|
||||
async function confirmSaveSqlToLibrary() {
|
||||
if (saveSqlFolderCreationPending.value) return;
|
||||
const tab = activeTab.value;
|
||||
const name = saveSqlName.value.trim();
|
||||
if (!tab || !tab.sql.trim() || !name) return;
|
||||
@@ -931,6 +962,7 @@ async function saveActiveSqlAsLocalFile() {
|
||||
const path = await api.saveExternalSqlFile(defaultSavedSqlName(tab.title), tab.sql);
|
||||
if (!path) return;
|
||||
queryStore.linkExternalSqlPath(tab.id, path, sqlFileTitleFromPath(path));
|
||||
invalidateSaveSqlFolderSelection();
|
||||
showSaveSqlDialog.value = false;
|
||||
closePendingSavedTab();
|
||||
toast(t("savedSql.saved"), 2000);
|
||||
@@ -2256,7 +2288,10 @@ onUnmounted(() => {
|
||||
@update:open="
|
||||
(open: boolean) => {
|
||||
showSaveSqlDialog = open;
|
||||
if (!open && pendingSaveAndCloseTabId) cancelPendingSaveAndClose();
|
||||
if (!open) {
|
||||
invalidateSaveSqlFolderSelection();
|
||||
if (pendingSaveAndCloseTabId) cancelPendingSaveAndClose();
|
||||
}
|
||||
}
|
||||
"
|
||||
>
|
||||
@@ -2271,23 +2306,31 @@ onUnmounted(() => {
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="text-xs font-medium text-muted-foreground">{{ t("savedSql.folder") }}</label>
|
||||
<Select v-model="saveSqlFolderId">
|
||||
<SelectTrigger class="h-8 w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent position="popper">
|
||||
<SelectItem :value="ROOT_SAVED_SQL_FOLDER">{{ t("savedSql.rootFolder") }}</SelectItem>
|
||||
<SelectItem v-for="folder in saveSqlFolders" :key="folder.id" :value="folder.id">
|
||||
{{ folder.displayName }}
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<SearchableSelect
|
||||
:model-value="saveSqlFolderId"
|
||||
:options="[ROOT_SAVED_SQL_FOLDER, ...saveSqlFolders.map((f) => f.id)]"
|
||||
:display-name="saveSqlFolderDisplayName"
|
||||
:normalize-custom="saveSqlFolderNormalizeCustom"
|
||||
:placeholder="t('savedSql.folderPlaceholder')"
|
||||
:search-placeholder="t('savedSql.searchPlaceholder')"
|
||||
:empty-text="t('common.noResults')"
|
||||
:disabled="saveSqlFolderCreationPending"
|
||||
allow-custom
|
||||
trigger-variant="outline"
|
||||
trigger-class="h-8 w-full max-w-none text-sm"
|
||||
content-class="w-[var(--reka-popover-trigger-width)]"
|
||||
@update:model-value="handleSaveSqlFolderSelect"
|
||||
>
|
||||
<template #custom-option-label="{ value }">
|
||||
<span class="truncate">{{ t("savedSql.createFolderOption", { name: value }) }}</span>
|
||||
</template>
|
||||
</SearchableSelect>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button v-if="isDesktop" variant="secondary" @click="saveActiveSqlAsLocalFile">{{ t("savedSql.saveToFile") }}</Button>
|
||||
<Button variant="outline" @click="cancelPendingSaveAndClose()">{{ t("dangerDialog.cancel") }}</Button>
|
||||
<Button :disabled="!saveSqlName.trim()" @click="confirmSaveSqlToLibrary">{{ t("savedSql.save") }}</Button>
|
||||
<Button :disabled="saveSqlFolderCreationPending || !saveSqlName.trim()" @click="confirmSaveSqlToLibrary">{{ t("savedSql.save") }}</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
Reference in new issue
Block a user