# Column mapper

Match file columns to the object's fields. Exact name matches, the model's suggestions (with how sure it is) and your own choices are marked apart, so a guess never passes for a match. Required fields left unmapped, and two columns sent to one field, are flagged before anything loads.

- Registry name: `column-mapper` (`@candor/column-mapper`)
- Tier: Pro. Installing it needs a Pro, Premium or Team licence key: the person runs `npx candor-ui key <key>` themselves; never ask for the key in chat or write it to a file.
- Docs: https://candor.themethodic.com/docs/column-mapper

## Install

```bash
npx candor-ui add column-mapper
```

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/column-mapper`.
It brings in: data, locale, select, utils.
npm packages: lucide-react@^1.67.0.

## Example

```tsx
"use client"

import * as React from "react"
import { ColumnMapper } from "@/components/column-mapper"
import type { ColumnMapping, ImportColumn, TargetField } from "@/lib/data"

const columns: ImportColumn[] = [
  { header: "Flag", samples: ["new-billing-page", "dark-mode", "fast-search"] },
  { header: "Repo", samples: ["acme/web", "acme/web", "acme/api"] },
  { header: "Owner Email", samples: ["dana@acme.example", "jonas@acme", "mei@acme.example"] },
  { header: "Rollout %", samples: ["25", "100", "n/a"] },
  { header: "Notes", samples: ["Remove after Q4", "", "Behind a beta"] },
]

const fields: TargetField[] = [
  { name: "key", label: "Flag key", type: "text", required: true },
  { name: "repository", label: "Repository", type: "choice" },
  { name: "owner_id", label: "Owner", type: "id", required: true },
  { name: "rollout", label: "Rollout", type: "number" },
  { name: "description", label: "Description", type: "text" },
]

// Keel's first pass: one exact match, its own suggestions with confidence, and a column it couldn't place.
const suggested: ColumnMapping[] = [
  { header: "Flag", field: "key", by: "model", confidence: 0.91 },
  { header: "Repo", field: "repository", by: "match" },
  { header: "Owner Email", field: null, by: "model", confidence: 0 },
  { header: "Rollout %", field: "rollout", by: "model", confidence: 0.82 },
  { header: "Notes", field: "description", by: "model", confidence: 0.58 },
]

export default function Example() {
  const [mapping, setMapping] = React.useState(suggested)
  return <ColumnMapper className="max-w-2xl" columns={columns} fields={fields} mapping={mapping} onChange={setMapping} />
}
```

## <ColumnMapper>

Props:

- `columns: ImportColumn[]`: The file's columns, with sample values.
- `fields: TargetField[]`: The fields a column can map to; required ones are marked and checked.
- `mapping: ColumnMapping[]`: The current match for each column, and who made it: exact name, the model (with confidence) or you.
- `onChange: (mapping: ColumnMapping[]) => void`: Called with the whole new mapping when a person changes a column's field.
- `className?: string | undefined`

## Strings (`columnMapper`)

The fixed words, English by default. Override any of them under `columnMapper` in `<LocaleProvider strings={{ columnMapper: { … } }}>`; the table is exported as `columnMapperStrings`.

- `mapColumns`: Map columns
- `mapped`: {mapped} of {total} mapped
- `suggestedCount`: {count} suggested
- `requiredMissing`: Required and not mapped: {fields}
- `noValues`: No values
- `fieldFor`: Field for {column}
- `dontImport`: Don’t import
- `clash`: Another column also maps here
- `suggested`: Suggested · {percent}% sure
- `nameMatches`: Name matches
- `yourChoice`: Your choice
- `skipped`: Skipped

## Rules for using Candor UI

- Components take plain typed data. Never pass model output as HTML or render it as a link; messages are typed blocks.
- A control that can't be used says why: wrap it in `<Locked reason="…">`, don't just disable it.
- Don't show a value you don't have: leave it out (it renders as —) rather than guess. An estimate is labelled as one.
- Nothing is pre-selected in a decision a person makes, and the agent is named from your app's data, never from model output.
- Your app's words go in `LocaleProvider` (fixed strings) and `TermsProvider` (nouns); entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
