v1 of protocol checker
All checks were successful
Deploy to Server / deploy (push) Successful in 34s

This commit is contained in:
Aniketh Kalagara
2026-04-14 19:08:02 -05:00
parent 2f69f57cf7
commit 4098453c97
7 changed files with 328 additions and 57 deletions

View File

@@ -66,6 +66,8 @@ const TABLE_COLUMNS: { label: string; key: keyof ChemicalInventory }[] = [
{ label: "Multiple CAS (comma delimited)", key: "multipleCAS" },
];
type ImportColumnMapping = keyof ChemicalInventory | "__skip__";
// ── helpers ────────────────────────────────────────────────────────────────
function daysUntil(dateStr: string) {
@@ -144,7 +146,7 @@ export function Inventory() {
const [importStep, setImportStep] = useState<"upload" | "map" | "result">("upload");
const [importHeaders, setImportHeaders] = useState<string[]>([]);
const [importRows, setImportRows] = useState<string[][]>([]);
const [columnMapping, setColumnMapping] = useState<Record<string, keyof ChemicalInventory | "__skip__">>({});
const [columnMapping, setColumnMapping] = useState<Record<string, ImportColumnMapping>>({});
const [importResult, setImportResult] = useState<{ imported: number; errors: string[] } | null>(null);
const [isImporting, setIsImporting] = useState(false);
const [importError, setImportError] = useState("");
@@ -339,7 +341,7 @@ export function Inventory() {
return s.toLowerCase().replace(/[^a-z0-9]/g, "");
}
function fuzzyMatchColumn(header: string): keyof ChemicalInventory | "__skip__" {
function fuzzyMatchColumn(header: string): ImportColumnMapping {
const norm = normalizeHeader(header);
if (!norm) return "__skip__";
for (const col of TABLE_COLUMNS) {
@@ -349,7 +351,7 @@ export function Inventory() {
const colNorm = normalizeHeader(col.label);
if (colNorm.startsWith(norm) || norm.startsWith(colNorm)) return col.key;
}
let bestKey: keyof ChemicalInventory | "__skip__" = "__skip__";
let bestKey: ImportColumnMapping = "__skip__";
let bestScore = 0.55;
for (const col of TABLE_COLUMNS) {
const colNorm = normalizeHeader(col.label);
@@ -430,7 +432,7 @@ export function Inventory() {
console.log("[import] headers:", headers, "data rows:", dataRows.length);
setImportHeaders(headers);
setImportRows(dataRows);
const mapping: Record<string, keyof ChemicalInventory | ""> = {};
const mapping: Record<string, ImportColumnMapping> = {};
for (const h of headers) mapping[h] = fuzzyMatchColumn(h);
setColumnMapping(mapping);
console.log("[import] advancing to map step");
@@ -662,7 +664,7 @@ export function Inventory() {
<td className="px-3 py-2">
<Select
value={columnMapping[header] ?? ""}
onValueChange={v => setColumnMapping(m => ({ ...m, [header]: v as keyof ChemicalInventory | "__skip__" }))}
onValueChange={v => setColumnMapping(m => ({ ...m, [header]: v as ImportColumnMapping }))}
>
<SelectTrigger className="h-7 text-xs w-48">
<SelectValue placeholder="— skip —" />