diff --git a/src/components/RdmAuditWorkspace.tsx b/src/components/RdmAuditWorkspace.tsx index 44860f5..c4871b9 100644 --- a/src/components/RdmAuditWorkspace.tsx +++ b/src/components/RdmAuditWorkspace.tsx @@ -7,6 +7,7 @@ import { Chip, Collapsible, EmptyState, SectionLabel } from '@ui' import { classifyRdmError } from '../rdmErrors' import { describeAuditEvent, describeTreeItem, humanizeKind, humanizeRelation, humanizeState, isTreeItemExpandable, + relationOtherEndpoint, type AuditEventViewInput, } from '../rdmAuditPresentation' import { store, useStore } from '../store' @@ -478,11 +479,11 @@ function TraceTab({ pid }: { pid: string }) {
来源依据({sources.length}) - {sources.length === 0 ?
无来源
: sources.map((r, i) => )} + {sources.length === 0 ?
无来源
: sources.map((r, i) => )}
影响对象({impacts.length}) - {impacts.length === 0 ?
无影响
: impacts.map((r, i) => )} + {impacts.length === 0 ?
无影响
: impacts.map((r, i) => )}
)} @@ -491,8 +492,8 @@ function TraceTab({ pid }: { pid: string }) { ) } -function RelationRow({ r }: { r: RelationEntry }) { - const other = r.from?.id && r.to?.id ? (r.from?.id < r.to?.id ? r.from : r.to) : (r.from || r.to) +function RelationRow({ r, selected }: { r: RelationEntry; selected: { kind: string; id: string } }) { + const other = relationOtherEndpoint(r, selected) const readable = humanizeRelation(r) return (
diff --git a/src/rdmAuditPresentation.test.ts b/src/rdmAuditPresentation.test.ts index 0b7ac6a..d616921 100644 --- a/src/rdmAuditPresentation.test.ts +++ b/src/rdmAuditPresentation.test.ts @@ -1,5 +1,8 @@ import { describe, expect, it } from 'vitest' -import { describeAuditEvent, describeTreeItem, humanizeKind, humanizeRelation, humanizeState, isTreeItemExpandable } from './rdmAuditPresentation' +import { + describeAuditEvent, describeTreeItem, humanizeKind, humanizeRelation, humanizeState, + isTreeItemExpandable, relationOtherEndpoint, +} from './rdmAuditPresentation' describe('RDM audit presentation', () => { it('turns a structured document event into a readable action and impact', () => { @@ -74,4 +77,13 @@ describe('RDM audit presentation', () => { title: '模板内容 3', }) }) + + it('shows the endpoint opposite the selected object in a trace relationship', () => { + const relation = { + from: { kind: 'slice', id: 'slc-6' }, + to: { kind: 'section', id: 'sec-2' }, + } + expect(relationOtherEndpoint(relation, { kind: 'section', id: 'sec-2' })).toEqual(relation.from) + expect(relationOtherEndpoint(relation, { kind: 'slice', id: 'slc-6' })).toEqual(relation.to) + }) }) diff --git a/src/rdmAuditPresentation.ts b/src/rdmAuditPresentation.ts index 2c2093e..fd7da48 100644 --- a/src/rdmAuditPresentation.ts +++ b/src/rdmAuditPresentation.ts @@ -157,6 +157,15 @@ export function humanizeRelation(input: { layer?: string; type?: string; kind?: } } +export function relationOtherEndpoint( + relation: { from?: T; to?: T }, + selected: { kind: string; id: string }, +): T | undefined { + if (relation.to?.kind === selected.kind && relation.to.id === selected.id) return relation.from + if (relation.from?.kind === selected.kind && relation.from.id === selected.id) return relation.to + return relation.from || relation.to +} + export function isTreeItemExpandable(item: { kind: string; hasChildren?: boolean; id?: string; title?: string }): boolean { return item.kind === 'doc' || item.hasChildren === true }