Skip to content

Commit

Permalink
Merge pull request #5288 from specify/issue-5264
Browse files Browse the repository at this point in the history
Handle case where tree definition doesn't exist for a tree
  • Loading branch information
sharadsw authored Oct 2, 2024
2 parents f429d81 + 693067a commit 2a0b516
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions specifyweb/frontend/js_src/lib/components/Toolbar/TreeRepair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,16 @@ export function TreeSelectDialog({
: hasTreeAccess(treeName, 'read')
)
.map((treeName) => {
const treeDefinition = deserializeResource(
getTreeDefinitions(treeName)[0].definition
const treeDefinitions = getTreeDefinitions(treeName);
if (treeDefinitions.length === 0) {
console.warn(`No tree definitions exist for ${treeName}`);
return [treeName, undefined] as const;
}

const defaultTreeDefinition = deserializeResource(
treeDefinitions[0].definition
);
return [treeName, treeDefinition] as const;
return [treeName, defaultTreeDefinition] as const;
})
: undefined,
[permissionName, treeRanks]
Expand Down Expand Up @@ -106,11 +112,7 @@ export function TreeSelectDialog({
<Link.Default
className="flex-1"
href={getLink(treeName)}
title={
(treeDefinition?.get('remarks') as
| LocalizedString
| undefined) ?? undefined
}
title={treeDefinition?.get('remarks') ?? undefined}
onClick={(event): void => {
if (handleClick === undefined) return;
event.preventDefault();
Expand Down

0 comments on commit 2a0b516

Please sign in to comment.