From 212023ad73f5d6b6bdf9c39c23c200f3612af0e2 Mon Sep 17 00:00:00 2001 From: victor barbier Date: Mon, 30 Sep 2024 14:33:57 +0200 Subject: [PATCH] feat(networks): export with clusters --- client/src/api/networks/network/communities.ts | 7 ++++++- client/src/pages/networks/components/analytics.tsx | 2 ++ client/src/pages/networks/hooks/useExportData.ts | 8 +++++++- client/src/types/network.ts | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/client/src/api/networks/network/communities.ts b/client/src/api/networks/network/communities.ts index 4b0e951f..3aae05ce 100644 --- a/client/src/api/networks/network/communities.ts +++ b/client/src/api/networks/network/communities.ts @@ -57,7 +57,11 @@ const communityGetYears = (hits: ElasticHits): Record => return acc }, {}) -// const communityGetPublications = (hits: ElasticHits): Array => hits.map((hit) => hit.title.default) +const communityGetPublications = (hits: ElasticHits): Array> => + hits.map((hit) => ({ + id: hit.id, + title: hit.title.default, + })) const communityGetDomains = (hits: ElasticHits): Record => hits.reduce((acc, hit) => { @@ -105,6 +109,7 @@ export default async function communitiesCreate(graph: Graph, computeClusters: b topWeightNodes: communityGetTopWeightNodes(graph, index), ...(hits && { hits: hits.length, + publications: communityGetPublications(hits), years: communityGetYears(hits), domains: communityGetDomains(hits), oaPercent: communityGetOaPercent(hits), diff --git a/client/src/pages/networks/components/analytics.tsx b/client/src/pages/networks/components/analytics.tsx index b6471a10..974a7d1a 100644 --- a/client/src/pages/networks/components/analytics.tsx +++ b/client/src/pages/networks/components/analytics.tsx @@ -24,6 +24,8 @@ export default function ClustersAnalytics() { ) + console.log("clusters", clusters) + const chartData = clusters.slice(0, 10) const sizeChartOptions = getHorizontalBarChartOptions({ data: chartData, x: "label", y: "size" }) const publicationsChartOptions = getHorizontalBarChartOptions({ diff --git a/client/src/pages/networks/hooks/useExportData.ts b/client/src/pages/networks/hooks/useExportData.ts index 1ab69562..de2a3e77 100644 --- a/client/src/pages/networks/hooks/useExportData.ts +++ b/client/src/pages/networks/hooks/useExportData.ts @@ -2,6 +2,7 @@ import { useCallback, useMemo, useState } from "react" import useTab from "./useTab" import useSearchData from "./useSearchData" import { NetworkData } from "../../../types/network" +import useClusters from "./useClusters" const isString = (x: any) => Object.prototype.toString.call(x) === "[object String]" @@ -48,11 +49,16 @@ const exportNetwork = (network: NetworkData) => ({ cluster: item.cluster, })), links: network.links, + clusters: network.clusters.map((cluster) => ({ + cluster: cluster.cluster, + publications: cluster.publications, + })), }) export default function useExportData() { const { currentTab } = useTab() - const { search } = useSearchData(currentTab, false) + const { clusters: computeClusters } = useClusters() + const { search } = useSearchData(currentTab, computeClusters) const [isLoading, setIsLoading] = useState(false) const exportFile = useCallback( diff --git a/client/src/types/network.ts b/client/src/types/network.ts index fcd714ba..795c252f 100644 --- a/client/src/types/network.ts +++ b/client/src/types/network.ts @@ -41,6 +41,7 @@ export type NetworkCommunity = { years?: Record domains?: Record oaPercent?: number + publications?: Array> } export type NetworkConfig = { terminology?: Record