feat(sidebar): add shortcut to disconnect connections
This commit is contained in:
1 parent
30a4131bb2
commit
3a3eb7dd7c
19 files changed
+93
-5
No files matched your search
@@ -30,12 +30,12 @@ import { needsSidebarObjectGroupDiscovery } from "@/lib/sidebar/sidebarSearchDis
|
||||
import { isSidebarSearchPrunedDatabaseNode, resolveSidebarSearchDatabaseScope } from "@/lib/sidebar/sidebarSearchDatabaseScope";
|
||||
import { createSidebarSearchExpansionState } from "@/lib/sidebar/sidebarSearchExpansionState";
|
||||
import { createSidebarSearchLoadingTracker } from "@/lib/sidebar/sidebarSearchLoadingTracker";
|
||||
import { isCancelSearchShortcut, isCopySidebarSelectionShortcut, isEditSidebarConnectionShortcut, isPasteSidebarSelectionShortcut, isViewTableDdlShortcut } from "@/lib/editor/keyboardShortcuts";
|
||||
import { isCancelSearchShortcut, isCopySidebarSelectionShortcut, isDisconnectSidebarConnectionShortcut, isEditSidebarConnectionShortcut, isPasteSidebarSelectionShortcut, isViewTableDdlShortcut } from "@/lib/editor/keyboardShortcuts";
|
||||
import { sidebarNodeSupportsDdlView } from "@/lib/sidebar/sidebarTreeDdlShortcut";
|
||||
import { objectSourceTargetForTreeNode } from "@/lib/sidebar/treeNodeClick";
|
||||
import { supportsTypeObjectSource } from "@/lib/database/databaseObjectCapabilities";
|
||||
import { copyToClipboard } from "@/lib/common/clipboard";
|
||||
import { connectionPasteTargetGroupId, copySelectedConnectionsToClipboards, selectedConnectionEditTarget } from "@/lib/sidebar/sidebarConnectionSelection";
|
||||
import { connectionPasteTargetGroupId, copySelectedConnectionsToClipboards, selectedConnectionDisconnectTargets, selectedConnectionEditTarget } from "@/lib/sidebar/sidebarConnectionSelection";
|
||||
import { formatSidebarTableCopyText } from "@/lib/sidebar/sidebarTableNameCopy";
|
||||
import { pruneTreeSelectionToVisibleNodeIds } from "@/lib/sidebar/sidebarTreeSelection";
|
||||
import { isEditableSidebarTypeSearchTarget, sidebarTypeSearchNextQuery } from "@/lib/sidebar/sidebarTypeSearch";
|
||||
@@ -2407,6 +2407,13 @@ function onWindowKeydown(event: KeyboardEvent) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (sidebarShortcutTargetAllowsAppShortcut(event.target) && isDisconnectConnectionShortcut(event)) {
|
||||
if (requestSelectedConnectionDisconnect()) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (sidebarShortcutTargetAllowsAppShortcut(event.target) && isCopySidebarSelectionShortcut(event, settingsStore.editorSettings.shortcuts)) {
|
||||
if (copySelectedSidebarNames()) {
|
||||
event.preventDefault();
|
||||
@@ -2467,6 +2474,10 @@ function isEditConnectionShortcut(event: KeyboardEvent): boolean {
|
||||
return isEditSidebarConnectionShortcut(event, settingsStore.editorSettings.shortcuts);
|
||||
}
|
||||
|
||||
function isDisconnectConnectionShortcut(event: KeyboardEvent): boolean {
|
||||
return isDisconnectSidebarConnectionShortcut(event, settingsStore.editorSettings.shortcuts);
|
||||
}
|
||||
|
||||
function requestSelectedConnectionEdit(): boolean {
|
||||
const selectedNodeId = store.selectedTreeNodeId;
|
||||
const currentNode = selectedNodeId ? flatTreeIndex.value.nodeById.get(selectedNodeId) : null;
|
||||
@@ -2477,6 +2488,26 @@ function requestSelectedConnectionEdit(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
function requestSelectedConnectionDisconnect(): boolean {
|
||||
const selectedNodeId = store.selectedTreeNodeId;
|
||||
const currentNode = selectedNodeId ? flatTreeIndex.value.nodeById.get(selectedNodeId) : null;
|
||||
if (!currentNode) return false;
|
||||
const targets = selectedConnectionDisconnectTargets(currentNode, selectedSidebarNodesInVisibleOrder());
|
||||
const connectedTargets = targets.filter((target) => store.connectedIds.has(target.connectionId));
|
||||
if (connectedTargets.length > 0) {
|
||||
const connectionIds = connectedTargets.map((target) => target.connectionId);
|
||||
void disconnectSidebarConnections(connectionIds, (connectionId) => store.disconnect(connectionId)).then((result) => {
|
||||
if (result.succeeded > 0 && result.failed === 0) {
|
||||
toast(connectionIds.length > 1 ? t("connection.disconnectedSelected", { count: connectionIds.length }) : t("connection.disconnected"), 2000);
|
||||
} else if (result.failed > 0) {
|
||||
toast(t("connection.disconnectSelectedPartial", { succeeded: result.succeeded, failed: result.failed }), 5000);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function copySelectedSidebarNames(): boolean {
|
||||
const nodes = selectedSidebarNodesInVisibleOrder();
|
||||
if (nodes.length === 0) return false;
|
||||
|
||||
@@ -145,7 +145,7 @@ import { copyDisplayPathForTreeNode, copyNameForTreeNode, isDirectNavigationTree
|
||||
import { customTypeCapabilities, supportsTypeObjectSource } from "@/lib/database/databaseObjectCapabilities";
|
||||
import { mongoCollectionTableTypeFromNode, mongoCreateDatabasePreview, mongoDropIndexFailureCount } from "@/lib/sidebar/mongoCollectionMutation";
|
||||
import { dataTabOpenModeFromTreeClick, type DataTabOpenMode } from "@/lib/sidebar/dataTabOpenPolicy";
|
||||
import { isCopySidebarSelectionShortcut, isEditSidebarConnectionShortcut, isModRShortcut, isPasteSidebarSelectionShortcut } from "@/lib/editor/keyboardShortcuts";
|
||||
import { isCopySidebarSelectionShortcut, isDisconnectSidebarConnectionShortcut, isEditSidebarConnectionShortcut, isModRShortcut, isPasteSidebarSelectionShortcut } from "@/lib/editor/keyboardShortcuts";
|
||||
import { handleSidebarTreeDeleteShortcut } from "@/lib/sidebar/sidebarTreeDeleteShortcut";
|
||||
import { dataTableDoubleClickAction } from "@/lib/tabs/dataTabActivation";
|
||||
import { attachedDatabaseNameFromPath, buildCreateDatabaseSql, buildDuckDbAttachDatabaseSql, buildSqliteAttachDatabaseSql, supportsCreateDatabaseCharset, supportsCreateDatabaseLocale, uniqueAttachedDatabaseName } from "@/lib/database/createDatabaseSql";
|
||||
@@ -1266,6 +1266,12 @@ function onKeydown(event: KeyboardEvent) {
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
if (isDisconnectConnectionShortcut(event)) {
|
||||
if (!requestDisconnectSelectedConnection()) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
if (isSidebarTreeArrowKey(event) && handleSidebarTreeArrowKey(event)) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
@@ -1334,6 +1340,10 @@ function isEditConnectionShortcut(event: KeyboardEvent): boolean {
|
||||
return isEditSidebarConnectionShortcut(event, settingsStore.editorSettings.shortcuts);
|
||||
}
|
||||
|
||||
function isDisconnectConnectionShortcut(event: KeyboardEvent): boolean {
|
||||
return isDisconnectSidebarConnectionShortcut(event, settingsStore.editorSettings.shortcuts);
|
||||
}
|
||||
|
||||
function isCopyTreeSelectionShortcut(event: KeyboardEvent): boolean {
|
||||
return isCopySidebarSelectionShortcut(event, settingsStore.editorSettings.shortcuts);
|
||||
}
|
||||
@@ -1529,6 +1539,18 @@ function requestEditSelectedConnection(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
function requestDisconnectSelectedConnection(): boolean {
|
||||
if (canDisconnectConnection()) {
|
||||
void disconnectConnection();
|
||||
return true;
|
||||
}
|
||||
if (canDisconnectConnectionGroup()) {
|
||||
void disconnectConnectionGroup();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function requestDeleteSelectedNode(): boolean {
|
||||
claimTreeItemDialogOwnership();
|
||||
ensureDangerDialogRouting();
|
||||
@@ -5484,6 +5506,8 @@ const shortcutOpenDataInNewTab = computed(() => settingsStore.editorSettings.sho
|
||||
|
||||
const shortcutEditConnection = computed(() => settingsStore.editorSettings.shortcuts.editSidebarConnection);
|
||||
|
||||
const shortcutDisconnectConnection = computed(() => settingsStore.editorSettings.shortcuts.disconnectSidebarConnection);
|
||||
|
||||
const shortcutRename = "F2";
|
||||
|
||||
const shortcutRefresh = "F5";
|
||||
@@ -5624,7 +5648,7 @@ function buildConnectionSidebarMenu(context: SidebarMenuFactoryContext): boolean
|
||||
if (isConnecting.value) {
|
||||
items.push({ label: t("connection.cancelConnecting"), action: cancelConnectionAttempt, icon: X });
|
||||
} else if (canDisconnectConnection()) {
|
||||
items.push({ label: connectionDisconnectMenuLabel(), action: disconnectConnection, icon: Unplug });
|
||||
items.push({ label: connectionDisconnectMenuLabel(), action: disconnectConnection, icon: Unplug, shortcut: shortcutDisconnectConnection.value });
|
||||
// save_password=false 且本次运行期已输入密码:提供"断开并忘记本次密码",
|
||||
// 清除会话凭据后下次连接需重新输入。
|
||||
if (canForgetSessionCredential()) {
|
||||
@@ -5816,6 +5840,7 @@ function buildConnectionSidebarMenu(context: SidebarMenuFactoryContext): boolean
|
||||
action: disconnectConnectionGroup,
|
||||
icon: Unplug,
|
||||
disabled: !canDisconnectConnectionGroup(),
|
||||
shortcut: shortcutDisconnectConnection.value,
|
||||
});
|
||||
items.push({ label: "", separator: true });
|
||||
items.push({
|
||||
|
||||
@@ -7991,6 +7991,7 @@ export default withEnglishFallback({
|
||||
shortcutCopySidebarSelection: "Yan paneldəki seçimi kopyala",
|
||||
shortcutPasteSidebarSelection: "Yan panelə yerləşdir",
|
||||
shortcutEditSidebarConnection: "Yan paneldəki əlaqəni redaktə et",
|
||||
shortcutDisconnectSidebarConnection: "Yan paneldəki əlaqəni kəs",
|
||||
shortcutOpenDataInNewTab: "Məlumatları yeni vərəqdə aç (siçan klikləməsi)",
|
||||
shortcutViewTableDdl: "Cədvəlin DDL-inə bax",
|
||||
shortcutSendSelectionToAi: "Seçimi AI-yə göndər",
|
||||
|
||||
@@ -8871,6 +8871,7 @@ export default {
|
||||
shortcutCopySidebarSelection: "Copy sidebar selection",
|
||||
shortcutPasteSidebarSelection: "Paste into sidebar",
|
||||
shortcutEditSidebarConnection: "Edit sidebar connection",
|
||||
shortcutDisconnectSidebarConnection: "Disconnect sidebar connection",
|
||||
shortcutOpenDataInNewTab: "Open data in new tab (mouse click)",
|
||||
shortcutViewTableDdl: "View table DDL",
|
||||
shortcutSendSelectionToAi: "Send selection to AI",
|
||||
|
||||
@@ -8205,6 +8205,7 @@ export default withEnglishFallback({
|
||||
shortcutCopySidebarSelection: "Copiar selección de la barra lateral",
|
||||
shortcutPasteSidebarSelection: "Pegar en la barra lateral",
|
||||
shortcutEditSidebarConnection: "Editar conexión de la barra lateral",
|
||||
shortcutDisconnectSidebarConnection: "Desconectar conexión de la barra lateral",
|
||||
shortcutOpenDataInNewTab: "Abrir datos en una pestaña nueva (clic del ratón)",
|
||||
shortcutViewTableDdl: "Ver DDL de la tabla",
|
||||
shortcutSendSelectionToAi: "Enviar selección a IA",
|
||||
|
||||
@@ -8705,6 +8705,7 @@ export default withEnglishFallback({
|
||||
shortcutCopySidebarSelection: "Salin seleksi bilah sisi",
|
||||
shortcutPasteSidebarSelection: "Tempel ke bilah sisi",
|
||||
shortcutEditSidebarConnection: "Edit koneksi bilah sisi",
|
||||
shortcutDisconnectSidebarConnection: "Putuskan koneksi bilah sisi",
|
||||
shortcutOpenDataInNewTab: "Buka data di tab baru (klik mouse)",
|
||||
shortcutViewTableDdl: "Lihat DDL tabel",
|
||||
shortcutSendSelectionToAi: "Kirim seleksi ke AI",
|
||||
|
||||
@@ -7976,6 +7976,7 @@ export default withEnglishFallback({
|
||||
shortcutCopySidebarSelection: "Copia selezione barra laterale",
|
||||
shortcutPasteSidebarSelection: "Incolla nella barra laterale",
|
||||
shortcutEditSidebarConnection: "Modifica connessione barra laterale",
|
||||
shortcutDisconnectSidebarConnection: "Disconnetti connessione barra laterale",
|
||||
shortcutOpenDataInNewTab: "Apri dati in una nuova scheda (clic del mouse)",
|
||||
shortcutViewTableDdl: "Visualizza DDL tabella",
|
||||
shortcutSendSelectionToAi: "Invia selezione ad AI",
|
||||
|
||||
@@ -7973,6 +7973,7 @@ export default withEnglishFallback({
|
||||
shortcutCopySidebarSelection: "サイドバーの選択をコピー",
|
||||
shortcutPasteSidebarSelection: "サイドバーに貼り付け",
|
||||
shortcutEditSidebarConnection: "サイドバー接続を編集",
|
||||
shortcutDisconnectSidebarConnection: "サイドバー接続を切断",
|
||||
shortcutOpenDataInNewTab: "新しいデータタブで開く(マウスクリック)",
|
||||
shortcutViewTableDdl: "テーブルDDLを表示",
|
||||
shortcutSendSelectionToAi: "選択範囲をAIに送信",
|
||||
|
||||
@@ -7757,6 +7757,7 @@ export default withEnglishFallback({
|
||||
shortcutCopySidebarSelection: "사이드바 선택 복사",
|
||||
shortcutPasteSidebarSelection: "사이드바에 붙여넣기",
|
||||
shortcutEditSidebarConnection: "사이드바 연결 편집",
|
||||
shortcutDisconnectSidebarConnection: "사이드바 연결 끊기",
|
||||
shortcutOpenDataInNewTab: "새 탭에서 데이터 열기 (마우스 클릭)",
|
||||
shortcutViewTableDdl: "테이블 DDL 보기",
|
||||
shortcutSendSelectionToAi: "선택 영역을 AI로 보내기",
|
||||
|
||||
@@ -7977,6 +7977,7 @@ export default withEnglishFallback({
|
||||
shortcutCopySidebarSelection: "Copiar seleção da barra lateral",
|
||||
shortcutPasteSidebarSelection: "Colar na barra lateral",
|
||||
shortcutEditSidebarConnection: "Editar conexão da barra lateral",
|
||||
shortcutDisconnectSidebarConnection: "Desconectar conexão da barra lateral",
|
||||
shortcutOpenDataInNewTab: "Abrir dados em nova aba (clique do mouse)",
|
||||
shortcutViewTableDdl: "Ver DDL da tabela",
|
||||
shortcutSendSelectionToAi: "Enviar seleção para IA",
|
||||
|
||||
@@ -9242,6 +9242,7 @@ export default withEnglishFallback({
|
||||
shortcutCopySidebarSelection: "Копировать выделенное в боковой панели",
|
||||
shortcutPasteSidebarSelection: "Вставить в боковую панель",
|
||||
shortcutEditSidebarConnection: "Изменить подключение в боковой панели",
|
||||
shortcutDisconnectSidebarConnection: "Отключить подключение в боковой панели",
|
||||
shortcutOpenDataInNewTab: "Открыть данные в новой вкладке (клик мышью)",
|
||||
shortcutViewTableDdl: "Просмотреть DDL таблицы",
|
||||
shortcutSendSelectionToAi: "Отправить выделенное в AI",
|
||||
|
||||
@@ -7890,6 +7890,7 @@ export default withEnglishFallback({
|
||||
shortcutCopySidebarSelection: "Kenar çubuğu seçimini kopyala",
|
||||
shortcutPasteSidebarSelection: "Kenar çubuğuna yapıştır",
|
||||
shortcutEditSidebarConnection: "Kenar çubuğu bağlantısını düzenle",
|
||||
shortcutDisconnectSidebarConnection: "Kenar çubuğu bağlantısını kes",
|
||||
shortcutOpenDataInNewTab: "Verileri yeni sekmede aç (fare tıklaması)",
|
||||
shortcutViewTableDdl: "Tablo DDL'ini görüntüle",
|
||||
shortcutSendSelectionToAi: "Seçimi yapay zekâya gönder",
|
||||
|
||||
@@ -8837,6 +8837,7 @@ export default withEnglishFallback({
|
||||
shortcutCopySidebarSelection: "复制侧边栏选中项",
|
||||
shortcutPasteSidebarSelection: "粘贴到侧边栏",
|
||||
shortcutEditSidebarConnection: "编辑侧边栏连接",
|
||||
shortcutDisconnectSidebarConnection: "断开侧边栏连接",
|
||||
shortcutOpenDataInNewTab: "在新数据标签页中打开(鼠标点击)",
|
||||
shortcutViewTableDdl: "查看表 DDL",
|
||||
shortcutSendSelectionToAi: "发送选中代码到 AI",
|
||||
|
||||
@@ -7272,6 +7272,7 @@ export default withEnglishFallback({
|
||||
shortcutCopySidebarSelection: "複製側邊欄選取項",
|
||||
shortcutPasteSidebarSelection: "貼到側邊欄",
|
||||
shortcutEditSidebarConnection: "編輯側邊欄連線",
|
||||
shortcutDisconnectSidebarConnection: "中斷側邊欄連線",
|
||||
shortcutOpenDataInNewTab: "在新資料分頁中開啟(滑鼠點擊)",
|
||||
shortcutViewTableDdl: "檢視資料表 DDL",
|
||||
shortcutSendSelectionToAi: "傳送選取程式碼至 AI",
|
||||
|
||||
@@ -43,7 +43,7 @@ describe("shortcutRegistry editor actions", () => {
|
||||
"exPasteSqlInCondition",
|
||||
"toggleFold",
|
||||
];
|
||||
const sidebarShortcutActionIds: ShortcutActionId[] = ["copySidebarSelection", "pasteSidebarSelection", "editSidebarConnection", "viewTableDdl"];
|
||||
const sidebarShortcutActionIds: ShortcutActionId[] = ["copySidebarSelection", "pasteSidebarSelection", "editSidebarConnection", "disconnectSidebarConnection", "viewTableDdl"];
|
||||
|
||||
it("registers pagination navigation as unassigned grid shortcuts", () => {
|
||||
const paginationActions = [
|
||||
|
||||
@@ -321,6 +321,10 @@ export function isEditSidebarConnectionShortcut(event: ShortcutLikeEvent, shortc
|
||||
return matchesShortcut(event, actionShortcut("editSidebarConnection", shortcuts));
|
||||
}
|
||||
|
||||
export function isDisconnectSidebarConnectionShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>): boolean {
|
||||
return matchesShortcut(event, actionShortcut("disconnectSidebarConnection", shortcuts));
|
||||
}
|
||||
|
||||
export function isViewTableDdlShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>): boolean {
|
||||
return matchesShortcut(event, actionShortcut("viewTableDdl", shortcuts));
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ export type ShortcutActionId =
|
||||
| "copySidebarSelection"
|
||||
| "pasteSidebarSelection"
|
||||
| "editSidebarConnection"
|
||||
| "disconnectSidebarConnection"
|
||||
| "openDataInNewTab"
|
||||
| "viewTableDdl"
|
||||
| "sendSelectionToAi"
|
||||
@@ -614,6 +615,12 @@ export const SHORTCUT_DEFINITIONS: ShortcutDefinition[] = [
|
||||
scope: "sidebar",
|
||||
defaultShortcut: "Mod+E",
|
||||
},
|
||||
{
|
||||
id: "disconnectSidebarConnection",
|
||||
labelKey: "settings.shortcutDisconnectSidebarConnection",
|
||||
scope: "sidebar",
|
||||
defaultShortcut: "Shift+Mod+E",
|
||||
},
|
||||
{
|
||||
id: "openDataInNewTab",
|
||||
labelKey: "settings.shortcutOpenDataInNewTab",
|
||||
|
||||
Reference in new issue
Block a user