[Phase 2] Frontend: DataGrid + Editor + SchemaDiagram composite-PK support
Part of the SQL Server Phase 2 epic #150. Depends on #ISSUE_2 (backend CRUD) and #ISSUE_3 (FK aggregation).
The driver isn't on main. Code lives on feat/sql-server and isn't in any release. Check that branch out, branch off it, target your PR at it — not at main. The whole thing squashes into main when Phase 2 closes (#149).
Once the backend supports composite PKs and aggregated FKs, three React components need to carry the new identifier shape through the UI.
Task
1. src/components/ui/DataGrid.tsx (≈ lines 65–84, 400–418)
Add a new optional prop:
pkColumns?: string[]; // composite; overrides `pkColumn` when provided
When present and > 1 columns, the row-edit handlers (~ lines 400–418) must build pk_cols[] / pk_vals[] from the row instead of a single pkCol / pkVal, and pass them to the invoke calls. When pkColumns?.length === 1 or missing → legacy behaviour unchanged.
2. src/pages/Editor.tsx (≈ lines 1670–1717)
Detect composite PK from the column metadata: filter TableColumn[] on is_pk === true, sort by pk_ordinal (a new Option<u32> field you'll add to src-tauri/src/models.rs::TableColumn in the same PR — ship with #[serde(default)] so old JSON deserializes).
Pass pk_cols / pk_vals to invoke('update_record' | 'delete_record', ...) when composite is detected.
3. src/components/ui/SchemaDiagram.tsx (≈ lines 190–229)
Group FK rows by fk.name (constraint name). For each constraint draw one edge with a combined label:
const localCols = first.columns?.length ? first.columns : [first.column_name];
const refCols = first.ref_columns?.length ? first.ref_columns : [first.ref_column];
const label = localCols.length > 1 ? `${localCols.join(',')}→${refCols.join(',')}` : undefined;
When fk.columns is empty (MySQL / Postgres / SQLite drivers still emit the legacy shape), the fallback keeps the single-edge-per-FK behaviour visually identical to today.
Rules
- Zero visual regressions on MySQL / Postgres / SQLite — manual check each driver's ER diagram + editable grid
- Component tests for DataGrid with
pkColumns prop (Vitest / testing-library) — single-key fallback + real composite
npm run typecheck clean
npm run lint clean
Reference
- Plan:
docs/sql-server-implementation-plan.md § Phase 2 — 2.5
- Existing single-PK pattern:
src/components/ui/DataGrid.tsx:183-186 (pkIndexMap)
[Phase 2] Frontend: DataGrid + Editor + SchemaDiagram composite-PK support
Part of the SQL Server Phase 2 epic #150. Depends on #ISSUE_2 (backend CRUD) and #ISSUE_3 (FK aggregation).
The driver isn't on
main. Code lives onfeat/sql-serverand isn't in any release. Check that branch out, branch off it, target your PR at it — not atmain. The whole thing squashes intomainwhen Phase 2 closes (#149).Once the backend supports composite PKs and aggregated FKs, three React components need to carry the new identifier shape through the UI.
Task
1.
src/components/ui/DataGrid.tsx(≈ lines 65–84, 400–418)Add a new optional prop:
When present and
> 1 columns, the row-edit handlers (~ lines 400–418) must buildpk_cols[]/pk_vals[]from the row instead of a singlepkCol/pkVal, and pass them to theinvokecalls. WhenpkColumns?.length === 1or missing → legacy behaviour unchanged.2.
src/pages/Editor.tsx(≈ lines 1670–1717)Detect composite PK from the column metadata: filter
TableColumn[]onis_pk === true, sort bypk_ordinal(a newOption<u32>field you'll add tosrc-tauri/src/models.rs::TableColumnin the same PR — ship with#[serde(default)]so old JSON deserializes).Pass
pk_cols/pk_valstoinvoke('update_record' | 'delete_record', ...)when composite is detected.3.
src/components/ui/SchemaDiagram.tsx(≈ lines 190–229)Group FK rows by
fk.name(constraint name). For each constraint draw one edge with a combined label:When
fk.columnsis empty (MySQL / Postgres / SQLite drivers still emit the legacy shape), the fallback keeps the single-edge-per-FK behaviour visually identical to today.Rules
pkColumnsprop (Vitest / testing-library) — single-key fallback + real compositenpm run typecheckcleannpm run lintcleanReference
docs/sql-server-implementation-plan.md§ Phase 2 — 2.5src/components/ui/DataGrid.tsx:183-186(pkIndexMap)