🐛 fix(table-designer): 优化表设计触发器修改入口

- 修改触发器从固定弹窗改为对象编辑 SQL 标签页
- 生成删除旧触发器和创建新触发器脚本,便于执行前审查
- 抽出触发器编辑 SQL 构造工具,统一 TriggerViewer 与 TableDesigner 逻辑
- 保留新增触发器原弹窗路径,降低行为变更范围
- 新增触发器编辑入口与 SQL 构造回归测试
Refs #557
This commit is contained in:
Syngnat
2026-06-12 17:39:34 +08:00
parent 8519748512
commit ae2b27c4b4
5 changed files with 128 additions and 29 deletions

View File

@@ -0,0 +1,39 @@
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
const tableDesignerSource = readFileSync(
path.resolve(__dirname, './TableDesigner.tsx'),
'utf8',
);
const getFunctionBlock = (source: string, name: string): string => {
const start = source.indexOf(`const ${name} = () => {`);
expect(start).toBeGreaterThanOrEqual(0);
const nextFunction = source.indexOf('\n const ', start + 1);
expect(nextFunction).toBeGreaterThan(start);
return source.slice(start, nextFunction);
};
describe('TableDesigner trigger edit entry', () => {
it('opens trigger edits in an object-edit query tab instead of the fixed modal', () => {
const editBlock = getFunctionBlock(tableDesignerSource, 'handleEditTrigger');
expect(editBlock).toContain('setActiveContext({ connectionId: tab.connectionId, dbName });');
expect(editBlock).toContain('addTab({');
expect(editBlock).toContain("type: 'query'");
expect(editBlock).toContain("queryMode: 'object-edit'");
expect(editBlock).toContain('buildEditableTriggerSql(selectedTrigger.name, createSql');
expect(editBlock).toContain('dropSql: buildDropTriggerSql(selectedTrigger.name)');
expect(editBlock).not.toContain('setIsTriggerEditModalOpen(true)');
});
it('keeps trigger creation on the existing modal path', () => {
const createBlock = getFunctionBlock(tableDesignerSource, 'handleCreateTrigger');
expect(createBlock).toContain("setTriggerEditMode('create')");
expect(createBlock).toContain('setTriggerEditSql(generateTriggerTemplate())');
expect(createBlock).toContain('setIsTriggerEditModalOpen(true)');
});
});