From b11223277c4ab24378682f5f174c76f7aee62dab Mon Sep 17 00:00:00 2001 From: kempersc Date: Sun, 18 Jan 2026 15:27:04 +0100 Subject: [PATCH] fix(entity-review): persist source URLs for WCMS-only profiles - Add source_urls to WCMS-only profile detail response - Update _candidates_by_wcms cache when creating new WCMS-only entries - Use correct refresh method (fetchWcmsOnlyProfileDetail) after adding source URL Fixes issue where source URLs added to WCMS-only profiles were not displayed after page refresh because: 1. The wcms-only-profile/{email} endpoint wasn't returning source_urls 2. The frontend was calling fetchProfileDetail instead of fetchWcmsOnlyProfileDetail after adding a source URL 3. New WCMS-only entries weren't added to the lookup cache --- frontend/src/pages/EntityReviewPage.tsx | 11 ++++++++--- src/glam_extractor/api/entity_review.py | 20 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/frontend/src/pages/EntityReviewPage.tsx b/frontend/src/pages/EntityReviewPage.tsx index 5759e3ff6a..335589c83c 100644 --- a/frontend/src/pages/EntityReviewPage.tsx +++ b/frontend/src/pages/EntityReviewPage.tsx @@ -752,15 +752,20 @@ export default function EntityReviewPage() { // Hide success message after 3 seconds setTimeout(() => setSourceUrlSuccess(null), 3000); - // Optionally refresh profile (the source URLs aren't displayed yet, but could be in the future) - await fetchProfileDetail(selectedProfile.ppid); + // Refresh profile to show the newly added source URL + // Use appropriate fetch method based on profile type + if (selectedProfile.is_wcms_only && selectedProfile.email) { + await fetchWcmsOnlyProfileDetail(selectedProfile.email); + } else { + await fetchProfileDetail(selectedProfile.ppid); + } } catch (err) { setSourceUrlError(err instanceof Error ? err.message : 'Failed to add source'); } finally { setAddingSourceUrl(false); } - }, [selectedProfile, sourceUrl, sourceComment, language, fetchProfileDetail]); + }, [selectedProfile, sourceUrl, sourceComment, language, fetchProfileDetail, fetchWcmsOnlyProfileDetail]); // Save review decision const saveDecision = useCallback(async (decision: 'match' | 'not_match' | 'uncertain') => { diff --git a/src/glam_extractor/api/entity_review.py b/src/glam_extractor/api/entity_review.py index d3b96b6e36..74e69fb441 100644 --- a/src/glam_extractor/api/entity_review.py +++ b/src/glam_extractor/api/entity_review.py @@ -938,8 +938,19 @@ async def get_wcms_only_profile_detail(email: str): "last_access": wcms_data.get("last_access"), } + # Build PPID for WCMS-only profiles + wcms_only_ppid = f"wcms-only-{wcms_data.get('user_id', email_lower)}" + + # Load candidates to check for source_urls + # WCMS-only profiles that have had sources added will be in candidates file + load_candidates() + source_urls = [] + if _candidates_by_wcms is not None and wcms_only_ppid in _candidates_by_wcms: + source_urls_raw = _candidates_by_wcms[wcms_only_ppid].get('source_urls', []) + source_urls = source_urls_raw # Already list of dicts + return { - "ppid": f"wcms-only-{wcms_data.get('user_id', email_lower)}", + "ppid": wcms_only_ppid, "name": name, "email": wcms_data.get("email", email), "email_domain": email_domain, @@ -949,6 +960,7 @@ async def get_wcms_only_profile_detail(email: str): "match_candidates": [], # Empty - ready for manual LinkedIn addition "annotation_date": None, "is_wcms_only": True, # Flag to indicate this is a WCMS-only profile + "source_urls": source_urls, # Include any added source URLs } @@ -2702,8 +2714,12 @@ async def add_source_url(request: AddSourceUrlRequest): 'source_urls': [source_observation] } _candidates_cache['candidates'].append(new_entry) + + # Also add to the in-memory lookup cache so it can be found on subsequent requests + if _candidates_by_wcms is not None: + _candidates_by_wcms[wcms_ppid] = new_entry - # Also update the wcms lookup cache + # Also update the wcms lookup cache (for existing entries) if _candidates_by_wcms is not None and wcms_ppid in _candidates_by_wcms: if 'source_urls' not in _candidates_by_wcms[wcms_ppid]: _candidates_by_wcms[wcms_ppid]['source_urls'] = []