Fix 'Mapping already exists' error on second save

After createMapping, the new mapping's id was not stored in allValues
state, so editing the row again fell into the create path instead of
update. Now stores created.id so subsequent saves correctly use updateMapping.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Paul Trowbridge 2026-04-05 20:50:40 -04:00
parent 37a6645af0
commit 10dc92b45e

View File

@ -130,14 +130,14 @@ export default function Mappings({ source }) {
valueKey(x.extracted_value) === k ? { ...x, output: updated.output } : x valueKey(x.extracted_value) === k ? { ...x, output: updated.output } : x
)) ))
} else { } else {
await api.createMapping({ const created = await api.createMapping({
source_name: source, source_name: source,
rule_name: row.rule_name, rule_name: row.rule_name,
input_value: row.extracted_value, input_value: row.extracted_value,
output output
}) })
setAllValues(av => av.map(x => setAllValues(av => av.map(x =>
valueKey(x.extracted_value) === k ? { ...x, is_mapped: true, output } : x valueKey(x.extracted_value) === k ? { ...x, is_mapped: true, mapping_id: created.id, output } : x
)) ))
} }
setDrafts(d => { const n = { ...d }; delete n[k]; return n }) setDrafts(d => { const n = { ...d }; delete n[k]; return n })