feat: confirm before closing unsaved SQL query tabs
This commit is contained in:
1 parent
51e2ef0d1f
commit
19b5b70fb7
6 files changed
+157
-5
No files matched your search
@@ -121,6 +121,8 @@ const newQueryContextSource = ref<"tab" | "sidebar">("tab");
|
||||
const showSaveSqlDialog = ref(false);
|
||||
const saveSqlName = ref("");
|
||||
const saveSqlFolderId = ref("");
|
||||
const pendingSaveAndCloseTabId = ref<string | null>(null);
|
||||
const pendingPrevActiveTabId = ref<string | null>(null);
|
||||
const ROOT_SAVED_SQL_FOLDER = "__root__";
|
||||
|
||||
const activeTab = computed(() => queryStore.tabs.find((t) => t.id === queryStore.activeTabId));
|
||||
@@ -390,6 +392,36 @@ function defaultSavedSqlName(title: string) {
|
||||
return normalized.endsWith(".sql") ? normalized : `${normalized}.sql`;
|
||||
}
|
||||
|
||||
async function handleSaveTab(tabId: string) {
|
||||
const tab = queryStore.tabs.find((t) => t.id === tabId);
|
||||
if (!tab || !tab.sql.trim()) return;
|
||||
const existing = tab.savedSqlId ? savedSqlStore.getFile(tab.savedSqlId) : undefined;
|
||||
if (existing) {
|
||||
const updated = await savedSqlStore.saveFile({
|
||||
id: existing.id,
|
||||
connectionId: tab.connectionId,
|
||||
folderId: existing.folderId,
|
||||
name: existing.name,
|
||||
database: tab.database,
|
||||
schema: tab.schema,
|
||||
sql: tab.sql,
|
||||
});
|
||||
queryStore.linkSavedSql(tab.id, updated.id, updated.name);
|
||||
queryStore.markTabClean(tab);
|
||||
toast(t("savedSql.saved"), 2000);
|
||||
queryStore.closeTab(tabId, { force: true });
|
||||
return;
|
||||
}
|
||||
// No existing saved SQL — open save dialog, then close after save
|
||||
const prevActive = queryStore.activeTabId;
|
||||
queryStore.activeTabId = tabId;
|
||||
saveSqlName.value = defaultSavedSqlName(tab.title);
|
||||
saveSqlFolderId.value = ROOT_SAVED_SQL_FOLDER;
|
||||
pendingSaveAndCloseTabId.value = tabId;
|
||||
pendingPrevActiveTabId.value = prevActive;
|
||||
showSaveSqlDialog.value = true;
|
||||
}
|
||||
|
||||
async function openSaveSqlDialog() {
|
||||
const tab = activeTab.value;
|
||||
if (!tab || !tab.sql.trim()) return;
|
||||
@@ -459,7 +491,15 @@ async function confirmSaveSqlToLibrary() {
|
||||
sql: tab.sql,
|
||||
});
|
||||
queryStore.linkSavedSql(tab.id, saved.id, saved.name);
|
||||
queryStore.markTabClean(tab);
|
||||
showSaveSqlDialog.value = false;
|
||||
if (pendingSaveAndCloseTabId.value) {
|
||||
const closeId = pendingSaveAndCloseTabId.value;
|
||||
pendingSaveAndCloseTabId.value = null;
|
||||
if (pendingPrevActiveTabId.value) queryStore.activeTabId = pendingPrevActiveTabId.value;
|
||||
pendingPrevActiveTabId.value = null;
|
||||
queryStore.closeTab(closeId, { force: true });
|
||||
}
|
||||
toast(t("savedSql.saved"), 2000);
|
||||
} catch (e: any) {
|
||||
toast(t("savedSql.saveFailed", { message: e?.message || String(e) }), 5000);
|
||||
@@ -1056,7 +1096,7 @@ onUnmounted(() => {
|
||||
|
||||
<div :class="isClassicLayout ? 'flex-1 min-w-0 overflow-hidden' : 'flex-1 min-w-0 overflow-hidden rounded-md border border-border/80 bg-background'">
|
||||
<div class="h-full flex flex-col min-w-0">
|
||||
<AppTabBar :show-driver-store="showDriverStore" :agent-driver-update-count="toolbarAgentDriverUpdateCount" @toggle-driver-store="showDriverStore = true" @close-driver-store="showDriverStore = false" />
|
||||
<AppTabBar :show-driver-store="showDriverStore" :agent-driver-update-count="toolbarAgentDriverUpdateCount" @toggle-driver-store="showDriverStore = true" @close-driver-store="showDriverStore = false" @save-tab="handleSaveTab" />
|
||||
<DriverStorePage v-if="showDriverStore" class="flex-1 min-h-0" :update-notifications-enabled="updateNotificationsEnabled" @update-count-change="updateAgentDriverUpdateCount" />
|
||||
<div v-else-if="activeTab" class="flex flex-col flex-1 min-h-0">
|
||||
<EditorToolbar
|
||||
@@ -1219,7 +1259,15 @@ onUnmounted(() => {
|
||||
</Transition>
|
||||
</div>
|
||||
|
||||
<Dialog v-model:open="showSaveSqlDialog">
|
||||
<Dialog
|
||||
:open="showSaveSqlDialog"
|
||||
@update:open="
|
||||
(open: boolean) => {
|
||||
showSaveSqlDialog = open;
|
||||
if (!open) pendingSaveAndCloseTabId = null;
|
||||
}
|
||||
"
|
||||
>
|
||||
<DialogContent class="sm:max-w-[420px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ t("savedSql.saveToLibrary") }}</DialogTitle>
|
||||
@@ -1245,7 +1293,14 @@ onUnmounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" @click="showSaveSqlDialog = false">{{ t("dangerDialog.cancel") }}</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
@click="
|
||||
showSaveSqlDialog = false;
|
||||
pendingSaveAndCloseTabId = null;
|
||||
"
|
||||
>{{ t("dangerDialog.cancel") }}</Button
|
||||
>
|
||||
<Button :disabled="!saveSqlName.trim()" @click="confirmSaveSqlToLibrary">{{ t("savedSql.save") }}</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
|
||||
Reference in new issue
Block a user