mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-08 23:53:30 +08:00
🐛 fix(query-editor): 修复切换查询页后 SQL 美化方言误判
- 同步查询页的 connectionId 与 dbName 状态 - 美化时按活动连接和 tab 上下文兜底选择格式化方言 - 补充 PostgreSQL ::date 场景回归测试 Close #494
This commit is contained in:
@@ -2047,6 +2047,19 @@ const QueryEditor: React.FC<{ tab: TabData; isActive?: boolean }> = ({ tab, isAc
|
||||
currentDbRef.current = currentDb;
|
||||
}, [currentDb]);
|
||||
|
||||
useEffect(() => {
|
||||
const nextConnectionId = String(tab.connectionId || '').trim();
|
||||
const nextDb = String(tab.dbName || '').trim();
|
||||
if (nextConnectionId !== currentConnectionIdRef.current) {
|
||||
currentConnectionIdRef.current = nextConnectionId;
|
||||
setCurrentConnectionId(nextConnectionId);
|
||||
}
|
||||
if (nextDb !== currentDbRef.current) {
|
||||
currentDbRef.current = nextDb;
|
||||
setCurrentDb(nextDb);
|
||||
}
|
||||
}, [tab.id, tab.connectionId, tab.dbName]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isExternalSQLFileTab) return;
|
||||
const currentDraft = getQueryTabDraft(tab.id, query);
|
||||
@@ -3704,7 +3717,13 @@ const QueryEditor: React.FC<{ tab: TabData; isActive?: boolean }> = ({ tab, isAc
|
||||
|
||||
const handleFormat = () => {
|
||||
try {
|
||||
const formatterLanguage = resolveQueryEditorFormatterLanguage(connections.find(c => c.id === currentConnectionId));
|
||||
const activeConnectionId = String(currentConnectionIdRef.current || '').trim();
|
||||
const tabConnectionId = String(tab.connectionId || '').trim();
|
||||
const conn = connectionsRef.current.find(c => c.id === activeConnectionId)
|
||||
|| (tabConnectionId && tabConnectionId !== activeConnectionId
|
||||
? connectionsRef.current.find(c => c.id === tabConnectionId)
|
||||
: undefined);
|
||||
const formatterLanguage = resolveQueryEditorFormatterLanguage(conn);
|
||||
const formatted = format(getCurrentQuery(), { language: formatterLanguage, keywordCase: sqlFormatOptions.keywordCase });
|
||||
const editor = editorRef.current;
|
||||
const monaco = monacoRef.current;
|
||||
|
||||
Reference in New Issue
Block a user