From eee46f102a4026f2b11992d355b2c407ff02dd9e Mon Sep 17 00:00:00 2001 From: victor barbier Date: Fri, 15 Nov 2024 13:44:02 +0100 Subject: [PATCH] fix(networks): correct badge when maxYear undefined --- client/src/api/networks/network/communities.ts | 6 ++++-- client/src/pages/networks/components/clusters/index.tsx | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/client/src/api/networks/network/communities.ts b/client/src/api/networks/network/communities.ts index aa659810..5df154e9 100644 --- a/client/src/api/networks/network/communities.ts +++ b/client/src/api/networks/network/communities.ts @@ -36,8 +36,10 @@ const communityGetIds = (graph: Graph, community: number): Array => const communityGetSize = (graph: Graph, community: number): number => graph.filterNodes((_, attr) => attr?.community === community).length -const communityGetMaxYear = (graph: Graph, community: number): number => - Math.max(...communityGetAttribute(graph, community, "maxYear").map(Number)) +const communityGetMaxYear = (graph: Graph, community: number): number => { + const maxYear = Math.max(...communityGetAttribute(graph, community, "maxYear").map(Number)) + return Number.isFinite(maxYear) ? maxYear : undefined +} const communityGetNodes = (graph: Graph, community: number): Array<{ id: string; weight: number; label: string }> => { const ids = communityGetIds(graph, community) diff --git a/client/src/pages/networks/components/clusters/index.tsx b/client/src/pages/networks/components/clusters/index.tsx index 441848e7..b9c8cb6b 100644 --- a/client/src/pages/networks/components/clusters/index.tsx +++ b/client/src/pages/networks/components/clusters/index.tsx @@ -66,7 +66,7 @@ function ClusterItem({ currentTab, community }: ClusterItemArgs) { {`${intl.formatMessage({ id: "networks.section.clusters.open-access" })}: ${community.oaPercent.toFixed(1)}%`} - {`${intl.formatMessage({ id: "networks.section.clusters.last-activity" })}: ${community.maxYear}`} + {`${intl.formatMessage({ id: "networks.section.clusters.last-activity" })}: ${community?.maxYear || "N/A"}`} {`${intl.formatMessage( { id: "networks.section.clusters.citations" },