fix(geoportal): background enrichment using proven enrichFeatures()

Previous single-parcel enrichment wrote empty data (couldn't match in eTerra).
Now uses the original enrichFeatures() which properly fetches owners, CF, etc.

Changes:
- Enrichment runs in BACKGROUND (returns immediately with message)
- Clears bad enrichment data before re-running
- Tracks running enrichments to avoid duplicates
- GET /api/geoportal/enrich?siruta=... checks if enrichment is running
- Panel: hasRealEnrichment checks for CF/PROPRIETARI/CATEGORIE (not just NR_CAD)
- Enrichment button stays visible until real data exists
- Message: "Enrichment pornit in background. Datele vor aparea in 1-3 minute."

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
AI Assistant
2026-03-24 13:23:44 +02:00
parent d9c247fee2
commit 91034c41ee
2 changed files with 68 additions and 122 deletions
@@ -59,8 +59,8 @@ export function FeatureInfoPanel({ feature, onClose }: FeatureInfoPanelProps) {
? String(feature.properties.name ?? "UAT")
: cadRef ? `Parcela ${cadRef}` : `#${feature.properties.object_id ?? "?"}`;
// Has ANY enrichment data (not just NR_CAD)
const hasEnrichment = !!e && Object.values(e).some((v) => v != null && v !== "" && v !== "-" && v !== 0);
// Has REAL enrichment (not just NR_CAD/SUPRAFATA which come from basic sync)
const hasRealEnrichment = !!e && !!(e.NR_CF || e.PROPRIETARI || e.CATEGORIE_FOLOSINTA || e.INTRAVILAN);
const siruta = String(feature.properties.siruta ?? detail?.siruta ?? "");
const handleEnrich = async () => {
@@ -76,16 +76,7 @@ export function FeatureInfoPanel({ feature, onClose }: FeatureInfoPanelProps) {
});
const d = await resp.json();
if (resp.ok) {
if (d.enrichment && detail) {
setDetail({ ...detail, enrichment: d.enrichment, enrichedAt: new Date().toISOString() });
setEnrichMsg("");
} else {
// Reload from API
const oid = feature.properties.object_id ?? feature.properties.objectId;
const r = await fetch(`/api/geoportal/feature?objectId=${oid}&siruta=${siruta}&sourceLayer=${feature.sourceLayer}`);
if (r.ok) { const data = await r.json(); setDetail(data.feature); }
setEnrichMsg("");
}
setEnrichMsg(d.message ?? "Enrichment pornit");
} else {
setEnrichMsg(d.error ?? "Eroare la enrichment");
}
@@ -132,7 +123,7 @@ export function FeatureInfoPanel({ feature, onClose }: FeatureInfoPanelProps) {
<Row label="Suprafata" value={formatArea(e?.SUPRAFATA_2D ?? feature.properties.area_value)} />
{/* Enrichment data */}
{hasEnrichment && (
{hasRealEnrichment && (
<>
<div className="border-t pt-1.5 mt-1.5" />
<WrapRow label="Proprietari" value={e?.PROPRIETARI} />
@@ -161,7 +152,7 @@ export function FeatureInfoPanel({ feature, onClose }: FeatureInfoPanelProps) {
{/* Action buttons */}
<div className="flex gap-1.5 pt-2 border-t mt-2">
{!hasEnrichment && (
{!hasRealEnrichment && (
<Button
variant="outline" size="sm" className="h-7 text-xs gap-1 flex-1"
onClick={handleEnrich} disabled={enriching}
@@ -211,7 +202,7 @@ export function FeatureInfoPanel({ feature, onClose }: FeatureInfoPanelProps) {
</div>
{enrichMsg && (
<p className="text-xs text-destructive mt-1">{enrichMsg}</p>
<p className="text-xs text-amber-600 dark:text-amber-400 mt-1 leading-relaxed">{enrichMsg}</p>
)}
</>
)}