From 672cac38bce987b0cd5b42b9366905c2cf6e878e Mon Sep 17 00:00:00 2001 From: Sharad S Date: Fri, 27 Sep 2024 13:53:29 -0400 Subject: [PATCH 1/3] Handle case where tree definition doesn't exist for a tree --- .../js_src/lib/components/Toolbar/TreeRepair.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/Toolbar/TreeRepair.tsx b/specifyweb/frontend/js_src/lib/components/Toolbar/TreeRepair.tsx index aac5160bbca..2276f8c8709 100644 --- a/specifyweb/frontend/js_src/lib/components/Toolbar/TreeRepair.tsx +++ b/specifyweb/frontend/js_src/lib/components/Toolbar/TreeRepair.tsx @@ -75,10 +75,12 @@ export function TreeSelectDialog({ : hasTreeAccess(treeName, 'read') ) .map((treeName) => { - const treeDefinition = deserializeResource( - getTreeDefinitions(treeName)[0].definition - ); - return [treeName, treeDefinition] as const; + const treeDefinitions = getTreeDefinitions(treeName); + const defaultTreeDefinition = + treeDefinitions.length > 0 + ? deserializeResource(treeDefinitions[0].definition) + : undefined; + return [treeName, defaultTreeDefinition] as const; }) : undefined, [permissionName, treeRanks] From 227dd9bb14650152e6cede22fea3897b036e9888 Mon Sep 17 00:00:00 2001 From: Sharad S Date: Fri, 27 Sep 2024 17:57:06 +0000 Subject: [PATCH 2/3] Lint code with ESLint and Prettier Triggered by 672cac38bce987b0cd5b42b9366905c2cf6e878e on branch refs/heads/issue-5264 --- .../frontend/js_src/lib/components/Toolbar/TreeRepair.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/Toolbar/TreeRepair.tsx b/specifyweb/frontend/js_src/lib/components/Toolbar/TreeRepair.tsx index 2276f8c8709..e95e41ab402 100644 --- a/specifyweb/frontend/js_src/lib/components/Toolbar/TreeRepair.tsx +++ b/specifyweb/frontend/js_src/lib/components/Toolbar/TreeRepair.tsx @@ -108,11 +108,7 @@ export function TreeSelectDialog({ { if (handleClick === undefined) return; event.preventDefault(); From 693067aa9b349a203c7ad0185bfa88470e527414 Mon Sep 17 00:00:00 2001 From: Sharad S Date: Mon, 30 Sep 2024 09:43:34 -0500 Subject: [PATCH 3/3] Add console warning --- .../js_src/lib/components/Toolbar/TreeRepair.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/Toolbar/TreeRepair.tsx b/specifyweb/frontend/js_src/lib/components/Toolbar/TreeRepair.tsx index e95e41ab402..bcccac2084a 100644 --- a/specifyweb/frontend/js_src/lib/components/Toolbar/TreeRepair.tsx +++ b/specifyweb/frontend/js_src/lib/components/Toolbar/TreeRepair.tsx @@ -76,10 +76,14 @@ export function TreeSelectDialog({ ) .map((treeName) => { const treeDefinitions = getTreeDefinitions(treeName); - const defaultTreeDefinition = - treeDefinitions.length > 0 - ? deserializeResource(treeDefinitions[0].definition) - : undefined; + 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, defaultTreeDefinition] as const; }) : undefined,