Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ 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.
OpenCite ranks up to 1,000 name matches by affiliation before showing five
suggestions. If more matches exist, it asks for manual review instead of
automatically assigning an ORCID.
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.

Expand Down
66 changes: 55 additions & 11 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { normalizeMetadata } from './metadata/normalizeMetadata.js';
import { getDefaultReleaseTag } from './metadata/releaseTag.js';
import { updateMetadataField } from './metadata/updateMetadataField.js';
import { importGithubMetadata } from './services/githubImporter.js';
import { pickPreferredOrcidCandidate, searchOrcidCandidates } from './services/orcidSearch.js';
import { createOrcidLookupController } from './services/orcidSearch.js';
import { toCitationCff } from './services/citation.js';
import { validateCitationCffText } from './services/citationValidation.js';
import { toZenodoJson } from './services/zenodo.js';
Expand Down Expand Up @@ -92,6 +92,7 @@ const PIPELINE_STEPS = [
];

const WARNING_MESSAGE_MAX_LENGTH = 180;
const INCOMPLETE_ORCID_SEARCH = 'Not all ORCID results could be checked. Refine the name and review suggestions manually.';

function truncateMessage(message, maxLength = WARNING_MESSAGE_MAX_LENGTH) {
const normalized = String(message ?? '').replace(/\s+/g, ' ').trim();
Expand Down Expand Up @@ -409,6 +410,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);
Expand All @@ -425,6 +427,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);
Expand Down Expand Up @@ -682,11 +688,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;
Expand All @@ -697,9 +709,10 @@ export default function App() {
}

try {
const suggestions = await searchOrcidCandidates(author);
const preferred = pickPreferredOrcidCandidate(author, suggestions);

const { suggestions, preferred, incomplete } = await lookup.search(author);
if (!lookup.enabled || lookup.generation !== generation) {
return { form: nextForm, suggestions: {} };
}
if (preferred) {
nextAuthors[index] = {
...nextAuthors[index],
Expand All @@ -708,14 +721,17 @@ export default function App() {
continue;
}

if (suggestions.length > 0) {
if (suggestions.length > 0 || incomplete) {
nextSuggestions[index] = {
loading: false,
suggestions,
error: '',
error: incomplete ? INCOMPLETE_ORCID_SEARCH : '',
};
}
} catch (error) {
if (!lookup.enabled || lookup.generation !== generation) {
return { form: nextForm, suggestions: {} };
}
nextSuggestions[index] = {
loading: false,
suggestions: [],
Expand Down Expand Up @@ -766,10 +782,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) {
Expand Down Expand Up @@ -825,6 +844,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) => ({
Expand All @@ -833,16 +858,24 @@ export default function App() {
}));

try {
const suggestions = await searchOrcidCandidates(author);
const { suggestions, incomplete } = await lookup.search(author);
if (!lookup.enabled || lookup.generation !== generation) {
return;
}
setOrcidSuggestions((current) => ({
...current,
[index]: {
loading: false,
suggestions,
error: suggestions.length > 0 ? '' : 'No ORCID candidates found.',
error: incomplete
? INCOMPLETE_ORCID_SEARCH
: suggestions.length > 0 ? '' : 'No ORCID candidates found.',
},
}));
} catch (error) {
if (!lookup.enabled || lookup.generation !== generation) {
return;
}
setOrcidSuggestions((current) => ({
...current,
[index]: {
Expand All @@ -854,6 +887,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,
Expand Down Expand Up @@ -1402,6 +1444,8 @@ export default function App() {
touchedFields={touchedFields}
importedMetadataAvailable={hasImportedMetadata}
orcidSuggestions={orcidSuggestions}
orcidLookupEnabled={orcidLookupEnabled}
changeOrcidLookup={changeOrcidLookup}
updateField={updateField}
appendGrantSuggestion={appendGrantSuggestion}
appendAllGrantSuggestions={appendAllGrantSuggestions}
Expand Down
16 changes: 14 additions & 2 deletions src/components/MetadataForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export function MetadataForm({
touchedFields = {},
importedMetadataAvailable = false,
orcidSuggestions = {},
orcidLookupEnabled,
changeOrcidLookup,
updateField,
appendGrantSuggestion,
appendAllGrantSuggestions,
Expand Down Expand Up @@ -82,6 +84,10 @@ export function MetadataForm({
<h3 id="section-authors-title">Author list and ORCID</h3>
<p className="section-lede">Add authors in publication order, then enrich with ORCID and affiliation.</p>
</header>
<label className="orcid-lookup-toggle">
<input type="checkbox" checked={orcidLookupEnabled} onChange={changeOrcidLookup} />
<span>Enable ORCID lookup for imports and suggestions</span>
</label>
<label className={`full-width ${shouldShowFieldError('authors') ? 'field-error' : ''}`}>
<span>Authors*</span>
{totalAuthors > AUTHORS_VISIBLE_BY_DEFAULT && (
Expand Down Expand Up @@ -145,7 +151,7 @@ export function MetadataForm({
type="button"
className="secondary"
onClick={() => suggestOrcid(index)}
disabled={orcidSuggestions[index]?.loading}
disabled={!orcidLookupEnabled || orcidSuggestions[index]?.loading}
>
{orcidSuggestions[index]?.loading ? 'Searching…' : 'Suggest ORCID'}
</button>
Expand All @@ -159,7 +165,13 @@ export function MetadataForm({
className="secondary orcid-suggestion"
onClick={() => applySuggestedOrcid(index, candidate)}
>
{candidate.label} - {candidate.orcid.replace('https://orcid.org/', '')}
<span>{candidate.label}</span>
<small>
{candidate.affiliations?.length
? candidate.affiliations.join('; ')
: candidate.affiliation || 'No public affiliation listed'}
</small>
<small>ORCID: {candidate.orcid.replace('https://orcid.org/', '')}</small>
</button>
))}
</div>
Expand Down
Loading
Loading