mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-25 16:04:02 +08:00
✨ feat(shortcuts): 把 SQL 诊断与慢查询快捷键注册到管理系统并加菜单入口
- 注册到系统:diagnoseQuery 与 showSlowQueries 加入 ShortcutAction,可在快捷键管理面板自定义 - 修复冲突:原硬编码 Ctrl+Shift+D 与 toggleTheme 冲突、Ctrl+Shift+H 与 toggleLogPanel 冲突;改为 Ctrl+Shift+P / Ctrl+Shift+L - 菜单入口:QueryEditor 的"更多"下拉加 SQL 诊断、慢 SQL 历史两个菜单项,附带快捷键提示 - i18n 同步:6 种语言补齐 label/description
This commit is contained in:
@@ -2211,9 +2211,8 @@ const QueryEditor: React.FC<{ tab: TabData; isActive?: boolean }> = ({ tab, isAc
|
||||
const [saveModalMode, setSaveModalMode] = useState<'save' | 'rename'>('save');
|
||||
const [saveForm] = Form.useForm();
|
||||
|
||||
// SQL 诊断工作台:Ctrl+Shift+D 触发(Mac 为 Cmd+Shift+D)
|
||||
// SQL 诊断工作台与慢 SQL 历史:通过快捷键管理系统注册(避免与 toggleTheme/toggleLogPanel 冲突)
|
||||
const [explainOpen, setExplainOpen] = useState(false);
|
||||
// 慢 SQL 历史:Ctrl+Shift+H 触发
|
||||
const [slowQueryOpen, setSlowQueryOpen] = useState(false);
|
||||
|
||||
// Database Selection
|
||||
@@ -2275,23 +2274,6 @@ const QueryEditor: React.FC<{ tab: TabData; isActive?: boolean }> = ({ tab, isAc
|
||||
} as any;
|
||||
}, [connections, currentConnectionId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isActive) return;
|
||||
const handler = (e: KeyboardEvent) => {
|
||||
if (!(e.ctrlKey || e.metaKey) || !e.shiftKey) return;
|
||||
const key = e.key.toLowerCase();
|
||||
if (key === 'd') {
|
||||
e.preventDefault();
|
||||
setExplainOpen(true);
|
||||
} else if (key === 'h') {
|
||||
e.preventDefault();
|
||||
setSlowQueryOpen(true);
|
||||
}
|
||||
};
|
||||
window.addEventListener('keydown', handler);
|
||||
return () => window.removeEventListener('keydown', handler);
|
||||
}, [isActive]);
|
||||
|
||||
const addSqlLog = useStore(state => state.addSqlLog);
|
||||
const addTab = useStore(state => state.addTab);
|
||||
const setActiveContext = useStore(state => state.setActiveContext);
|
||||
@@ -2323,6 +2305,33 @@ const QueryEditor: React.FC<{ tab: TabData; isActive?: boolean }> = ({ tab, isAc
|
||||
() => resolveShortcutBinding(shortcutOptions, 'runQuery', activeShortcutPlatform),
|
||||
[activeShortcutPlatform, shortcutOptions],
|
||||
);
|
||||
// SQL 诊断 / 慢 SQL 历史的快捷键绑定(从 store 读取,用户可在快捷键管理面板自定义)
|
||||
const diagnoseQueryShortcutBinding = useMemo(
|
||||
() => resolveShortcutBinding(shortcutOptions, 'diagnoseQuery', activeShortcutPlatform),
|
||||
[activeShortcutPlatform, shortcutOptions],
|
||||
);
|
||||
const showSlowQueriesShortcutBinding = useMemo(
|
||||
() => resolveShortcutBinding(shortcutOptions, 'showSlowQueries', activeShortcutPlatform),
|
||||
[activeShortcutPlatform, shortcutOptions],
|
||||
);
|
||||
|
||||
// SQL 诊断 / 慢 SQL 历史的快捷键监听(必须在 binding 声明之后)
|
||||
useEffect(() => {
|
||||
if (!isActive) return;
|
||||
const handler = (e: KeyboardEvent) => {
|
||||
if (diagnoseQueryShortcutBinding?.enabled && isShortcutMatch(e, diagnoseQueryShortcutBinding.combo)) {
|
||||
e.preventDefault();
|
||||
setExplainOpen(true);
|
||||
return;
|
||||
}
|
||||
if (showSlowQueriesShortcutBinding?.enabled && isShortcutMatch(e, showSlowQueriesShortcutBinding.combo)) {
|
||||
e.preventDefault();
|
||||
setSlowQueryOpen(true);
|
||||
}
|
||||
};
|
||||
window.addEventListener('keydown', handler);
|
||||
return () => window.removeEventListener('keydown', handler);
|
||||
}, [isActive, diagnoseQueryShortcutBinding, showSlowQueriesShortcutBinding]);
|
||||
const selectCurrentStatementShortcutBinding = useMemo(
|
||||
() => resolveShortcutBinding(shortcutOptions, 'selectCurrentStatement', activeShortcutPlatform),
|
||||
[activeShortcutPlatform, shortcutOptions],
|
||||
@@ -5840,6 +5849,35 @@ const QueryEditor: React.FC<{ tab: TabData; isActive?: boolean }> = ({ tab, isAc
|
||||
label: translate('query_editor.action.export_sql_file'),
|
||||
onClick: () => void handleExportSQLFile(),
|
||||
},
|
||||
{ type: 'divider' },
|
||||
{
|
||||
key: 'diagnose-query',
|
||||
label: (
|
||||
<span>
|
||||
{translate('app.shortcuts.action.diagnoseQuery.label' as any) || 'SQL 诊断'}
|
||||
{diagnoseQueryShortcutBinding?.enabled && diagnoseQueryShortcutBinding.combo && (
|
||||
<span style={{ marginLeft: 8, color: 'var(--gn-text-muted, #6c757d)', fontSize: 11 }}>
|
||||
{getShortcutDisplayLabel(diagnoseQueryShortcutBinding.combo, activeShortcutPlatform)}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
),
|
||||
onClick: () => setExplainOpen(true),
|
||||
},
|
||||
{
|
||||
key: 'show-slow-queries',
|
||||
label: (
|
||||
<span>
|
||||
{translate('app.shortcuts.action.showSlowQueries.label' as any) || '慢 SQL 历史'}
|
||||
{showSlowQueriesShortcutBinding?.enabled && showSlowQueriesShortcutBinding.combo && (
|
||||
<span style={{ marginLeft: 8, color: 'var(--gn-text-muted, #6c757d)', fontSize: 11 }}>
|
||||
{getShortcutDisplayLabel(showSlowQueriesShortcutBinding.combo, activeShortcutPlatform)}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
),
|
||||
onClick: () => setSlowQueryOpen(true),
|
||||
},
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -18,7 +18,9 @@ export type ShortcutAction =
|
||||
| 'toggleTheme'
|
||||
| 'openShortcutManager'
|
||||
| 'toggleMacFullscreen'
|
||||
| 'resetWindowZoom';
|
||||
| 'resetWindowZoom'
|
||||
| 'diagnoseQuery'
|
||||
| 'showSlowQueries';
|
||||
|
||||
export type ShortcutPlatform = 'mac' | 'windows';
|
||||
|
||||
@@ -111,6 +113,8 @@ export const SHORTCUT_ACTION_ORDER: ShortcutAction[] = [
|
||||
'toggleAIPanel',
|
||||
'toggleLogPanel',
|
||||
'toggleTheme',
|
||||
'diagnoseQuery',
|
||||
'showSlowQueries',
|
||||
'openShortcutManager',
|
||||
'toggleMacFullscreen',
|
||||
'resetWindowZoom',
|
||||
@@ -202,6 +206,18 @@ const SHORTCUT_ACTION_META_DEFINITIONS: Record<ShortcutAction, ShortcutActionMet
|
||||
labelKey: 'app.shortcuts.action.toggleTheme.label',
|
||||
descriptionKey: 'app.shortcuts.action.toggleTheme.description',
|
||||
},
|
||||
diagnoseQuery: {
|
||||
labelKey: 'app.shortcuts.action.diagnoseQuery.label',
|
||||
descriptionKey: 'app.shortcuts.action.diagnoseQuery.description',
|
||||
scope: 'queryEditor',
|
||||
allowInEditable: true,
|
||||
},
|
||||
showSlowQueries: {
|
||||
labelKey: 'app.shortcuts.action.showSlowQueries.label',
|
||||
descriptionKey: 'app.shortcuts.action.showSlowQueries.description',
|
||||
scope: 'queryEditor',
|
||||
allowInEditable: true,
|
||||
},
|
||||
openShortcutManager: {
|
||||
labelKey: 'app.shortcuts.action.openShortcutManager.label',
|
||||
descriptionKey: 'app.shortcuts.action.openShortcutManager.description',
|
||||
@@ -279,6 +295,16 @@ export const DEFAULT_SHORTCUT_OPTIONS: ShortcutOptions = {
|
||||
mac: { combo: 'Meta+Shift+D', enabled: true },
|
||||
windows: { combo: 'Ctrl+Shift+D', enabled: true },
|
||||
},
|
||||
// SQL 诊断:避开 toggleTheme 的 Ctrl+Shift+D,用 Ctrl+Shift+P(P = Plan)
|
||||
diagnoseQuery: {
|
||||
mac: { combo: 'Meta+Shift+P', enabled: true },
|
||||
windows: { combo: 'Ctrl+Shift+P', enabled: true },
|
||||
},
|
||||
// 慢查询历史:避开 toggleLogPanel 的 Ctrl+H / Meta+Shift+H,用 Ctrl+Shift+L(L = Log)
|
||||
showSlowQueries: {
|
||||
mac: { combo: 'Meta+Shift+L', enabled: true },
|
||||
windows: { combo: 'Ctrl+Shift+L', enabled: true },
|
||||
},
|
||||
openShortcutManager: {
|
||||
mac: { combo: 'Meta+,', enabled: true },
|
||||
windows: { combo: 'Ctrl+,', enabled: true },
|
||||
|
||||
@@ -386,6 +386,10 @@
|
||||
"app.shortcuts.action.toggleMacFullscreen.label": "Nativen Vollbildmodus umschalten",
|
||||
"app.shortcuts.action.toggleTheme.description": "Zwischen hellem und dunklem Theme wechseln",
|
||||
"app.shortcuts.action.toggleTheme.label": "Theme umschalten",
|
||||
"app.shortcuts.action.diagnoseQuery.description": "EXPLAIN für die aktuelle SQL ausführen und Ausführungsplan mit Indexvorschlägen anzeigen",
|
||||
"app.shortcuts.action.diagnoseQuery.label": "SQL-Diagnose",
|
||||
"app.shortcuts.action.showSlowQueries.description": "Verlauf langsamer SQL-Abfragen für die aktuelle Verbindung anzeigen (Standard-Schwellwert 500ms)",
|
||||
"app.shortcuts.action.showSlowQueries.label": "Langsame SQL-Historie",
|
||||
"app.shortcuts.capture_hint": "Drücken Sie das Tastenkürzel, nachdem Sie auf \"Aufzeichnen\" geklickt haben. Mit Esc brechen Sie die Aufzeichnung ab. Globale Tastenkürzel sollten eine Modifikatortaste enthalten; AI-Chat-Senden unterstützt nur Enter-Kombinationen, Shift+Enter bleibt ein Zeilenumbruch.",
|
||||
"app.shortcuts.capture_waiting": "Tastenkürzel drücken...",
|
||||
"app.shortcuts.context.datagrid": "Datentabelle",
|
||||
|
||||
@@ -386,6 +386,10 @@
|
||||
"app.shortcuts.action.toggleMacFullscreen.label": "Toggle Native Fullscreen",
|
||||
"app.shortcuts.action.toggleTheme.description": "Switch between light and dark themes",
|
||||
"app.shortcuts.action.toggleTheme.label": "Toggle Theme",
|
||||
"app.shortcuts.action.diagnoseQuery.description": "Run EXPLAIN on the current SQL and visualize the execution plan with index suggestions",
|
||||
"app.shortcuts.action.diagnoseQuery.label": "SQL Diagnose",
|
||||
"app.shortcuts.action.showSlowQueries.description": "View slow SQL history for the current connection (default threshold 500ms)",
|
||||
"app.shortcuts.action.showSlowQueries.label": "Slow SQL History",
|
||||
"app.shortcuts.capture_hint": "Press the shortcut after clicking \"Record\". Press Esc to cancel recording. Global shortcuts should include a modifier; AI chat send only supports Enter-related combinations, and Shift+Enter keeps inserting a new line.",
|
||||
"app.shortcuts.capture_waiting": "Press a shortcut...",
|
||||
"app.shortcuts.context.datagrid": "Data Grid",
|
||||
|
||||
@@ -386,6 +386,10 @@
|
||||
"app.shortcuts.action.toggleMacFullscreen.label": "ネイティブフルスクリーン切り替え",
|
||||
"app.shortcuts.action.toggleTheme.description": "ライトテーマとダークテーマを切り替えます",
|
||||
"app.shortcuts.action.toggleTheme.label": "テーマを切り替え",
|
||||
"app.shortcuts.action.diagnoseQuery.description": "現在の SQL に対して EXPLAIN を実行し、実行計画図とインデックス提案を表示します",
|
||||
"app.shortcuts.action.diagnoseQuery.label": "SQL 診断",
|
||||
"app.shortcuts.action.showSlowQueries.description": "現在の接続のスロー SQL 履歴を表示(デフォルト閾値 500ms)",
|
||||
"app.shortcuts.action.showSlowQueries.label": "スロー SQL 履歴",
|
||||
"app.shortcuts.capture_hint": "「記録」をクリックした後にショートカットを押してください。Esc で記録をキャンセルできます。グローバルショートカットには修飾キーを含めることを推奨します。AI チャット送信は Enter 関連の組み合わせのみ対応し、Shift+Enter は改行のままです。",
|
||||
"app.shortcuts.capture_waiting": "ショートカットを押してください...",
|
||||
"app.shortcuts.context.datagrid": "データグリッド",
|
||||
|
||||
@@ -386,6 +386,10 @@
|
||||
"app.shortcuts.action.toggleMacFullscreen.label": "Переключить нативный полноэкранный режим",
|
||||
"app.shortcuts.action.toggleTheme.description": "Переключение между светлой и темной темами",
|
||||
"app.shortcuts.action.toggleTheme.label": "Переключить тему",
|
||||
"app.shortcuts.action.diagnoseQuery.description": "Выполнить EXPLAIN для текущего SQL и показать план выполнения с предложениями индексов",
|
||||
"app.shortcuts.action.diagnoseQuery.label": "SQL-диагностика",
|
||||
"app.shortcuts.action.showSlowQueries.description": "Просмотр истории медленных SQL-запросов для текущего подключения (порог по умолчанию 500мс)",
|
||||
"app.shortcuts.action.showSlowQueries.label": "История медленных SQL",
|
||||
"app.shortcuts.capture_hint": "Нажмите сочетание клавиш после нажатия \"Записать\". Нажмите Esc, чтобы отменить запись. Для глобальных горячих клавиш рекомендуется модификатор; отправка AI-чата поддерживает только комбинации с Enter, а Shift+Enter сохраняет перенос строки.",
|
||||
"app.shortcuts.capture_waiting": "Нажмите сочетание клавиш...",
|
||||
"app.shortcuts.context.datagrid": "Таблица данных",
|
||||
|
||||
@@ -386,6 +386,10 @@
|
||||
"app.shortcuts.action.toggleMacFullscreen.label": "切换原生全屏",
|
||||
"app.shortcuts.action.toggleTheme.description": "在亮色和暗色主题之间切换",
|
||||
"app.shortcuts.action.toggleTheme.label": "切换主题",
|
||||
"app.shortcuts.action.diagnoseQuery.description": "对当前 SQL 执行 EXPLAIN 并展示执行计划图与索引建议",
|
||||
"app.shortcuts.action.diagnoseQuery.label": "SQL 诊断",
|
||||
"app.shortcuts.action.showSlowQueries.description": "查看当前连接的慢 SQL 历史记录(默认阈值 500ms)",
|
||||
"app.shortcuts.action.showSlowQueries.label": "慢 SQL 历史",
|
||||
"app.shortcuts.capture_hint": "点击“录制”后按下快捷键。按 Esc 可取消录制。全局快捷键建议包含修饰键;AI 聊天发送仅支持 Enter 相关组合,Shift+Enter 保留换行。",
|
||||
"app.shortcuts.capture_waiting": "请按下快捷键...",
|
||||
"app.shortcuts.context.datagrid": "数据表格",
|
||||
|
||||
@@ -386,6 +386,10 @@
|
||||
"app.shortcuts.action.toggleMacFullscreen.label": "切換原生全螢幕",
|
||||
"app.shortcuts.action.toggleTheme.description": "在淺色與深色主題之間切換",
|
||||
"app.shortcuts.action.toggleTheme.label": "切換主題",
|
||||
"app.shortcuts.action.diagnoseQuery.description": "對目前 SQL 執行 EXPLAIN 並顯示執行計劃圖與索引建議",
|
||||
"app.shortcuts.action.diagnoseQuery.label": "SQL 診斷",
|
||||
"app.shortcuts.action.showSlowQueries.description": "檢視目前連線的慢 SQL 歷史記錄(預設閾值 500ms)",
|
||||
"app.shortcuts.action.showSlowQueries.label": "慢 SQL 歷史",
|
||||
"app.shortcuts.capture_hint": "點擊「錄製」後按下快捷鍵。按 Esc 可取消錄製。全域快捷鍵建議包含修飾鍵;AI 聊天傳送僅支援 Enter 相關組合,Shift+Enter 保留換行。",
|
||||
"app.shortcuts.capture_waiting": "請按下快捷鍵...",
|
||||
"app.shortcuts.context.datagrid": "資料表格",
|
||||
|
||||
Reference in New Issue
Block a user