From 8a3e989c19d71a45c3e8aa1c106dc2b36742143a Mon Sep 17 00:00:00 2001 From: beanbean9339 Date: Sun, 25 Oct 2026 17:11:59 -0400 Subject: [PATCH 1/5] fix: update ORCID query to exclude affiliation and enhance affiliation matching logic --- src/services/orcidSearch.js | 43 ++++++++++++++---------- tests/services/orcidSearch.test.js | 53 ++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 tests/services/orcidSearch.test.js diff --git a/src/services/orcidSearch.js b/src/services/orcidSearch.js index 62d0905..667674e 100644 --- a/src/services/orcidSearch.js +++ b/src/services/orcidSearch.js @@ -2,11 +2,13 @@ function quoteQueryValue(value) { return `"${String(value ?? '').replace(/"/g, '\\"').trim()}"`; } -function buildOrcidQuery({ givenNames, familyNames, affiliation }) { +// Affiliation is intentionally not part of the query: GitHub "Company" values +// (e.g. "@Imageomics, @ABC") rarely match ORCID org names, and requiring a +// match hides valid results. It is only used to rank and disambiguate. +export function buildOrcidQuery({ givenNames, familyNames }) { const parts = []; const given = String(givenNames ?? '').trim(); const family = String(familyNames ?? '').trim(); - const org = String(affiliation ?? '').trim(); if (given) { parts.push(`given-names:${quoteQueryValue(given)}`); @@ -16,10 +18,6 @@ function buildOrcidQuery({ givenNames, familyNames, affiliation }) { parts.push(`family-name:${quoteQueryValue(family)}`); } - if (org) { - parts.push(`affiliation-org-name:${quoteQueryValue(org)}`); - } - return parts.join(' AND '); } @@ -59,15 +57,27 @@ function normalizeName(value) { .trim(); } -function affiliationLooksSimilar(left, right) { - const a = normalizeName(left); - const b = normalizeName(right); +function splitAffiliations(value) { + return String(value ?? '') + .split(/[,;|]/) + .map((part) => normalizeName(part)) + .filter(Boolean); +} + +export function affiliationLooksSimilar(left, right) { + const lefts = splitAffiliations(left); + const rights = splitAffiliations(right); + + return lefts.some((a) => rights.some((b) => a === b || a.includes(b) || b.includes(a))); +} - if (!a || !b) { - return false; +function rankByAffiliation(candidates, affiliation) { + if (!String(affiliation ?? '').trim()) { + return candidates; } - return a === b || a.includes(b) || b.includes(a); + const matching = candidates.filter((candidate) => affiliationLooksSimilar(candidate.affiliation, affiliation)); + return [...matching, ...candidates.filter((candidate) => !matching.includes(candidate))]; } export function pickPreferredOrcidCandidate(author, candidates) { @@ -98,7 +108,7 @@ export async function searchOrcidCandidates(author) { return []; } - const response = await fetch(`https://pub.orcid.org/v3.0/expanded-search/?q=${encodeURIComponent(query)}`, { + const response = await fetch(`https://pub.orcid.org/v3.0/expanded-search/?q=${encodeURIComponent(query)}&rows=20`, { headers: { Accept: 'application/json', }, @@ -111,8 +121,7 @@ export async function searchOrcidCandidates(author) { const payload = await response.json(); const results = Array.isArray(payload?.['expanded-result']) ? payload['expanded-result'] : []; - return results - .map((result) => normalizeCandidate(result)) - .filter(Boolean) - .slice(0, 5); + const candidates = results.map((result) => normalizeCandidate(result)).filter(Boolean); + + return rankByAffiliation(candidates, author?.affiliation).slice(0, 5); } \ No newline at end of file diff --git a/tests/services/orcidSearch.test.js b/tests/services/orcidSearch.test.js new file mode 100644 index 0000000..078e9dc --- /dev/null +++ b/tests/services/orcidSearch.test.js @@ -0,0 +1,53 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; + +import { + affiliationLooksSimilar, + buildOrcidQuery, + pickPreferredOrcidCandidate, + searchOrcidCandidates, +} from '../../src/services/orcidSearch.js'; + +test('ORCID query does not require the affiliation to match', () => { + const query = buildOrcidQuery({ + givenNames: 'Elizabeth', + familyNames: 'Campolongo', + affiliation: '@Imageomics, @ABC, @FAIR4AI-Bio', + }); + + assert.equal(query, 'given-names:"Elizabeth" AND family-name:"Campolongo"'); +}); + +test('affiliation matching handles GitHub company lists', () => { + assert.equal(affiliationLooksSimilar('@Imageomics, @ABC', 'Imageomics Institute'), true); + assert.equal(affiliationLooksSimilar('@Imageomics, @ABC', 'Ohio State University'), false); + assert.equal(affiliationLooksSimilar('', 'Ohio State University'), false); +}); + +test('search finds the ORCID despite a non-matching company and ranks affiliation matches first', async () => { + const originalFetch = globalThis.fetch; + let requestedUrl = ''; + globalThis.fetch = async (url) => { + requestedUrl = String(url); + return { + ok: true, + json: async () => ({ + 'expanded-result': [ + { 'orcid-id': '0000-0000-0000-0001', 'given-names': 'Elizabeth', 'family-names': 'Campolongo', 'institution-name': ['Elsewhere'] }, + { 'orcid-id': '0000-0000-0000-0002', 'given-names': 'Elizabeth', 'family-names': 'Campolongo', 'institution-name': ['Imageomics Institute'] }, + ], + }), + }; + }; + + try { + const author = { givenNames: 'Elizabeth', familyNames: 'Campolongo', affiliation: '@Imageomics, @ABC' }; + const candidates = await searchOrcidCandidates(author); + + assert.ok(!decodeURIComponent(requestedUrl).includes('affiliation-org-name')); + assert.equal(candidates[0].orcid, 'https://orcid.org/0000-0000-0000-0002'); + assert.equal(pickPreferredOrcidCandidate(author, candidates)?.orcid, 'https://orcid.org/0000-0000-0000-0002'); + } finally { + globalThis.fetch = originalFetch; + } +}); From 9ea1996ed3e832c3e200e134c03409475f368036 Mon Sep 17 00:00:00 2001 From: beanbean9339 Date: Sun, 8 Nov 2026 15:21:34 -0500 Subject: [PATCH 2/5] feat: enhance ORCID lookup with affiliation suggestions and toggle functionality --- README.md | 7 ++ src/App.jsx | 55 +++++++++++-- src/components/MetadataForm.jsx | 16 +++- src/services/orcidSearch.js | 111 ++++++++++++++++++++++++-- src/styles.css | 12 +++ tests/components/metadataForm.test.js | 41 ++++++++++ tests/services/orcidSearch.test.js | 70 +++++++++++++++- 7 files changed, 295 insertions(+), 17 deletions(-) create mode 100644 tests/components/metadataForm.test.js diff --git a/README.md b/README.md index 6f4c607..bb80b3e 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,13 @@ version, license, authors, grants, and DOI/references when available. 4. Validate metadata before export. 5. Download generated metadata files (or ZIP export). +ORCID suggestions display the name and public affiliations returned by ORCID +to help distinguish people with similar names. Selecting a suggestion fills +only the ORCID field; existing names and affiliations are left unchanged. +Use **Enable ORCID lookup for imports and suggestions** to disable automatic +and manual lookups. Turning it off cancels pending lookups but does not remove +ORCIDs already entered. + Most users should use the deployed application. Local setup is primarily for contributors and development/testing workflows. diff --git a/src/App.jsx b/src/App.jsx index 992b93b..9908489 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -3,7 +3,7 @@ import JSZip from 'jszip'; import { MetadataForm } from './components/MetadataForm.jsx'; import { normalizeMetadata } from './metadata/normalizeMetadata.js'; import { importGithubMetadata } from './services/githubImporter.js'; -import { pickPreferredOrcidCandidate, searchOrcidCandidates } from './services/orcidSearch.js'; +import { createOrcidLookupController, pickPreferredOrcidCandidate } from './services/orcidSearch.js'; import { toCitationCff } from './services/citation.js'; import { validateCitationCffText } from './services/citationValidation.js'; import { toZenodoJson } from './services/zenodo.js'; @@ -401,6 +401,7 @@ export default function App() { const [previewType, setPreviewType] = useState('citation'); const [copyState, setCopyState] = useState('idle'); const [orcidSuggestions, setOrcidSuggestions] = useState({}); + const [orcidLookupEnabled, setOrcidLookupEnabled] = useState(true); const [exportNotice, setExportNotice] = useState({ kind: '', message: '', details: [] }); const [touchedFields, setTouchedFields] = useState({}); const [hasImportedMetadata, setHasImportedMetadata] = useState(false); @@ -417,6 +418,10 @@ export default function App() { return window.matchMedia?.('(prefers-color-scheme: light)').matches ? 'light' : 'dark'; }); const importRequestIdRef = useRef(0); + const orcidLookupRef = useRef(null); + if (!orcidLookupRef.current) { + orcidLookupRef.current = createOrcidLookupController(); + } useEffect(() => { document.documentElement.setAttribute('data-theme', theme); @@ -674,11 +679,17 @@ export default function App() { } async function resolveOrcidSuggestionsForAuthors(nextForm) { + const lookup = orcidLookupRef.current; + const generation = lookup.generation; const authors = Array.isArray(nextForm.authors) ? nextForm.authors : []; const nextAuthors = [...authors]; const nextSuggestions = {}; for (let index = 0; index < authors.length; index += 1) { + if (!lookup.enabled || lookup.generation !== generation) { + return { form: nextForm, suggestions: {} }; + } + const author = authors[index]; if (String(author?.orcid ?? '').trim()) { continue; @@ -689,7 +700,10 @@ export default function App() { } try { - const suggestions = await searchOrcidCandidates(author); + const suggestions = await lookup.search(author); + if (!lookup.enabled || lookup.generation !== generation) { + return { form: nextForm, suggestions: {} }; + } const preferred = pickPreferredOrcidCandidate(author, suggestions); if (preferred) { @@ -708,6 +722,9 @@ export default function App() { }; } } catch (error) { + if (!lookup.enabled || lookup.generation !== generation) { + return { form: nextForm, suggestions: {} }; + } nextSuggestions[index] = { loading: false, suggestions: [], @@ -758,10 +775,13 @@ export default function App() { let nextSuggestions = {}; const importedMeaningfulMetadata = hasMeaningfulMetadataValues(nextForm); - if (result.errors.length === 0 && importedMeaningfulMetadata) { + if (result.errors.length === 0 && importedMeaningfulMetadata && orcidLookupRef.current.enabled) { + const generation = orcidLookupRef.current.generation; const resolved = await resolveOrcidSuggestionsForAuthors(nextForm); - nextForm = resolved.form; - nextSuggestions = resolved.suggestions; + if (orcidLookupRef.current.enabled && orcidLookupRef.current.generation === generation) { + nextForm = resolved.form; + nextSuggestions = resolved.suggestions; + } } if (importRequestIdRef.current !== requestId) { @@ -817,6 +837,12 @@ export default function App() { } async function suggestOrcid(index) { + const lookup = orcidLookupRef.current; + if (!lookup.enabled) { + return; + } + + const generation = lookup.generation; const author = form.authors[index] ?? {}; setOrcidSuggestions((current) => ({ @@ -825,7 +851,10 @@ export default function App() { })); try { - const suggestions = await searchOrcidCandidates(author); + const suggestions = await lookup.search(author); + if (!lookup.enabled || lookup.generation !== generation) { + return; + } setOrcidSuggestions((current) => ({ ...current, [index]: { @@ -835,6 +864,9 @@ export default function App() { }, })); } catch (error) { + if (!lookup.enabled || lookup.generation !== generation) { + return; + } setOrcidSuggestions((current) => ({ ...current, [index]: { @@ -846,6 +878,15 @@ export default function App() { } } + function changeOrcidLookup(event) { + const enabled = event.target.checked; + orcidLookupRef.current.setEnabled(enabled); + setOrcidLookupEnabled(enabled); + if (!enabled) { + setOrcidSuggestions({}); + } + } + function applySuggestedOrcid(index, candidate) { setForm((current) => ({ ...current, @@ -1394,6 +1435,8 @@ export default function App() { touchedFields={touchedFields} importedMetadataAvailable={hasImportedMetadata} orcidSuggestions={orcidSuggestions} + orcidLookupEnabled={orcidLookupEnabled} + changeOrcidLookup={changeOrcidLookup} updateField={updateField} appendGrantSuggestion={appendGrantSuggestion} appendAllGrantSuggestions={appendAllGrantSuggestions} diff --git a/src/components/MetadataForm.jsx b/src/components/MetadataForm.jsx index 84eaf3c..1c8de34 100644 --- a/src/components/MetadataForm.jsx +++ b/src/components/MetadataForm.jsx @@ -9,6 +9,8 @@ export function MetadataForm({ touchedFields = {}, importedMetadataAvailable = false, orcidSuggestions = {}, + orcidLookupEnabled, + changeOrcidLookup, updateField, appendGrantSuggestion, appendAllGrantSuggestions, @@ -81,6 +83,10 @@ export function MetadataForm({

Author list and ORCID

Add authors in publication order, then enrich with ORCID and affiliation.

+