Shadcn Diff / Change Review Table
Review a bulk update before it lands: products with changes are highlighted in the catalog, and clicking one opens its changes as a diff to accept or reject, field by field or all at once.
$ npx shadcn add https://www.shad-table.dev/r/change-review-table.jsonSupplier price list + stocktaketouches 11 products of 16
| Product | Price | Stock | Status | Category | Review |
|---|---|---|---|---|---|
Desk MatACC-300 | $35 | 210 | Active | Accessories | |
ACC-310 | $99 | 75 | Active | Accessories | New product |
CHR-001 | $249 | 34 | Active | Seating | 1 change |
Ergo Kneeling ChairCHR-008 | $219 | 22 | Active | Seating | |
CHR-014 | $189 | 12 | Active | Seating | 2 changes |
CHR-020 | $149 | 60 | Draft | Seating | New product |
DSK-090 | $279 | 0 | Archived | Desks | Removal |
Compact DeskDSK-101 | $299 | 41 | Active | Desks | |
DSK-120 | $649 | 8 | Active | Desks | 3 changes |
DSK-122 | $729 | 0 | Draft | Desks | 2 changes |
Clamp Desk LampLMP-020 | $79 | 96 | Active | Lighting | |
LMP-031 | $129 | 51 | Active | Lighting | 1 change |
LMP-044 | $59 | 140 | Active | Lighting | 2 changes |
Rolling PedestalSTR-200 | $189 | 30 | Active | Storage | |
STR-210 | $319 | 17 | Active | Shelving | 1 change |
STR-215 | $39 | 300 | Active | Accessories | 2 changes |
0 accepted · 0 rejected · 17 to review
How it works
1.Each change is a before and an after
An update carries both versions of the record, a new record only the after, and a removed one only the before. The changed fields are worked out by comparing the two, so the bulk update needs no list of what changed.
type Change =| { id: string; kind: 'update'; before: Product; after: Product }| { id: string; kind: 'create'; after: Product }| { id: string; kind: 'delete'; before: Product }
2.Decisions are kept per field, not per row
Every changed field has a key like "p3.price". Accepting or rejecting a cell sets that key; the row buttons set all of a row's keys at once. Anything without a key is still to review, so the row's state (to review, in progress, accepted, rejected, partly accepted) is derived rather than stored.
export function rowState(change, decisions): RowState {const made = keysOf(change).map((k) => decisions[k])const pending = made.filter((d) => !d).lengthif (pending === made.length) return 'pending'if (pending) return 'partial'...}
3.The table is the catalog; the panel is the diff
The table lists every product as it is today, so the update reads in context. Rows with changes to review are tinted with an amber edge, and the values that would change carry a dot. Clicking one slides a card in over the right of the table, inside the same frame, with the product as a diff: unchanged fields as context, each change as a "−" line for the old value and a "+" line for the new one.
Name Oak Standing Desk− Price $649+ Price $699 +7.7%− Stock 8+ Stock 0 -8Category Desks
4.Deciding moves on to the next product
Accept or reject at the bottom of the panel, and it opens the next product still to review, so a whole update can be worked through without going back to the table. When a product has several changes, each "+" line has a checkbox: tick the ones to keep, and the buttons then finish the rest. The arrows in the header step through every product with changes, decided or not, and Escape closes the panel.
function decideKeys(keys, decision, advance = false) {const next = decide(decisions, keys, decision)setDecisions(next)if (advance) setOpenId(nextToReview(openId, next))}
5."To review" works as a queue
The view filter is a column filter whose value includes the decisions, so deciding a row's last change drops it out of "To review" straight away. The filter value is memoized: a new object on every render would make TanStack recompute the rows each time.
const columnFilters = useMemo(() => view === 'all' ? [] : [{ id: 'product', value: { view, decisions } }],[view, decisions],)
6.Applying writes only accepted changes
apply() starts from each record's before and copies over only the accepted fields. New records are added and removals happen only when accepted. Changes still to review are left as they are, so a partial review is safe to apply.
const next = { ...change.before }for (const f of changedFields(change)) {if (decisions[changeKey(change.id, f)] === 'accepted') next[f] = change.after[f]}