Skip to content

Commit

Permalink
Austenem/CAT-975 Remove N/A ORCID link (#3612)
Browse files Browse the repository at this point in the history
* add check for invalid orcid ids

* switch to orcid check function

* make orcid function more strict

* update corresponding authors list

* account for X edge case

* fix tests

* restructure validation function

* update names
  • Loading branch information
austenem authored Nov 19, 2024
1 parent c6241c9 commit 454e147
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-remove-na-link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Remove invalid ORCID IDs from Attribution tables.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { StyledTableContainer, HeaderCell } from 'js/shared-styles/tables';
import IconTooltipCell from 'js/shared-styles/tables/IconTooltipCell';
import { CollapsibleDetailPageSection } from 'js/components/detailPage/DetailPageSection';
import EmailIconLink from 'js/shared-styles/Links/iconLinks/EmailIconLink';
import { isValidEmail } from 'js/helpers/functions';
import { isValidEmail, validateAndFormatOrcidId } from 'js/helpers/functions';
import IconPanel from 'js/shared-styles/panels/IconPanel';

import { useNormalizedContacts, useNormalizedContributors } from './hooks';
Expand Down Expand Up @@ -105,6 +105,7 @@ function ContributorsTable({
<TableBody>
{sortedContributors.map((contributor) => {
const { affiliation, name, email, isPrincipalInvestigator, orcid } = contributor;
const validatedOrcidId = validateAndFormatOrcidId(orcid);
return (
<TableRow key={orcid} data-testid="contributor-row">
<TableCell>{`${name}${isPrincipalInvestigator ? ' (PI)' : ''}`}</TableCell>
Expand All @@ -113,9 +114,9 @@ function ContributorsTable({
<ContactCell isContact={contributorIsContact(contributor, normalizedContacts)} email={email} />
</TableCell>
<TableCell>
{orcid && (
<OutboundIconLink href={`https://orcid.org/${orcid}`} variant="body2">
{orcid}
{validatedOrcidId && (
<OutboundIconLink href={`https://orcid.org/${validatedOrcidId}`} variant="body2">
{validatedOrcidId}
</OutboundIconLink>
)}
</TableCell>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { ContactAPIResponse, normalizeContact } from 'js/components/detailPage/ContributorsTable/utils';
import { validateAndFormatOrcidId } from 'js/helpers/functions';
import OutboundIconLink from 'js/shared-styles/Links/iconLinks/OutboundIconLink';
import BulletedList from 'js/shared-styles/lists/bulleted-lists/BulletedList';
import BulletedListItem from 'js/shared-styles/lists/bulleted-lists/BulletedListItem';

function CorrespondingAuthorsList({ contacts }: { contacts: ContactAPIResponse[] }) {
const normalizedContacts = contacts.map((contact) => normalizeContact(contact));
return (
<BulletedList>
{normalizedContacts.map(({ name, orcid }) => {
const validatedOrcidId = validateAndFormatOrcidId(orcid);
return (
<BulletedListItem key={name}>
{name}
&nbsp;
{validatedOrcidId && (
<OutboundIconLink href={`https://orcid.org/${validatedOrcidId}`}>{validatedOrcidId}</OutboundIconLink>
)}
</BulletedListItem>
);
})}
</BulletedList>
);
}

export default CorrespondingAuthorsList;
16 changes: 16 additions & 0 deletions context/app/static/js/helpers/functions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
shouldCapitalizeString,
generateCommaList,
isValidEmail,
validateAndFormatOrcidId,
} from './functions';

test('isEmptyArrayOrObject', () => {
Expand Down Expand Up @@ -129,3 +130,18 @@ test('isValidEmail', () => {
expect(isValidEmail(email)).toStrictEqual(false);
});
});

test('validateAndFormatOrcidId', () => {
expect(validateAndFormatOrcidId('0000-0002-2451-0633')).toEqual('0000-0002-2451-0633');
expect(validateAndFormatOrcidId('0000-0002-2451-063X')).toEqual('0000-0002-2451-063X');
expect(validateAndFormatOrcidId('0000000224510633')).toEqual('0000-0002-2451-0633');
expect(validateAndFormatOrcidId('000000022451063X')).toEqual('0000-0002-2451-063X');
expect(validateAndFormatOrcidId('')).toBeFalsy();
expect(validateAndFormatOrcidId(undefined)).toBeFalsy();
expect(validateAndFormatOrcidId('n/a')).toBeFalsy();
expect(validateAndFormatOrcidId(' 0000-0002-2451-0633 ')).toBeFalsy();
expect(validateAndFormatOrcidId('0000 0002 2451 0633')).toBeFalsy();
expect(validateAndFormatOrcidId('abcd-1234-5678-9101')).toBeFalsy();
expect(validateAndFormatOrcidId('1234-5678-9101')).toBeFalsy();
expect(validateAndFormatOrcidId('12345678901234567')).toBeFalsy();
});
24 changes: 24 additions & 0 deletions context/app/static/js/helpers/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,30 @@ export function isValidEmail(email: string) {
return emailRegex.test(cleanedValue);
}

/**
* Checks if a string is a properly formatted ORCID ID - aka, 16 digits (the final digit may also be an 'X')
* with or without 4 dashes, which is what orcid.org permits in a URL.
* @param orcidId the ORCID ID string to validate and format.
* @returns the formatted ORCID ID if valid, or null if invalid.
*/
export function validateAndFormatOrcidId(orcidId?: string): string | null {
if (typeof orcidId !== 'string' || orcidId.trim() === '') {
return null;
}

const orcidWithDashes = /^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]$/;
const orcidNoDashes = /^[0-9]{15}[0-9X]$/;

if (orcidWithDashes.test(orcidId)) {
return orcidId;
}
if (orcidNoDashes.test(orcidId)) {
return orcidId.replace(/(\d{4})(\d{4})(\d{4})(\d{3}[0-9X])/, '$1-$2-$3-$4');
}

return null;
}

export function getEntityIcon(entity: { entity_type: ESEntityType; is_component?: boolean; processing?: string }) {
if (isDataset(entity)) {
if (entity.is_component) {
Expand Down

0 comments on commit 454e147

Please sign in to comment.