Search docs

Jump to any table example

Discord—

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.json

Supplier price list + stocktaketouches 11 products of 16

ProductPriceStockStatusCategoryReview
Desk MatACC-300
$35210ActiveAccessories
ACC-310
$9975ActiveAccessories
New product
CHR-001
$24934ActiveSeating
1 change
Ergo Kneeling ChairCHR-008
$21922ActiveSeating
CHR-014
$18912ActiveSeating
2 changes
CHR-020
$14960DraftSeating
New product
DSK-090
$2790ArchivedDesks
Removal
Compact DeskDSK-101
$29941ActiveDesks
DSK-120
$6498ActiveDesks
3 changes
DSK-122
$7290DraftDesks
2 changes
Clamp Desk LampLMP-020
$7996ActiveLighting
LMP-031
$12951ActiveLighting
1 change
LMP-044
$59140ActiveLighting
2 changes
Rolling PedestalSTR-200
$18930ActiveStorage
STR-210
$31917ActiveShelving
1 change
STR-215
$39300ActiveAccessories
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.

src/components/change-review/data.ts
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.

src/components/change-review/diff.ts
export function rowState(change, decisions): RowState {
const made = keysOf(change).map((k) => decisions[k])
const pending = made.filter((d) => !d).length
if (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.

src/components/change-review/diff-panel.tsx
Name Oak Standing Desk
− Price $649
+ Price $699 +7.7%
− Stock 8
+ Stock 0 -8
Category 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.

src/components/change-review/index.tsx
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.

src/components/change-review/data-table.tsx
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.

src/components/change-review/diff.ts
const next = { ...change.before }
for (const f of changedFields(change)) {
if (decisions[changeKey(change.id, f)] === 'accepted') next[f] = change.after[f]
}