- apps/web 11건 + apps/admin 10건 accent.amber->main 치환 - packages/ui/src/theme.ts에서 amber/amberDim/amberGlow @deprecated 별칭 제거 (본체 main/dim/glow 유지). 전 모노레포 amber 잔여 0건 확인. SKIP: site/src/tokens.ts(별도 토큰 계통, d3roPalette 비의존) 정책: docs/REFACTOR_POLICY.md DP1, 이식 인사이트 P7
128 lines
3.7 KiB
TypeScript
128 lines
3.7 KiB
TypeScript
'use client'
|
|
|
|
// apps/admin/src/components/audit-diff-viewer.tsx
|
|
// before/after JSON diff 뷰어
|
|
|
|
import { Box } from '@mui/material'
|
|
import { PhosphorText } from '@d3ro/ui/components/ds'
|
|
import { d3roPalette, d3roFontMono, d3roTypo } from '@d3ro/ui/theme'
|
|
|
|
interface AuditDiffViewerProps {
|
|
beforeData: Record<string, unknown> | null
|
|
afterData: Record<string, unknown> | null
|
|
}
|
|
|
|
interface DiffEntry {
|
|
key: string
|
|
before: unknown
|
|
after: unknown
|
|
type: 'added' | 'removed' | 'changed' | 'unchanged'
|
|
}
|
|
|
|
function computeDiff(
|
|
before: Record<string, unknown> | null,
|
|
after: Record<string, unknown> | null
|
|
): DiffEntry[] {
|
|
const allKeys = new Set<string>([
|
|
...Object.keys(before ?? {}),
|
|
...Object.keys(after ?? {}),
|
|
])
|
|
|
|
const entries: DiffEntry[] = []
|
|
for (const key of allKeys) {
|
|
const bVal = before?.[key]
|
|
const aVal = after?.[key]
|
|
const bStr = JSON.stringify(bVal)
|
|
const aStr = JSON.stringify(aVal)
|
|
|
|
if (bVal === undefined) {
|
|
entries.push({ key, before: undefined, after: aVal, type: 'added' })
|
|
} else if (aVal === undefined) {
|
|
entries.push({ key, before: bVal, after: undefined, type: 'removed' })
|
|
} else if (bStr !== aStr) {
|
|
entries.push({ key, before: bVal, after: aVal, type: 'changed' })
|
|
} else {
|
|
entries.push({ key, before: bVal, after: aVal, type: 'unchanged' })
|
|
}
|
|
}
|
|
|
|
// changed/added/removed first
|
|
return entries.sort((a, b) => {
|
|
const order = { changed: 0, added: 1, removed: 2, unchanged: 3 }
|
|
return order[a.type] - order[b.type]
|
|
})
|
|
}
|
|
|
|
const typeColors: Record<DiffEntry['type'], string> = {
|
|
added: d3roPalette.tag.green,
|
|
removed: d3roPalette.tag.red,
|
|
changed: d3roPalette.accent.main,
|
|
unchanged: d3roPalette.text.muted,
|
|
}
|
|
|
|
const typeLabels: Record<DiffEntry['type'], string> = {
|
|
added: '+',
|
|
removed: '-',
|
|
changed: '~',
|
|
unchanged: ' ',
|
|
}
|
|
|
|
function formatValue(val: unknown): string {
|
|
if (val === undefined) return '(none)'
|
|
if (val === null) return 'null'
|
|
if (typeof val === 'string') return `"${val}"`
|
|
return JSON.stringify(val)
|
|
}
|
|
|
|
export function AuditDiffViewer({ beforeData, afterData }: AuditDiffViewerProps): React.ReactElement {
|
|
if (!beforeData && !afterData) {
|
|
return <PhosphorText variant="dim">No diff data</PhosphorText>
|
|
}
|
|
|
|
const diff = computeDiff(beforeData, afterData)
|
|
|
|
return (
|
|
<Box sx={{
|
|
fontFamily: d3roFontMono,
|
|
fontSize: d3roTypo.small.size,
|
|
bgcolor: d3roPalette.bg.inset,
|
|
borderRadius: 1,
|
|
p: 1.5,
|
|
overflow: 'auto',
|
|
}}>
|
|
{diff.map((entry) => (
|
|
<Box
|
|
key={entry.key}
|
|
sx={{
|
|
display: 'flex',
|
|
gap: 1,
|
|
py: 0.25,
|
|
opacity: entry.type === 'unchanged' ? 0.5 : 1,
|
|
}}
|
|
>
|
|
<Box sx={{ color: typeColors[entry.type], width: 12, flexShrink: 0, textAlign: 'center' }}>
|
|
{typeLabels[entry.type]}
|
|
</Box>
|
|
<Box sx={{ color: d3roPalette.text.label, minWidth: 140, flexShrink: 0 }}>
|
|
{entry.key}
|
|
</Box>
|
|
{entry.type === 'changed' ? (
|
|
<Box>
|
|
<Box component="span" sx={{ color: d3roPalette.tag.red, textDecoration: 'line-through' }}>
|
|
{formatValue(entry.before)}
|
|
</Box>
|
|
<Box component="span" sx={{ mx: 0.5, color: d3roPalette.text.muted }}>{'->'}</Box>
|
|
<Box component="span" sx={{ color: d3roPalette.tag.green }}>
|
|
{formatValue(entry.after)}
|
|
</Box>
|
|
</Box>
|
|
) : (
|
|
<Box sx={{ color: typeColors[entry.type] }}>
|
|
{entry.type === 'removed' ? formatValue(entry.before) : formatValue(entry.after)}
|
|
</Box>
|
|
)}
|
|
</Box>
|
|
))}
|
|
</Box>
|
|
)
|
|
}
|