mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-17 22:01:59 +00:00
数据目录 F1-A2:在目录页去掉外键约束、命名推断、数据剖析、模型起草得出的关联关系改为驳回、保留编号,只有人工添加的才真正删除;改了两端的旧关系同样驳回。以前删掉的推断关系下次起草又加回来,关系图按表结构现推也会带回来,照样驱动 SQL 检查和助手挑表。表结构推得出的人工关系(人工改过基数的外键关系)去掉时也只驳回。编辑界面上这类关系不给「删除」只给「驳回」(保存时等同单项驳回,可撤销),检查脚本跟上
This commit is contained in:
@@ -2141,6 +2141,11 @@ export const CATALOG_TEXT = {
|
||||
cardinalityNone: '未知',
|
||||
addRelation: '添加关联关系',
|
||||
removeRelation: '删除这条关联关系',
|
||||
rejectRelation: '驳回',
|
||||
rejectRelationLabel: '驳回这条关联关系',
|
||||
undoRejectRelation: '撤销驳回',
|
||||
rejectingMark: '保存后驳回',
|
||||
relationRemoveHint: '人工添加的关联关系可以删除;外键约束、命名推断、数据剖析得出的只能驳回,驳回后不提供给助手、不参与 SQL 检查,之后起草也不会再提出',
|
||||
relationColumns: '本表字段,用逗号分隔',
|
||||
relationTarget: '目标表',
|
||||
relationToColumns: '目标字段,用逗号分隔',
|
||||
|
||||
@@ -23,7 +23,7 @@ import { CodesDialog } from './CodesDialog'
|
||||
import { coverageText } from './profile'
|
||||
import {
|
||||
COLUMN_FIELDS, DATE_KEYS, TABLE_FIELDS, buildNotes, changeCount, columnPath, confirmProposed, countsOf, formFromNotes,
|
||||
relationDraft, relationPath, tablePath, unknownKeys, validateForm,
|
||||
relationDraft, relationPath, relationRemoval, tablePath, unknownKeys, validateForm,
|
||||
} from './model'
|
||||
import type { ColumnField, EditForm, RelationDraft, TableField, TableKey } from './model'
|
||||
|
||||
@@ -681,42 +681,70 @@ function RelationEditor({ drafts, initial, problems, rows, onChange }: {
|
||||
const patch = (key: string, p: Partial<RelationDraft>) => onChange((rs) => rs.map((r) => (r.key === key ? { ...r, ...p } : r)))
|
||||
return (
|
||||
<div className="space-y-2" data-relation-editor="">
|
||||
<p className="text-2xs leading-relaxed text-faint" data-relation-remove-hint="">{CT.relationRemoveHint}</p>
|
||||
{drafts.map((r) => {
|
||||
const b = before.get(r.key)
|
||||
const changed = !b || b.columns !== r.columns || b.to_table !== r.to_table || b.to_columns !== r.to_columns || b.cardinality !== r.cardinality
|
||||
const problem = problems[`r:${r.key}`]
|
||||
// 人工添加的才能删除;外键约束、命名推断、数据剖析得出的只能驳回(删掉会被起草和现推带回来)
|
||||
const removal = relationRemoval(r.orig)
|
||||
const rejecting = !!r.reject
|
||||
const locked = rejecting ? 'text-faint line-through' : undefined
|
||||
return (
|
||||
<div key={r.key} className="rounded-lg border bg-panel p-2.5" data-relation-draft={r.key}>
|
||||
<div key={r.key} className="rounded-lg border bg-panel p-2.5" data-relation-draft={r.key} data-rejecting={rejecting ? 'true' : undefined}>
|
||||
<div className="grid items-end gap-2 sm:grid-cols-[1fr_1fr_1fr_8rem_auto]">
|
||||
<label className="min-w-0">
|
||||
<span className="label">{CT.relationHead.from}</span>
|
||||
<input className="field mono" value={r.columns} placeholder={CT.relationColumns}
|
||||
<input className={clsx('field mono', locked)} value={r.columns} placeholder={CT.relationColumns} disabled={rejecting}
|
||||
onChange={(e) => patch(r.key, { columns: e.target.value })} data-input="columns" />
|
||||
</label>
|
||||
<label className="min-w-0">
|
||||
<span className="label">{CT.relationTarget}</span>
|
||||
<input className="field mono" list="catalog-tables" value={r.to_table}
|
||||
<input className={clsx('field mono', locked)} list="catalog-tables" value={r.to_table} disabled={rejecting}
|
||||
onChange={(e) => patch(r.key, { to_table: e.target.value })} data-input="to_table" />
|
||||
</label>
|
||||
<label className="min-w-0">
|
||||
<span className="label">{CT.relationHead.toColumns}</span>
|
||||
<input className="field mono" value={r.to_columns} placeholder={CT.relationToColumns}
|
||||
<input className={clsx('field mono', locked)} value={r.to_columns} placeholder={CT.relationToColumns} disabled={rejecting}
|
||||
onChange={(e) => patch(r.key, { to_columns: e.target.value })} data-input="to_columns" />
|
||||
</label>
|
||||
<label className="min-w-0">
|
||||
<span className="label">{CT.relationHead.cardinality}</span>
|
||||
<select className="field" value={r.cardinality} onChange={(e) => patch(r.key, { cardinality: e.target.value })} data-input="cardinality">
|
||||
<select className={clsx('field', locked)} value={r.cardinality} disabled={rejecting}
|
||||
onChange={(e) => patch(r.key, { cardinality: e.target.value })} data-input="cardinality">
|
||||
<option value="">{CT.cardinalityNone}</option>
|
||||
{CARDINALITIES.map((c) => <option key={c} value={c}>{CATALOG_CARDINALITY_LABEL[c]}</option>)}
|
||||
</select>
|
||||
</label>
|
||||
<div className="flex items-center gap-1.5 pb-1">
|
||||
{r.orig && !changed && <StatusChip status={r.orig.status} source={r.orig.source} />}
|
||||
{changed && <span className="chip !text-2xs" style={{ color: 'var(--accent)' }}>{CT.changedMark}</span>}
|
||||
<DeleteButton label={CT.removeRelation} onClick={() => onChange((rs) => rs.filter((x) => x.key !== r.key))} />
|
||||
{rejecting
|
||||
? (
|
||||
<>
|
||||
<span className="chip !text-2xs" style={{ color: 'var(--accent)' }} data-rejecting-mark="">{CT.rejectingMark}</span>
|
||||
<button type="button" className="btn btn-sm btn-ghost !px-1.5" onClick={() => patch(r.key, { reject: false })} data-relation-undo-reject="">
|
||||
{CT.undoRejectRelation}
|
||||
</button>
|
||||
</>
|
||||
)
|
||||
: (
|
||||
<>
|
||||
{r.orig && !changed && <StatusChip status={r.orig.status} source={r.orig.source} />}
|
||||
{changed && <span className="chip !text-2xs" style={{ color: 'var(--accent)' }}>{CT.changedMark}</span>}
|
||||
{removal === 'delete' && (
|
||||
<DeleteButton label={CT.removeRelation} onClick={() => onChange((rs) => rs.filter((x) => x.key !== r.key))} />
|
||||
)}
|
||||
{removal === 'reject' && (
|
||||
// 驳回时两端和基数回到原样:驳回的是原来那条关系,不是改过的
|
||||
<button type="button" className="btn btn-sm btn-ghost !px-1.5" aria-label={CT.rejectRelationLabel} title={CT.rejectRelationLabel}
|
||||
onClick={() => patch(r.key, { ...(b ?? {}), reject: true })} data-relation-reject="">
|
||||
{CT.rejectRelation}
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{problem && <div className="mt-1.5 text-2xs text-[var(--err)]" role="alert">{problem}</div>}
|
||||
{problem && !rejecting && <div className="mt-1.5 text-2xs text-[var(--err)]" role="alert">{problem}</div>}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
||||
@@ -173,7 +173,7 @@ export function confirmProposed(notes: CatalogNotes, pick: (path: string) => boo
|
||||
// ---------------------------------------------------------------------------
|
||||
// 编辑表单:每一项一段文字。进入编辑时按目录生成(被驳回的项留空,原值放在占位里),提交时和进入时的文字逐项
|
||||
// 比较——没动的原样交回(保留来源和状态,被驳回的照旧驳回),改了的交新值(服务端记为人工填写、已确认),
|
||||
// 清空的不交(服务端删掉这一项)
|
||||
// 清空的不交(服务端删掉这一项)。关联关系另有规矩:只有人工添加的能删除,其余的只能驳回(relationRemoval)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** 表级的表单键:业务日期拆成三格 */
|
||||
@@ -189,6 +189,18 @@ export interface RelationDraft {
|
||||
to_table: string
|
||||
to_columns: string
|
||||
cardinality: string
|
||||
/** 编辑中点了「驳回」:保存时原样交回、状态改为已驳回(等同单项驳回) */
|
||||
reject?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉一条关联关系是删除还是驳回:人工添加的(以及还没保存的)可以删除;外键约束、命名推断、数据剖析、模型起草得出的
|
||||
* 只能驳回——删掉的话下次起草、助手和 SQL 检查按表结构现推都会把它带回来(服务端 apply_human_edit 也按这条处理:
|
||||
* 提交里没有的非人工关系转为驳回)。已经驳回的返回 null,没有可做的
|
||||
*/
|
||||
export function relationRemoval(orig: CatalogRelation | null): 'delete' | 'reject' | null {
|
||||
if (!orig || orig.source === 'human') return 'delete'
|
||||
return orig.status === 'rejected' ? null : 'reject'
|
||||
}
|
||||
|
||||
export interface EditForm {
|
||||
@@ -283,7 +295,7 @@ export function changeCount(initial: EditForm, form: EditForm): number {
|
||||
const after = new Set(form.relations.map((r) => r.key))
|
||||
for (const r of form.relations) {
|
||||
const b = before.get(r.key)
|
||||
if (!b || !sameRelation(b, r)) n++
|
||||
if (!b || !sameRelation(b, r) || !!b.reject !== !!r.reject) n++
|
||||
}
|
||||
for (const k of before.keys()) if (!after.has(k)) n++
|
||||
return n
|
||||
@@ -398,6 +410,7 @@ export function buildNotes(orig: CatalogNotes, initial: EditForm, form: EditForm
|
||||
const relations: CatalogRelation[] = []
|
||||
for (const r of form.relations) {
|
||||
const b = before.get(r.key)
|
||||
if (r.orig && r.reject) { relations.push({ ...r.orig, status: 'rejected' }); continue }
|
||||
if (r.orig && b && sameRelation(b, r)) { relations.push(r.orig); continue }
|
||||
relations.push({
|
||||
...(r.orig ?? { coverage: null }),
|
||||
|
||||
Reference in New Issue
Block a user