Skip to content

Commit

Permalink
Merge pull request #493 from shinyichen/SCIX-437-error-orcid-dashboard
Browse files Browse the repository at this point in the history
fix orcid namevariations undefined
  • Loading branch information
shinyichen authored Jul 5, 2024
2 parents 338383b + d3e4c80 commit 9f8a7b7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/components/Orcid/UserSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const AliasEditableControls = (props: { name: string; index: number }) => {
const initRef = useRef<HTMLButtonElement>(null);

const handleRemove = useCallback(() => {
if (isNotNilOrEmpty(preferences)) {
if (isNotNilOrEmpty(preferences) && isNotNilOrEmpty(preferences.nameVariations)) {
setPreferences({ preferences: { ...preferences, nameVariations: remove(index, 1, preferences.nameVariations) } });
}
onClose();
Expand Down Expand Up @@ -270,12 +270,12 @@ const AliasList = () => {

return (
<>
{preferences?.nameVariations.length === 0 ? (
{preferences?.nameVariations?.length === 0 ? (
<Box my={1}>
<Text>No aliases found</Text>
</Box>
) : null}
{preferences?.nameVariations.map((name, index) => (
{preferences?.nameVariations?.map((name, index) => (
<Box my={1} key={name}>
<AliasEditor name={name} index={index} />
</Box>
Expand All @@ -296,7 +296,7 @@ const AddNewAliasButton = () => {
const cleanName = escapeHtml(name.trim());

// if already there, warn about it
if (preferences.nameVariations.includes(cleanName)) {
if (preferences.nameVariations?.includes(cleanName)) {
setError('Alias already exists');
return;
}
Expand All @@ -306,7 +306,7 @@ const AddNewAliasButton = () => {
setPreferences({
preferences: {
...preferences,
nameVariations: [...preferences.nameVariations, name],
nameVariations: preferences.nameVariations ? [...preferences.nameVariations, name] : [name],
},
});
setAddingNew(false);
Expand Down Expand Up @@ -385,9 +385,10 @@ const AddNewAliasButton = () => {
variant="outline"
w={['full', 'auto']}
rightIcon={<Icon fontSize="14" as={MagnifyingGlassIcon} />}
params={{ q: `author:(${preferences?.nameVariations.map(wrapName).join(' OR ')})` }}
params={{ q: `author:(${preferences?.nameVariations?.map(wrapName).join(' OR ')})` }}
isDisabled={!preferences?.nameVariations || preferences?.nameVariations.length === 0}
>
<>{preferences?.nameVariations.length > 1 ? 'Search by aliases' : 'Search by alias'}</>
<>{preferences?.nameVariations?.length > 1 ? 'Search by aliases' : 'Search by alias'}</>
</SearchQueryLinkButton>
</Stack>
);
Expand Down

0 comments on commit 9f8a7b7

Please sign in to comment.