feat(toolbar): add immediate sync shortcut
This commit is contained in:
17 files changed
+100
-5
No files matched your search
@@ -68,6 +68,7 @@ import { disposeAllSqlServerActivityTraces } from "@/lib/sqlserver/sqlServerActi
|
||||
import { useVisibilityChange } from "@/composables/useVisibilityChange";
|
||||
import { useExternalSqlFileChanges } from "@/composables/useExternalSqlFileChanges";
|
||||
import { useWebDavAutoUpload } from "@/composables/useWebDavAutoUpload";
|
||||
import { readSyncMethod, readWebDavAutoUploadConfig, readWebDavBackupSelection } from "@/lib/webdav/webdavAutoUploadConfig";
|
||||
import { useScheduledDatabaseBackups } from "@/composables/useScheduledDatabaseBackups";
|
||||
import { shouldDrawDesktopWindowFrame } from "@/composables/useWindowControls";
|
||||
import { createOpenTabsRestorationBarrier, initializeDesktopOpenTabs, initializeOpenTabs, type OpenTabsRestorationBarrier } from "@/lib/app/openTabsStartup";
|
||||
@@ -397,6 +398,7 @@ const pluginCenterActive = ref(false);
|
||||
const pluginCenterFocus = ref<PluginCenterFocus | null>(null);
|
||||
const connectionPluginProvider = ref<PluginCenterFocus | null>(null);
|
||||
const settingsReturnSurface = ref<"query" | "driverStore" | "pluginCenter" | "welcome">("welcome");
|
||||
const immediateSyncing = ref(false);
|
||||
const showDriverStore = computed(() => driverStoreTabOpen.value && driverStoreActive.value);
|
||||
const showPluginCenter = computed(() => pluginCenterTabOpen.value && pluginCenterActive.value);
|
||||
const showSettingsPage = computed(() => Boolean(settingsPageTabOpen.value && settingsStore.settingsPageActive));
|
||||
@@ -1177,6 +1179,35 @@ function openSettings(initialTab = "appearance", initialSection?: string) {
|
||||
activateSettingsPage();
|
||||
}
|
||||
|
||||
async function openImmediateSync() {
|
||||
const syncMethod = readSyncMethod();
|
||||
if (syncMethod !== "webdav") {
|
||||
openSettings("sync", syncMethod === "snippet" ? "sync-snippet" : "sync-local");
|
||||
return;
|
||||
}
|
||||
const autoUploadConfig = readWebDavAutoUploadConfig();
|
||||
if (!autoUploadConfig.webDavConfig) {
|
||||
openSettings("sync", "sync-webdav");
|
||||
return;
|
||||
}
|
||||
const webDavConfig = autoUploadConfig.webDavConfig;
|
||||
if (immediateSyncing.value) return;
|
||||
immediateSyncing.value = true;
|
||||
await nextTick();
|
||||
|
||||
try {
|
||||
const secretsStatus = await api.webdavSyncSecretsStatus();
|
||||
const selection = readWebDavBackupSelection();
|
||||
const includeSecrets = Boolean((selection?.includeSecrets ?? secretsStatus.enabled) && secretsStatus.enabled && secretsStatus.hasSavedPassphrase);
|
||||
const summary = await api.webdavSyncUpload(webDavConfig, settingsStore.editorSettings, undefined, includeSecrets, selection);
|
||||
toast(t("settings.syncUploadSuccess", { bytes: summary.bytes, path: summary.remotePath }), 3000);
|
||||
} catch (error: any) {
|
||||
toast(error?.message || String(error), 5000);
|
||||
} finally {
|
||||
immediateSyncing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
type MainContentSurface = "query" | "settings" | "driverStore" | "pluginCenter";
|
||||
|
||||
function activateMainContentSurface(surface: MainContentSurface) {
|
||||
@@ -4403,6 +4434,7 @@ onUnmounted(() => {
|
||||
:has-connections="connectionStore.connections.length > 0"
|
||||
:can-new-query="canCreateNewQuery"
|
||||
:has-sql-file-connections="hasSqlFileConnections"
|
||||
:immediate-syncing="immediateSyncing"
|
||||
:show-logout="!isDesktop && needsAuth"
|
||||
@new-connection="showConnectionDialog = true"
|
||||
@expand-sidebar="setSidebarOpen(true)"
|
||||
@@ -4417,6 +4449,7 @@ onUnmounted(() => {
|
||||
@open-driver-store="openDriverStorePage"
|
||||
@open-plugin-center="openPluginCenterPage()"
|
||||
@check-updates="handleToolbarUpdateClick"
|
||||
@immediate-sync="openImmediateSync"
|
||||
@open-transfer="dialogs.showTransferDialog.value = true"
|
||||
@open-sql-file="dialogs.showSqlFileDialog.value = true"
|
||||
@open-schema-diff="dialogs.showSchemaDiffDialog.value = true"
|
||||
|
||||
@@ -333,7 +333,7 @@ import {
|
||||
type ToolbarVisibilityItem,
|
||||
} from "@/lib/settings/settingsSearch";
|
||||
import { LOCALE_OPTIONS } from "@/lib/app/localeOptions";
|
||||
import { DEFAULT_WEB_DAV_AUTO_UPLOAD_INTERVAL_MINUTES, DEFAULT_WEB_DAV_REMOTE_PATH, normalizedWebDavAutoUploadInterval, writeWebDavAutoUploadFields, writeWebDavBackupSelection } from "@/lib/webdav/webdavAutoUploadConfig";
|
||||
import { DEFAULT_WEB_DAV_AUTO_UPLOAD_INTERVAL_MINUTES, DEFAULT_WEB_DAV_REMOTE_PATH, normalizedWebDavAutoUploadInterval, readSyncMethod, writeWebDavAutoUploadFields, writeWebDavBackupSelection, writeSyncMethod, type SyncMethod } from "@/lib/webdav/webdavAutoUploadConfig";
|
||||
import { apiUrl, webPath } from "@/lib/common/webPath";
|
||||
import { DEFAULT_DATA_GRID_FONT_FAMILY, DEFAULT_UI_FONT_FAMILY, normalizeCustomFontFamilyInput, readableFontFamily, SYSTEM_UI_FONT_FAMILY } from "@/lib/app/appFonts";
|
||||
import { buildFontFamilyOptions, displayFontFamily, isPresetFontFamily, loadSystemFontNames } from "@/lib/app/fontFamilyOptions";
|
||||
@@ -4399,7 +4399,7 @@ const localBackupError = ref(false);
|
||||
const localBackupPath = ref("");
|
||||
const localBackupDirectoryStorageKey = "dbx-local-backup-directory";
|
||||
const localBackupDirectory = ref(localStorage.getItem(localBackupDirectoryStorageKey) || "");
|
||||
const syncMethodTab = ref<"webdav" | "snippet" | "local">("webdav");
|
||||
const syncMethodTab = ref<SyncMethod>(readSyncMethod());
|
||||
const syncSelectionOpen = ref(false);
|
||||
const syncSelectionMode = ref<"upload" | "restore">("upload");
|
||||
const syncSelectionCatalog = ref<SyncSnapshotCatalog | null>(null);
|
||||
@@ -4424,6 +4424,8 @@ const legacySnippetId = ref("");
|
||||
const pendingLegacyCleanupId = ref("");
|
||||
const snippetSyncSettingsLoading = ref(true);
|
||||
|
||||
watch(syncMethodTab, (value) => writeSyncMethod(value), { immediate: true });
|
||||
|
||||
const webdavReady = computed(() => !!webdavEndpoint.value.trim() && !webdavBusy.value);
|
||||
const localBackupCanIncludeSecrets = computed(() => !!localBackupSecretsPassphrase.value.trim());
|
||||
const snippetReady = computed(() => !snippetSyncSettingsLoading.value && !snippetBusy.value && (snippetProvider.value !== "gitlab" || (!snippetInstanceError.value && snippetInstanceUrl.value === activeSnippetInstanceUrl.value)) && (!!snippetToken.value.trim() || snippetHasSavedToken.value));
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { computed, ref, onMounted, onBeforeUnmount, h, nextTick, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { ChevronsRight, DatabaseZap, FilePlus2, Moon, Sun, SunMoon, History, Bot, ArrowLeftRight, FileCode, BookMarked, GitCompareArrows, TableProperties, Settings, LogOut, CloudDownload, Package, PlugZap, FileDown, FolderTree, Pin, PinOff, CalendarClock, Waypoints } from "@lucide/vue";
|
||||
import { ChevronsRight, DatabaseZap, FilePlus2, Moon, Sun, SunMoon, History, Bot, ArrowLeftRight, FileCode, BookMarked, GitCompareArrows, TableProperties, Settings, LogOut, CloudDownload, Package, PlugZap, FileDown, FolderTree, Pin, PinOff, CalendarClock, Waypoints, RefreshCw } from "@lucide/vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import LightDropdown, { type LightDropdownItem } from "@/components/ui/LightDropdown.vue";
|
||||
@@ -55,6 +55,7 @@ const props = defineProps<{
|
||||
hasConnections: boolean;
|
||||
canNewQuery: boolean;
|
||||
hasSqlFileConnections: boolean;
|
||||
immediateSyncing: boolean;
|
||||
showLogout?: boolean;
|
||||
}>();
|
||||
|
||||
@@ -78,6 +79,7 @@ const emit = defineEmits<{
|
||||
"open-data-compare": [];
|
||||
"open-backups": [];
|
||||
"open-mcp-settings": [];
|
||||
"immediate-sync": [];
|
||||
logout: [];
|
||||
}>();
|
||||
|
||||
@@ -214,6 +216,15 @@ const collapsibleRightItemDefs = computed(() => {
|
||||
disabled: boolean;
|
||||
}
|
||||
const items: ItemDef[] = [];
|
||||
if (toolbarItems.value.immediateSync) {
|
||||
items.push({
|
||||
key: "immediateSync",
|
||||
label: t("toolbar.immediateSync"),
|
||||
icon: RefreshCw,
|
||||
action: () => emit("immediate-sync"),
|
||||
disabled: props.immediateSyncing,
|
||||
});
|
||||
}
|
||||
if (showToolbarUpdateEntry.value) {
|
||||
items.push({
|
||||
key: "checkUpdates",
|
||||
@@ -672,6 +683,15 @@ const toolbarStyle = computed(() => {
|
||||
</Tooltip>
|
||||
</template>
|
||||
|
||||
<Tooltip v-if="toolbarItems.immediateSync">
|
||||
<TooltipTrigger as-child>
|
||||
<Button v-show="isRightItemVisible('immediateSync')" variant="ghost" size="icon" class="toolbar-action-button h-8 w-8 shrink-0" :aria-label="t('toolbar.immediateSync')" :aria-busy="immediateSyncing" :disabled="immediateSyncing" @click="emit('immediate-sync')">
|
||||
<RefreshCw class="toolbar-action-icon h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{{ t("toolbar.immediateSync") }}</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip v-if="showAlwaysOnTopButton">
|
||||
<TooltipTrigger as-child>
|
||||
<Button
|
||||
|
||||
@@ -142,6 +142,7 @@ const toolbarProps = {
|
||||
hasConnections: false,
|
||||
canNewQuery: false,
|
||||
hasSqlFileConnections: false,
|
||||
immediateSyncing: false,
|
||||
};
|
||||
|
||||
describe("always-on-top button visibility", () => {
|
||||
@@ -247,6 +248,19 @@ describe("always-on-top button visibility", () => {
|
||||
unmount();
|
||||
});
|
||||
|
||||
it("disables the immediate sync action while syncing", async () => {
|
||||
const settingsStore = useSettingsStore();
|
||||
settingsStore.editorSettings.toolbarItems.immediateSync = true;
|
||||
const { host, unmount } = mount(AppToolbar, { ...toolbarProps, immediateSyncing: true });
|
||||
await settled();
|
||||
|
||||
const button = host.querySelector('[aria-label="toolbar.immediateSync"]');
|
||||
expect(button?.getAttribute("aria-busy")).toBe("true");
|
||||
expect((button as HTMLButtonElement | null)?.disabled).toBe(true);
|
||||
|
||||
unmount();
|
||||
});
|
||||
|
||||
it("renders shortcut hints in toolbar button tooltips", async () => {
|
||||
const settingsStore = useSettingsStore();
|
||||
settingsStore.updateEditorSettings({
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { EditorState } from "@codemirror/state";
|
||||
import { json } from "@codemirror/lang-json";
|
||||
import { foldable } from "@codemirror/language";
|
||||
import { ensureSyntaxTree, foldable } from "@codemirror/language";
|
||||
|
||||
describe("Redis JSON editor folding", () => {
|
||||
it("provides foldable ranges for JSON objects and arrays", () => {
|
||||
@@ -14,6 +14,7 @@ describe("Redis JSON editor folding", () => {
|
||||
}`,
|
||||
extensions: [json()],
|
||||
});
|
||||
ensureSyntaxTree(state, state.doc.length);
|
||||
|
||||
const objectLine = state.doc.line(1);
|
||||
const arrayLine = state.doc.line(2);
|
||||
|
||||
@@ -383,6 +383,7 @@ export default {
|
||||
logoutConfirm: "Are you sure you want to log out?",
|
||||
},
|
||||
toolbar: {
|
||||
immediateSync: "Sync now",
|
||||
commitOutcomeUnknown: "Commit result is unknown and the session no longer exists. Verify the data before running this SQL again.",
|
||||
moreActions: "More actions",
|
||||
newConnection: "New Connection",
|
||||
|
||||
@@ -376,6 +376,7 @@ export default withEnglishFallback({
|
||||
logoutConfirm: "¿Seguro que deseas cerrar sesión?",
|
||||
},
|
||||
toolbar: {
|
||||
immediateSync: "Sincronizar ahora",
|
||||
commitOutcomeUnknown: "El resultado del commit es desconocido y la sesión ya no existe. Compruebe los datos antes de volver a ejecutar el SQL.",
|
||||
moreActions: "Más acciones",
|
||||
newConnection: "Nueva conexión",
|
||||
|
||||
@@ -370,6 +370,7 @@ export default withEnglishFallback({
|
||||
logoutConfirm: "Sei sicuro di voler uscire?",
|
||||
},
|
||||
toolbar: {
|
||||
immediateSync: "Sincronizza ora",
|
||||
commitOutcomeUnknown: "L'esito del commit è sconosciuto e la sessione non esiste più. Verificare i dati prima di eseguire nuovamente SQL.",
|
||||
moreActions: "Altre azioni",
|
||||
newConnection: "Nuova Connessione",
|
||||
|
||||
@@ -371,6 +371,7 @@ export default withEnglishFallback({
|
||||
logoutConfirm: "ログアウトしてもよろしいですか?",
|
||||
},
|
||||
toolbar: {
|
||||
immediateSync: "今すぐ同期",
|
||||
commitOutcomeUnknown: "コミット結果は不明で、セッションは既に存在しません。SQL を再実行する前にデータを確認してください。",
|
||||
moreActions: "その他の操作",
|
||||
newConnection: "新しい接続",
|
||||
|
||||
@@ -379,6 +379,7 @@ export default withEnglishFallback({
|
||||
logoutConfirm: "로그아웃하시겠습니까?",
|
||||
},
|
||||
toolbar: {
|
||||
immediateSync: "지금 동기화",
|
||||
commitOutcomeUnknown: "커밋 결과를 알 수 없고 세션이 더 이상 존재하지 않습니다. SQL을 다시 실행하기 전에 데이터를 확인하세요。",
|
||||
moreActions: "더 많은 작업",
|
||||
newConnection: "새 연결",
|
||||
|
||||
@@ -371,6 +371,7 @@ export default withEnglishFallback({
|
||||
logoutConfirm: "Tem certeza de que deseja sair?",
|
||||
},
|
||||
toolbar: {
|
||||
immediateSync: "Sincronizar agora",
|
||||
commitOutcomeUnknown: "O resultado do commit é desconhecido e a sessão não existe mais. Verifique os dados antes de executar o SQL novamente.",
|
||||
moreActions: "Mais ações",
|
||||
newConnection: "Nova Conexão",
|
||||
|
||||
@@ -353,6 +353,7 @@ export default withEnglishFallback({
|
||||
logoutConfirm: "Вы действительно хотите выйти?",
|
||||
},
|
||||
toolbar: {
|
||||
immediateSync: "Синхронизировать сейчас",
|
||||
commitOutcomeUnknown: "Результат фиксации неизвестен, а сессия больше не существует. Проверьте данные перед повторным выполнением этого SQL.",
|
||||
moreActions: "Дополнительные действия",
|
||||
newConnection: "Новое подключение",
|
||||
|
||||
@@ -320,6 +320,7 @@ export default withEnglishFallback({
|
||||
logoutConfirm: "确定要退出登录吗?",
|
||||
},
|
||||
toolbar: {
|
||||
immediateSync: "立即同步",
|
||||
commitOutcomeUnknown: "提交结果未知,事务会话已不存在。请核对数据后再决定是否重新执行 SQL。",
|
||||
moreActions: "更多操作",
|
||||
newConnection: "新建连接",
|
||||
|
||||
@@ -429,6 +429,7 @@ export default withEnglishFallback({
|
||||
alwaysOnTopOff: "取消置頂",
|
||||
blockDangerousRedisCommands: "攔截危險命令",
|
||||
multiDbExecute: "多庫執行",
|
||||
immediateSync: "立即同步",
|
||||
},
|
||||
multiDbExecute: {
|
||||
manualTransaction: "手動交易",
|
||||
|
||||
@@ -50,7 +50,7 @@ export interface SettingsSearchRoute {
|
||||
|
||||
export type Translate = (key: string) => string;
|
||||
|
||||
type ToolbarVisibilityItemKey = "dataTransfer" | "driverManager" | "pluginCenter" | "sqlFile" | "schemaDiff" | "dataCompare" | "checkUpdates" | "sqlLibrary" | "sqlFileTree" | "history" | "ai" | "theme" | "github" | "alwaysOnTop";
|
||||
type ToolbarVisibilityItemKey = "immediateSync" | "dataTransfer" | "driverManager" | "pluginCenter" | "sqlFile" | "schemaDiff" | "dataCompare" | "checkUpdates" | "sqlLibrary" | "sqlFileTree" | "history" | "ai" | "theme" | "github" | "alwaysOnTop";
|
||||
|
||||
export type ToolbarVisibilityItem = ({ key: ToolbarVisibilityItemKey; titleKey: string; title?: never } | { key: ToolbarVisibilityItemKey; title: string; titleKey?: never }) & {
|
||||
/** The matching toolbar button can only exist in the desktop app, so the Web build hides the switch. */
|
||||
@@ -77,6 +77,7 @@ export const TOOLBAR_VISIBILITY_ITEMS: readonly ToolbarVisibilityItem[] = [
|
||||
{ key: "theme", titleKey: "toolbar.theme" },
|
||||
{ key: "github", title: "GitHub" },
|
||||
{ key: "alwaysOnTop", titleKey: "toolbar.alwaysOnTop", desktopOnly: true },
|
||||
{ key: "immediateSync", titleKey: "toolbar.immediateSync" },
|
||||
];
|
||||
|
||||
export function toolbarVisibilityItemLabel(item: ToolbarVisibilityItem, translate: Translate): string {
|
||||
|
||||
@@ -2,11 +2,23 @@ import type { SyncSelection, WebDavConfig } from "@/lib/backend/api";
|
||||
import { safeLocalStorageGet, safeLocalStorageSet } from "@/lib/backend/safeStorage";
|
||||
|
||||
export const WEB_DAV_BACKUP_SELECTION_STORAGE_KEY = "dbx-webdav-backup-selection";
|
||||
export const SYNC_METHOD_STORAGE_KEY = "dbx-sync-method";
|
||||
export const WEB_DAV_AUTO_UPLOAD_STORAGE_KEYS = ["dbx-webdav-endpoint", "dbx-webdav-username", "dbx-webdav-remote-path", "dbx-webdav-auto-upload-enabled", "dbx-webdav-auto-upload-interval-minutes", WEB_DAV_BACKUP_SELECTION_STORAGE_KEY] as const;
|
||||
|
||||
export const DEFAULT_WEB_DAV_REMOTE_PATH = "DBX/sync/snapshot.json";
|
||||
export const DEFAULT_WEB_DAV_AUTO_UPLOAD_INTERVAL_MINUTES = 30;
|
||||
|
||||
export type SyncMethod = "webdav" | "snippet" | "local";
|
||||
|
||||
export function readSyncMethod(): SyncMethod {
|
||||
const value = safeLocalStorageGet(SYNC_METHOD_STORAGE_KEY);
|
||||
return value === "snippet" || value === "local" ? value : "webdav";
|
||||
}
|
||||
|
||||
export function writeSyncMethod(value: SyncMethod) {
|
||||
safeLocalStorageSet(SYNC_METHOD_STORAGE_KEY, value);
|
||||
}
|
||||
|
||||
export interface WebDavAutoUploadConfig {
|
||||
enabled: boolean;
|
||||
intervalMinutes: number;
|
||||
|
||||
@@ -1094,6 +1094,7 @@ export interface EditorSettings {
|
||||
}
|
||||
|
||||
export interface ToolbarItems {
|
||||
immediateSync: boolean;
|
||||
dataTransfer: boolean;
|
||||
driverManager: boolean;
|
||||
pluginCenter: boolean;
|
||||
@@ -1115,6 +1116,7 @@ export interface ToolbarItems {
|
||||
}
|
||||
|
||||
export const DEFAULT_TOOLBAR_ITEMS: ToolbarItems = {
|
||||
immediateSync: false,
|
||||
dataTransfer: true,
|
||||
driverManager: true,
|
||||
pluginCenter: true,
|
||||
@@ -1700,6 +1702,7 @@ function normalizeToolbarItems(items: Partial<ToolbarItems> | undefined): Toolba
|
||||
const defaults = DEFAULT_TOOLBAR_ITEMS;
|
||||
if (!items || typeof items !== "object") return { ...defaults };
|
||||
return {
|
||||
immediateSync: items.immediateSync ?? defaults.immediateSync,
|
||||
dataTransfer: items.dataTransfer ?? defaults.dataTransfer,
|
||||
driverManager: items.driverManager ?? defaults.driverManager,
|
||||
pluginCenter: items.pluginCenter ?? defaults.pluginCenter,
|
||||
|
||||
Reference in new issue
Block a user