Apply TDS cure fallback and SDS/TDS URL filling to AI Lookup button

Previously these enrichments only ran in the label scanner path (ScanLabel).
The AI Lookup button and AiAugmentFromUrl went through separate code that
returned raw LookupAsync / LookupByUrlAsync results with no TDS fallback
and no SDS/TDS URL propagation to the form.

- InventoryController.ApplyTdsCureFallbackAsync: new private helper that
  checks whether cure temp or cure time is still null after the primary
  lookup, and if a TDS URL was returned calls FetchTdsCureSpecsAsync to
  fill the gap. Mutates the result in place so callers just return it.
- AiLookup: calls ApplyTdsCureFallbackAsync after LookupAsync succeeds.
- AiAugmentFromUrl: calls ApplyTdsCureFallbackAsync after LookupByUrlAsync.
- ScanLabel: replaced the inline TDS fallback block with a call to the
  same helper (merges catalog TDS URL into aiResult first so the helper
  sees the best available URL).
- _InventoryColorFamilyScripts.cshtml: added fillDocUrl() helper that fills
  field-sdsurl / field-tdsurl inputs and shows their open-link buttons when
  the AI lookup returns sdsUrl / tdsUrl. These fields existed in the form
  but were never populated by the AI Lookup button.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-03 20:19:43 -04:00
parent 4182286a31
commit 145da7b5c4
2 changed files with 46 additions and 16 deletions
@@ -450,6 +450,21 @@
aiFilledImage = true;
}
// SDS / TDS document URLs — fill inputs and show open-link buttons
const fillDocUrl = (fieldId, linkId, url, label) => {
if (!url) return;
const el = document.getElementById(fieldId);
const link = document.getElementById(linkId);
if (el && (forceRefill || !el.value.trim())) {
el.value = url;
filled.push(label);
if (!aiFilledFields.includes(fieldId)) aiFilledFields.push(fieldId);
}
if (link) { link.href = url; link.classList.remove('d-none'); }
};
fillDocUrl('field-sdsurl', 'field-sdsurl-link', data.sdsUrl, 'SDS');
fillDocUrl('field-tdsurl', 'field-tdsurl-link', data.tdsUrl, 'TDS');
// Build a persistent "needs more info" tip if key identity fields are still unknown
const missingHints = [];
if (!data.manufacturer && !document.getElementById('field-manufacturer')?.value?.trim())