feat(P1④/P1⑤): 改表加列UI + 审批列表入口e2e
- P1④ 改表加列: meta.ts alterEntity(POST /api/meta/entity/{table}/attributes)
+ ModelerPage 行内「加字段」Dialog(复用FieldTable),打破"v1只建新不改表"
+ five-ring.spec.ts 新增"改已有表加列(建模器加字段→元数据落库)"浏览器e2e
- P1⑤ 审批列表入口: 新增 approval-list-entry.spec.ts(纯mock)验生产主路径
转换列表页按钮→选中行(checkOnItemClick)→openApprovalDrawer→AppShell→ApprovalDrawer抽屉打开
- build绿+vitest73;fivering 5/5 + 审批入口 1/1 全绿
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
// 建模器 —— NocoBase 式实体建模入口(五环第①环:元数据→表)。
|
||||
// 仅管理员可用。展示已有实体清单 + 「新建实体」Dialog(表名/显示名/字段表)。
|
||||
// v1 只建新不改表(DECISION:no ALTER)。字段表与引用列选择器见同文件下方组件。
|
||||
// 仅管理员可用。展示已有实体清单 + 「新建实体」Dialog + 行内「加字段」Dialog。
|
||||
// v2:可建新实体 + 给已有实体加字段(受控 ALTER 安全通道,只加列/恒可空)。字段表见同文件下方组件。
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Dialog } from '../components/ui/Dialog';
|
||||
import { getProfile } from '../auth/token';
|
||||
import {
|
||||
listEntities,
|
||||
createEntity,
|
||||
alterEntity,
|
||||
type EntitySummary,
|
||||
type EntityAttr,
|
||||
} from '../api/meta';
|
||||
@@ -32,6 +33,12 @@ export function ModelerPage() {
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [submitErr, setSubmitErr] = useState('');
|
||||
|
||||
// 加字段(改表)态
|
||||
const [alterTarget, setAlterTarget] = useState<string | null>(null);
|
||||
const [alterRows, setAlterRows] = useState<FieldRow[]>([]);
|
||||
const [alterSubmitting, setAlterSubmitting] = useState(false);
|
||||
const [alterErr, setAlterErr] = useState('');
|
||||
|
||||
function reload() {
|
||||
setLoading(true);
|
||||
listEntities()
|
||||
@@ -54,6 +61,9 @@ export function ModelerPage() {
|
||||
// 引用行必须选了目标表才合法(Task 17 填充 referenceTable)
|
||||
const rowsValid = rows.every((r) => r.type !== '引用' || !!r.referenceTable);
|
||||
const canSubmit = tableValid && rowsValid && !submitting;
|
||||
// 加字段:至少一列,引用列必须选了目标表
|
||||
const alterRowsValid = alterRows.length > 0 && alterRows.every((r) => r.type !== '引用' || !!r.referenceTable);
|
||||
const canAlter = alterRowsValid && !alterSubmitting;
|
||||
|
||||
function openDialog() {
|
||||
setTablename('');
|
||||
@@ -78,6 +88,28 @@ export function ModelerPage() {
|
||||
}
|
||||
}
|
||||
|
||||
function openAlter(table: string) {
|
||||
setAlterTarget(table);
|
||||
setAlterRows([]);
|
||||
setAlterErr('');
|
||||
}
|
||||
|
||||
async function submitAlter() {
|
||||
if (!alterTarget) return;
|
||||
setAlterSubmitting(true);
|
||||
setAlterErr('');
|
||||
try {
|
||||
const attributes: EntityAttr[] = alterRows.map(buildAttribute);
|
||||
await alterEntity(alterTarget, attributes);
|
||||
setAlterTarget(null);
|
||||
reload();
|
||||
} catch (e) {
|
||||
setAlterErr((e as Error).message ?? '加字段失败');
|
||||
} finally {
|
||||
setAlterSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ height: '100%', overflow: 'auto', padding: 'var(--pad-lg)' }} data-testid="modeler">
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 16, marginBottom: 16, flexWrap: 'wrap' }}>
|
||||
@@ -107,14 +139,18 @@ export function ModelerPage() {
|
||||
<th style={{ padding: '8px 14px', borderBottom: '1px solid var(--line)' }}>表名</th>
|
||||
<th style={{ padding: '8px 14px', borderBottom: '1px solid var(--line)' }}>显示名</th>
|
||||
<th style={{ padding: '8px 14px', borderBottom: '1px solid var(--line)' }}>实体ID</th>
|
||||
<th style={{ padding: '8px 14px', borderBottom: '1px solid var(--line)' }}>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{entities.map((e) => (
|
||||
<tr key={e.entityId} data-testid="modeler-entity-row">
|
||||
<td style={{ padding: '8px 14px', borderBottom: '1px solid var(--line)' }}>{e.tablename}</td>
|
||||
<td style={{ padding: '8px 14px', borderBottom: '1px solid var(--line)' }} data-testid="modeler-entity-name">{e.tablename}</td>
|
||||
<td style={{ padding: '8px 14px', borderBottom: '1px solid var(--line)' }}>{e.name}</td>
|
||||
<td style={{ padding: '8px 14px', borderBottom: '1px solid var(--line)', color: 'var(--text-3)' }}>{e.entityId}</td>
|
||||
<td style={{ padding: '8px 14px', borderBottom: '1px solid var(--line)' }}>
|
||||
<button className="btn btn-sm" data-testid="modeler-add-field" onClick={() => openAlter(e.tablename)}>加字段</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
@@ -160,6 +196,30 @@ export function ModelerPage() {
|
||||
</div>
|
||||
</Dialog>
|
||||
) : null}
|
||||
|
||||
{alterTarget ? (
|
||||
<Dialog
|
||||
title={`加字段 · ${alterTarget}`}
|
||||
width={720}
|
||||
onClose={() => setAlterTarget(null)}
|
||||
foot={
|
||||
<>
|
||||
<button className="btn" onClick={() => setAlterTarget(null)}>取消</button>
|
||||
<button className="btn btn-primary" data-testid="modeler-alter-submit" disabled={!canAlter} onClick={submitAlter}>
|
||||
{alterSubmitting ? '加字段中…' : '加字段'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div style={{ display: 'grid', gap: 12 }}>
|
||||
<div className="sub-text">
|
||||
给已有实体 <b>{alterTarget}</b> 加列。受控 ALTER:只加列、恒可空(对有数据的表安全),不改/删既有列。
|
||||
</div>
|
||||
<FieldTable rows={alterRows} onChange={setAlterRows} />
|
||||
{alterErr ? <div style={{ color: 'var(--err)', fontSize: 12 }}>{alterErr}</div> : null}
|
||||
</div>
|
||||
</Dialog>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user