diff --git a/frontend/src/components/QueryEditor.external-sql-save.test.tsx b/frontend/src/components/QueryEditor.external-sql-save.test.tsx index 0f062af..e82866e 100644 --- a/frontend/src/components/QueryEditor.external-sql-save.test.tsx +++ b/frontend/src/components/QueryEditor.external-sql-save.test.tsx @@ -3557,6 +3557,7 @@ describe('QueryEditor external SQL save', () => { it('keeps the v2 query editor toolbar grouped and compact', () => { const source = readFileSync(new URL('./QueryEditor.tsx', import.meta.url), 'utf8'); + const transactionToolbarSource = readFileSync(new URL('./QueryEditorTransactionToolbar.tsx', import.meta.url), 'utf8'); const css = readFileSync(new URL('../v2-theme.css', import.meta.url), 'utf8'); expect(source).toContain('gn-v2-query-toolbar-selects'); @@ -3569,6 +3570,10 @@ describe('QueryEditor external SQL save', () => { expect(source).toContain('这里仅选择事务执行成功后的 COMMIT 方式'); expect(source).toContain("label: '事务:手动提交'"); expect(source).toContain("label: '事务:自动提交'"); + expect(source).toContain('QueryEditorTransactionToolbar'); + expect(transactionToolbarSource).toContain("className={isV2Ui ? 'gn-v2-query-transaction-toolbar' : undefined}"); + expect(transactionToolbarSource).toContain('事务待提交'); + expect(transactionToolbarSource).toContain('onFinish'); expect(source).toContain('gn-v2-query-toolbar-action-group'); expect(source).toContain('style={isV2Ui ? undefined : { width: 150 }}'); expect(source).toContain('style={isV2Ui ? undefined : { width: 200 }}'); diff --git a/frontend/src/components/QueryEditor.tsx b/frontend/src/components/QueryEditor.tsx index 16b0263..2e90fe2 100644 --- a/frontend/src/components/QueryEditor.tsx +++ b/frontend/src/components/QueryEditor.tsx @@ -36,6 +36,7 @@ import { getColumnDefinitionName, } from '../utils/columnDefinition'; import QueryEditorResultsPanel, { type QueryEditorResultSet } from './QueryEditorResultsPanel'; +import QueryEditorTransactionToolbar, { type PendingSqlEditorTransaction } from './QueryEditorTransactionToolbar'; const SQL_KEYWORDS = [ 'SELECT', 'FROM', 'WHERE', 'LIMIT', 'INSERT', 'UPDATE', 'DELETE', 'JOIN', 'LEFT', 'RIGHT', @@ -758,14 +759,6 @@ const SQL_EDITOR_AUTO_COMMIT_DELAY_OPTIONS = [ { value: 30000, label: '30 秒' }, ]; -type PendingSqlEditorTransaction = { - id: string; - commitMode: 'manual' | 'auto'; - autoCommitDelayMs: number; - createdAt: number; - autoCommitDueAt?: number | null; -}; - const normalizeEditorPosition = (position: any): { lineNumber: number; column: number } | null => { if (!position) return null; const lineNumber = Number(position.positionLineNumber ?? position.lineNumber ?? position.endLineNumber ?? position.startLineNumber ?? position.selectionStartLineNumber); @@ -5247,38 +5240,15 @@ const QueryEditor: React.FC<{ tab: TabData; isActive?: boolean }> = ({ tab, isAc }, wasClosed ? 350 : 0); }; - const sqlEditorTransactionToolbar = pendingSqlTransaction ? ( -
- - {pendingSqlTransaction.commitMode === 'auto' && sqlEditorAutoCommitRemainingSeconds !== null - ? `事务待提交,${sqlEditorAutoCommitRemainingSeconds}s 后自动提交` - : '事务待提交'} - - - -
- ) : null; + const sqlEditorTransactionToolbar = ( + void finishPendingSqlTransaction(action, 'manual')} + /> + ); return (
diff --git a/frontend/src/components/QueryEditorTransactionToolbar.tsx b/frontend/src/components/QueryEditorTransactionToolbar.tsx new file mode 100644 index 0000000..5a84968 --- /dev/null +++ b/frontend/src/components/QueryEditorTransactionToolbar.tsx @@ -0,0 +1,65 @@ +import React from 'react'; +import { Button } from 'antd'; + +export type PendingSqlEditorTransaction = { + id: string; + commitMode: 'manual' | 'auto'; + autoCommitDelayMs: number; + createdAt: number; + autoCommitDueAt?: number | null; +}; + +type QueryEditorTransactionToolbarProps = { + isV2Ui: boolean; + darkMode: boolean; + transaction: PendingSqlEditorTransaction | null; + autoCommitRemainingSeconds: number | null; + onFinish: (action: 'commit' | 'rollback') => void; +}; + +const QueryEditorTransactionToolbar: React.FC = ({ + isV2Ui, + darkMode, + transaction, + autoCommitRemainingSeconds, + onFinish, +}) => { + if (!transaction) { + return null; + } + + return ( +
+ + {transaction.commitMode === 'auto' && autoCommitRemainingSeconds !== null + ? `事务待提交,${autoCommitRemainingSeconds}s 后自动提交` + : '事务待提交'} + + + +
+ ); +}; + +export default QueryEditorTransactionToolbar;