Metadata diff

Pro

The change as files: one tab per file, each named by the thing it is (a field, a layout) as well as its path, with a unified diff that highlights the exact words that changed inside a line.

Markdown

Preview

Install

With the Candor CLI

First time? Get started sets up the registry and theme. Or with shadcn directly: npx shadcn@latest add @candor/metadata-diff

Brings in: entity-chip, locale, work, utils · npm: lucide-react@^1.67.0, radix-ui@^1.8.1

Usage

TSX · The example above
"use client"

import type { FileDiff } from "@/lib/work"
import { ChangeDiff } from "@/components/metadata-diff"

const files: FileDiff[] = [
  {
    path: "db/migrations/0142_add_customer_region.sql",
    entity: { kind: "migration", name: "0142_add_customer_region", label: "Add customers.region" },
    change: "create",
    language: "sql",
    hunks: [
      {
        lines: [
          { kind: "add", text: "CREATE TYPE region AS ENUM ('us', 'eu', 'apac', 'other');", newNo: 1 },
          { kind: "add", text: "ALTER TABLE customers ADD COLUMN region region;", newNo: 2 },
          { kind: "add", text: "CREATE INDEX customers_region_idx ON customers (region);", newNo: 3 },
        ],
      },
    ],
  },
  {
    path: "web/src/customers/CustomerHeader.tsx",
    entity: { kind: "component", name: "web/src/customers/CustomerHeader.tsx", label: "CustomerHeader" },
    change: "update",
    language: "tsx",
    hunks: [
      {
        header: "@@ function CustomerHeader @@",
        lines: [
          { kind: "context", text: '      <Fact label="Plan" value={customer.plan} />', oldNo: 43, newNo: 43 },
          { kind: "remove", text: '      <Fact label="Partner tier" value={customer.partnerTierOld} />', oldNo: 44 },
          { kind: "add", text: '      <Fact label="Region" value={regionLabel(customer.region)} />', newNo: 44 },
          { kind: "context", text: "    </dl>", oldNo: 45, newNo: 45 },
        ],
      },
    ],
  },
]

export default function Example() {
  return <ChangeDiff className="max-w-3xl" files={files} />
}

<ChangeDiff>

PropTypeDefaultDescription
filesrequiredFileDiff[]—The changed files, one tab each.
classNamestring | undefined—Extra classes for the outer element.

Strings

The fixed words, in English by default. Change any of them under metadataDiff in <LocaleProvider strings={{ … }}>; the table is exported as metadataDiffStrings.

KeyEnglish
labelChanges
files{ one: "{count} file", other: "{count} files" }
fileTabsFiles
createNew
updateChanged
deleteDeleted
addedAdded:
removedRemoved: