From 9e81c263bf89e94cc2d0b6c29e4ab1c56c5a674a Mon Sep 17 00:00:00 2001 From: victor barbier Date: Thu, 28 Nov 2024 17:03:18 +0100 Subject: [PATCH 1/2] fix(networks): fix unwanted graph reload --- client/src/api/networks/network/network.ts | 3 +-- client/src/api/networks/search/search.ts | 6 ++---- .../src/pages/networks/components/clusters/analytics.tsx | 2 +- client/src/pages/networks/components/clusters/button.tsx | 2 +- client/src/pages/networks/components/clusters/index.tsx | 2 +- client/src/pages/networks/components/exports/index.tsx | 2 +- client/src/pages/networks/components/graph/index.tsx | 3 ++- .../parameters/autocomplete-filter-node/index.tsx | 4 ++-- client/src/pages/networks/hooks/useExportData.ts | 4 +--- client/src/pages/networks/hooks/useSearchData.ts | 8 +++++--- client/src/types/network.ts | 5 +---- 11 files changed, 18 insertions(+), 23 deletions(-) diff --git a/client/src/api/networks/network/network.ts b/client/src/api/networks/network/network.ts index ee12de9d..ac4e9b72 100644 --- a/client/src/api/networks/network/network.ts +++ b/client/src/api/networks/network/network.ts @@ -26,7 +26,6 @@ export default async function networkCreate( model: string, filters: NetworkFilters, aggregation: ElasticBuckets, - computeClusters: boolean, parameters: NetworkParameters, lang: string ): Promise { @@ -89,7 +88,7 @@ export default async function networkCreate( forceAtlas2.assign(graph, { iterations: 100, settings: sensibleSettings }) // Add communities - const communities = await communitiesCreate(graph, computeClusters) + const communities = await communitiesCreate(graph, parameters.clusters) // Create network const network: NetworkData = { diff --git a/client/src/api/networks/search/search.ts b/client/src/api/networks/search/search.ts index 469da2ef..6b84e7a1 100644 --- a/client/src/api/networks/search/search.ts +++ b/client/src/api/networks/search/search.ts @@ -39,7 +39,7 @@ const networkSearchBody = (model: string, query?: string | unknown): NetworkSear }, }) -export async function networkSearch({ model, query, options, parameters, filters }: NetworkSearchArgs): Promise { +export async function networkSearch({ model, query, lang, parameters, filters }: NetworkSearchArgs): Promise { const body = networkSearchBody(model, query) if (filters && filters.length > 0) body.query.bool.filter = filters @@ -64,9 +64,7 @@ export async function networkSearch({ model, query, options, parameters, filters return null } - const computeClusters = options?.computeClusters ?? false - const lang = options?.lang ?? "fr" - const network = await networkCreate(query, model, filters, aggregation, computeClusters, parameters, lang) + const network = await networkCreate(query, model, filters, aggregation, parameters, lang) const config = configCreate(model) const info = infoCreate(query, model) diff --git a/client/src/pages/networks/components/clusters/analytics.tsx b/client/src/pages/networks/components/clusters/analytics.tsx index 7750a2e2..72a521b0 100644 --- a/client/src/pages/networks/components/clusters/analytics.tsx +++ b/client/src/pages/networks/components/clusters/analytics.tsx @@ -14,7 +14,7 @@ export default function NetworkAnalytics() { const { screen } = useScreenSize() const { currentTab } = useTab() const { parameters } = useParameters() - const { search, currentQuery } = useSearchData(currentTab, parameters.clusters) + const { search, currentQuery } = useSearchData(currentTab) const clusters = search.data?.network?.clusters if (Boolean(search.error) || !currentQuery || !parameters.clusters) return null diff --git a/client/src/pages/networks/components/clusters/button.tsx b/client/src/pages/networks/components/clusters/button.tsx index 17f440e6..751560cb 100644 --- a/client/src/pages/networks/components/clusters/button.tsx +++ b/client/src/pages/networks/components/clusters/button.tsx @@ -10,7 +10,7 @@ export default function ClustersButton() { const { currentTab } = useTab() const { integrationOptions } = useIntegration() const { parameters, handleParametersChange } = useParameters() - const { search, currentQuery } = useSearchData(currentTab, parameters.clusters) + const { search, currentQuery } = useSearchData(currentTab) if (integrationOptions.showClustersButton === false) return null diff --git a/client/src/pages/networks/components/clusters/index.tsx b/client/src/pages/networks/components/clusters/index.tsx index 659529e7..838321fd 100644 --- a/client/src/pages/networks/components/clusters/index.tsx +++ b/client/src/pages/networks/components/clusters/index.tsx @@ -139,7 +139,7 @@ export default function NetworkClusters() { const intl = useIntl() const { currentTab } = useTab() const { parameters } = useParameters() - const { search, currentQuery } = useSearchData(currentTab, parameters.clusters) + const { search, currentQuery } = useSearchData(currentTab) const [seeMore, setSeeMore] = useState(false) const network = search?.data?.network as NetworkData diff --git a/client/src/pages/networks/components/exports/index.tsx b/client/src/pages/networks/components/exports/index.tsx index f84974db..955e008f 100644 --- a/client/src/pages/networks/components/exports/index.tsx +++ b/client/src/pages/networks/components/exports/index.tsx @@ -9,7 +9,7 @@ export default function NetworkExports() { const intl = useIntl() const { currentTab } = useTab() const { integrationOptions } = useIntegration() - const { search, currentQuery } = useSearchData(currentTab, false) + const { search, currentQuery } = useSearchData(currentTab) const { isExporting, exportFile } = useExportData() if (integrationOptions?.showExports === false) return null diff --git a/client/src/pages/networks/components/graph/index.tsx b/client/src/pages/networks/components/graph/index.tsx index 4900ad38..80ab1a32 100644 --- a/client/src/pages/networks/components/graph/index.tsx +++ b/client/src/pages/networks/components/graph/index.tsx @@ -13,7 +13,7 @@ export default function NetworkGraph() { const { parameters } = useParameters() const { focusItem } = useNetworkContext() const { search, currentQuery, filters } = useSearchData(currentTab, false) - const { search: searchClusters } = useSearchData(currentTab, parameters.clusters) + const { search: searchClusters } = useSearchData(currentTab) const { locale: lang } = useDSFRConfig() const theme = document.documentElement.getAttribute("data-fr-theme") @@ -27,6 +27,7 @@ export default function NetworkGraph() { if (!vosviewer?.network) return const key = JSON.stringify({ currentTab, currentQuery, filters, ...parameters, lang, theme, focusItem }) + console.log("key", key) const vosparams = { largest_component: false, diff --git a/client/src/pages/networks/components/parameters/autocomplete-filter-node/index.tsx b/client/src/pages/networks/components/parameters/autocomplete-filter-node/index.tsx index 7b66928c..6d07e33e 100644 --- a/client/src/pages/networks/components/parameters/autocomplete-filter-node/index.tsx +++ b/client/src/pages/networks/components/parameters/autocomplete-filter-node/index.tsx @@ -5,8 +5,8 @@ import useSearchData from "../../../hooks/useSearchData" export default function AutocompleteFilterNode() { const { currentTab } = useTab() - const { parameters, handleParametersChange } = useParameters() - const { search } = useSearchData(currentTab, parameters.clusters) + const { handleParametersChange } = useParameters() + const { search } = useSearchData(currentTab) const nodes = search?.data?.network?.items?.map((item) => ({ label: item.label, id: item.id })) const autocomplete = diff --git a/client/src/pages/networks/hooks/useExportData.ts b/client/src/pages/networks/hooks/useExportData.ts index 4169f1ec..e1bca1dc 100644 --- a/client/src/pages/networks/hooks/useExportData.ts +++ b/client/src/pages/networks/hooks/useExportData.ts @@ -3,7 +3,6 @@ import useTab from "./useTab" import useSearchData from "./useSearchData" import { NetworkData } from "../../../types/network" import * as XLSX from "xlsx" -import useParameters from "./useParameters" function stringToArrayBuffer(string: string) { const buffer = new ArrayBuffer(string.length) @@ -87,8 +86,7 @@ const exportNetwork = (network: NetworkData) => ({ export default function useExportData() { const { currentTab } = useTab() - const { parameters } = useParameters() - const { search } = useSearchData(currentTab, parameters.clusters) + const { search } = useSearchData(currentTab) const [isLoading, setIsLoading] = useState(false) const exportFile = useCallback( diff --git a/client/src/pages/networks/hooks/useSearchData.ts b/client/src/pages/networks/hooks/useSearchData.ts index 19ab5e9a..0542718d 100644 --- a/client/src/pages/networks/hooks/useSearchData.ts +++ b/client/src/pages/networks/hooks/useSearchData.ts @@ -7,7 +7,7 @@ import { networkSearch } from "../../../api/networks/search/search" import useIntegration from "./useIntegration" import useParameters from "./useParameters" -export default function useSearchData(networkTab: string, computeClusters: boolean) { +export default function useSearchData(networkTab: string, forceClusters?: boolean) { const { currentQuery, filters } = useUrl() const { integrationId, integrationLang } = useIntegration() const { parameters } = useParameters() @@ -15,13 +15,15 @@ export default function useSearchData(networkTab: string, computeClusters: boole const { locale } = useDSFRConfig() const lang = integrationId ? integrationLang : locale + if (forceClusters !== undefined) parameters.clusters = forceClusters + const { data, error, isFetching } = useQuery({ - queryKey: ["network", networkTab, currentQuery, filters, computeClusters, lang, parameters], + queryKey: ["network", networkTab, currentQuery, filters, lang, parameters], queryFn: () => networkSearch({ model: networkTab, query: currentQuery, - options: { computeClusters: computeClusters, lang: lang }, + lang: lang, parameters: parameters, filters, }), diff --git a/client/src/types/network.ts b/client/src/types/network.ts index b6b35a4f..07dfd927 100644 --- a/client/src/types/network.ts +++ b/client/src/types/network.ts @@ -80,10 +80,7 @@ export type NetworkSearchArgs = { model: string query?: string filters?: NetworkFilters - options?: { - computeClusters?: boolean - lang?: string - } + lang?: string parameters?: NetworkParameters } export type NetworkSearchHitsArgs = { From 3f1e0b6010e0c798d78f9e71bfd330b93747b196 Mon Sep 17 00:00:00 2001 From: victor barbier Date: Fri, 29 Nov 2024 14:35:51 +0100 Subject: [PATCH 2/2] feat(filter): add publication tags filter --- .../pages/networks/components/graph/index.tsx | 1 - client/src/pages/networks/locales/de.json | 5 +++- client/src/pages/networks/locales/en.json | 3 +++ client/src/pages/networks/locales/es.json | 3 +++ client/src/pages/networks/locales/fr.json | 3 +++ .../components/publications/filters/index.tsx | 9 +++++-- .../components/publications/filters/tags.tsx | 26 +++++++++++++++++++ client/src/pages/search/locales/de.json | 3 +++ client/src/pages/search/locales/en.json | 3 +++ client/src/pages/search/locales/es.json | 3 +++ client/src/pages/search/locales/fr.json | 3 +++ 11 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 client/src/pages/search/components/publications/filters/tags.tsx diff --git a/client/src/pages/networks/components/graph/index.tsx b/client/src/pages/networks/components/graph/index.tsx index 80ab1a32..9d31be7b 100644 --- a/client/src/pages/networks/components/graph/index.tsx +++ b/client/src/pages/networks/components/graph/index.tsx @@ -27,7 +27,6 @@ export default function NetworkGraph() { if (!vosviewer?.network) return const key = JSON.stringify({ currentTab, currentQuery, filters, ...parameters, lang, theme, focusItem }) - console.log("key", key) const vosparams = { largest_component: false, diff --git a/client/src/pages/networks/locales/de.json b/client/src/pages/networks/locales/de.json index 6b971e76..b2eb53f0 100644 --- a/client/src/pages/networks/locales/de.json +++ b/client/src/pages/networks/locales/de.json @@ -35,6 +35,7 @@ "networks.filters.current.publications.type": "Publikationstyp", "networks.filters.current.publications.year": "Veröffentlichungsjahre", "networks.filters.current.publications.projects.type": "Finanzierungstyp", + "networks.filters.current.publications.tags.id": "Tags", "networks.filters.display": "Ergebnisse anzeigen", "networks.filters.title": "Filter", "networks.filters.active-filter-title": "Aktive Filter", @@ -56,7 +57,9 @@ "search.filters.publications.by-organization": "Nach Zugehörigkeit filtern", "search.filters.publications.by-organization-description": "Wählen Sie eine oder mehrere Zugehörigkeiten aus", "search.filters.publications.by-country": "Nach Land filtern", - "search.filters.publications.by-country-description": "Wählen Sie ein oder mehrere Länder aus", + "search.filters.publications.by-country-description": "Wählen Sie eine oder mehrere Länder aus", + "search.filters.publications.by-tag": "Nach Tag filtern", + "search.filters.publications.by-tag-description": "Wählen Sie einen oder mehrere Tags aus", "search.top.publications.filters.result-count": "{count, plural, =0 {# Veröffentlichung} one {# Veröffentlichung} other {# Veröffentlichungen}}", "search.top.filters.display": "Ergebnisse anzeigen", "search.top.result-more-than": "Mehr als ", diff --git a/client/src/pages/networks/locales/en.json b/client/src/pages/networks/locales/en.json index 70f5ea23..06a68823 100644 --- a/client/src/pages/networks/locales/en.json +++ b/client/src/pages/networks/locales/en.json @@ -57,6 +57,7 @@ "networks.filters.current.publications.type": "Publication Type", "networks.filters.current.publications.year": "Publication Years", "networks.filters.current.publications.projects.type": "Funding Type", + "networks.filters.current.publications.tags.id": "Tags", "networks.filters.display": "Display Results", "networks.filters.title": "Filters", "networks.filters.active-filter-title": "Active Filters", @@ -79,6 +80,8 @@ "search.filters.publications.by-organization-description": "Select one or more affiliations", "search.filters.publications.by-country": "Filter by Country", "search.filters.publications.by-country-description": "Select one or more countries", + "search.filters.publications.by-tag": "Filter by Tag", + "search.filters.publications.by-tag-description": "Select one or more tag", "search.top.publications.filters.result-count": "{count, plural, =0 {# publication} one {# publication} other {# publications}}", "search.top.filters.display": "Display Results", "search.top.result-more-than": "More than ", diff --git a/client/src/pages/networks/locales/es.json b/client/src/pages/networks/locales/es.json index 05317daf..24cf7e35 100644 --- a/client/src/pages/networks/locales/es.json +++ b/client/src/pages/networks/locales/es.json @@ -35,6 +35,7 @@ "networks.filters.current.publications.type": "Tipo de Publicación", "networks.filters.current.publications.year": "Años de Publicación", "networks.filters.current.publications.projects.type": "Tipo de Financiamiento", + "networks.filters.current.publications.tags.id": "Etiquetas", "networks.filters.display": "Mostrar Resultados", "networks.filters.title": "Filtros", "networks.filters.active-filter-title": "Filtros Activos", @@ -57,6 +58,8 @@ "search.filters.publications.by-organization-description": "Seleccione una o más afiliaciones", "search.filters.publications.by-country": "Filtrar por país", "search.filters.publications.by-country-description": "Seleccione una o más países", + "search.filters.publications.by-tag": "Filtrar por etiqueta", + "search.filters.publications.by-tag-description": "Seleccione una o más etiquetas", "search.top.publications.filters.result-count": "{count, plural, =0 {# publicación} one {# publicación} other {# publicaciones}}", "search.top.filters.display": "Mostrar Resultados", "search.top.result-more-than": "Más de ", diff --git a/client/src/pages/networks/locales/fr.json b/client/src/pages/networks/locales/fr.json index 5b49ef44..8ed8982e 100644 --- a/client/src/pages/networks/locales/fr.json +++ b/client/src/pages/networks/locales/fr.json @@ -57,6 +57,7 @@ "networks.filters.current.publications.type": "Type de publication", "networks.filters.current.publications.year": "Années de publication", "networks.filters.current.publications.projects.type": "Type de financement", + "networks.filters.current.publications.tags.id": "Tags", "networks.filters.display": "Afficher les résultats", "networks.filters.title": "Filtres", "networks.filters.active-filter-title": "Filtres actifs", @@ -79,6 +80,8 @@ "search.filters.publications.by-organization-description": "Sélectionnez une ou plusieurs affiliations", "search.filters.publications.by-country": "Filtrer par pays", "search.filters.publications.by-country-description": "Sélectionnez un ou plusieurs pays", + "search.filters.publications.by-tag": "Filter par tag", + "search.filters.publications.by-tag-description": "Sélectionnez un ou plusieurs tag", "search.top.publications.filters.result-count": "{count, plural, =0 {# publication} one {# publication} other {# publications}}", "search.top.filters.display": "Afficher les résultats", "search.top.result-more-than": "Plus de ", diff --git a/client/src/pages/search/components/publications/filters/index.tsx b/client/src/pages/search/components/publications/filters/index.tsx index b3255159..92565f95 100644 --- a/client/src/pages/search/components/publications/filters/index.tsx +++ b/client/src/pages/search/components/publications/filters/index.tsx @@ -11,11 +11,14 @@ import PublicationFunderFilter from "./funders"; import PublicationTypeFilter from "./types"; import PublicationYearFilter from "./years"; import PublicationCountriesFilter from "./countries" - +import PublicationTagsFilter from "./tags" export default function PublicationFilters() { const intl = useIntl() - const { total, search: { isFetching } } = useSearchData(); + const { + total, + search: { isFetching }, + } = useSearchData() const { api } = useUrl() const id = `${api}-filters` @@ -37,6 +40,8 @@ export default function PublicationFilters() {

+ +
diff --git a/client/src/pages/search/components/publications/filters/tags.tsx b/client/src/pages/search/components/publications/filters/tags.tsx new file mode 100644 index 00000000..b0bef690 --- /dev/null +++ b/client/src/pages/search/components/publications/filters/tags.tsx @@ -0,0 +1,26 @@ +import { TagInput, Text } from "@dataesr/dsfr-plus" +import { FormattedMessage } from "react-intl" +import useUrl from "../../../hooks/useUrl" + +export default function PublicationTagsFilter() { + const { currentFilters, handleFilterChange } = useUrl() + + const key = JSON.stringify(currentFilters?.["tags.id"]?.values?.map((tag) => String(tag.value)) || {}) + + return ( + <> + + + + + + + String(tag.value))} + onTagsChange={(tags) => tags.forEach((tag) => handleFilterChange({ field: "tags.id", value: tag }))} + /> + + ) +} diff --git a/client/src/pages/search/locales/de.json b/client/src/pages/search/locales/de.json index ea1f462b..03c32550 100644 --- a/client/src/pages/search/locales/de.json +++ b/client/src/pages/search/locales/de.json @@ -57,6 +57,8 @@ "search.filters.publications.by-organization-description": "Eine oder mehrere Zugehörigkeiten auswählen", "search.filters.publications.by-country": "Nach Land filtern", "search.filters.publications.by-country-description": "Wählen Sie ein oder mehrere Länder aus", + "search.filters.publications.by-tag": "Nach Tag filtern", + "search.filters.publications.by-tag-description": "Wählen Sie einen oder mehrere Tags aus", "search.filters.organizations.by-project": "Nach Finanzierungstyp filtern", "search.filters.organizations.by-project-description": "Einen oder mehrere Finanzierungstypen auswählen", "search.filters.organizations.by-kind": "Nach Sektor filtern", @@ -133,6 +135,7 @@ "search.filters.current.projects.participants.structure.mainAddress.localisationSuggestions": "Standort eines Teilnehmers", "search.filters.current.projects.participants.structure.id": "Teilnehmer", "search.filters.current.publications.isOa": "Zugriffstyp", + "search.filters.current.publications.tags.id": "Tags", "search.filters.current.patents.isInternational": "Ausgewählte Region", "search.filters.current.patents.isOeb": "Ausgewählte Region", "search.filters.current.patents.isGranted": "Ausgestellte Patente", diff --git a/client/src/pages/search/locales/en.json b/client/src/pages/search/locales/en.json index f5123d31..81226d7a 100644 --- a/client/src/pages/search/locales/en.json +++ b/client/src/pages/search/locales/en.json @@ -54,6 +54,8 @@ "search.filters.publications.by-organization-description": "Select one or more affiliations", "search.filters.publications.by-country": "Filter by Country", "search.filters.publications.by-country-description": "Select one or more countries", + "search.filters.publications.by-tag": "Filter by Tag", + "search.filters.publications.by-tag-description": "Select one or more tag", "search.filters.organizations.by-project": "Filter by funding Type", "search.filters.organizations.by-project-description": "Select one or more funding types", "search.filters.organizations.by-kind": "Filter by sector", @@ -130,6 +132,7 @@ "search.filters.current.projects.participants.structure.mainAddress.localisationSuggestions": "Location of a participant", "search.filters.current.projects.participants.structure.id": "Participants", "search.filters.current.publications.isOa": "Access type", + "search.filters.current.publications.tags.id": "Tags", "search.filters.current.patents.isInternational": "Selected region", "search.filters.current.patents.isOeb": "Selected region", "search.filters.current.patents.isGranted": "Granted patents", diff --git a/client/src/pages/search/locales/es.json b/client/src/pages/search/locales/es.json index 60af8528..ebf356a3 100644 --- a/client/src/pages/search/locales/es.json +++ b/client/src/pages/search/locales/es.json @@ -57,6 +57,8 @@ "search.filters.publications.by-organization-description": "Selecciona una o más afiliaciones", "search.filters.publications.by-country": "Filtrar por país", "search.filters.publications.by-country-description": "Seleccione uno o más países", + "search.filters.publications.by-tag": "Filtrar por etiqueta", + "search.filters.publications.by-tag-description": "Seleccione una o más etiquetas", "search.filters.organizations.by-project": "Filtrar por Tipo de Financiamiento", "search.filters.organizations.by-project-description": "Selecciona uno o más tipos de financiamiento", "search.filters.organizations.by-kind": "Filtrar por Sector", @@ -133,6 +135,7 @@ "search.filters.current.projects.participants.structure.mainAddress.localisationSuggestions": "Ubicación de un Participante", "search.filters.current.projects.participants.structure.id": "Participantes", "search.filters.current.publications.isOa": "Tipo de Acceso", + "search.filters.current.publications.tags.id": "Etiquetas", "search.filters.current.patents.isInternational": "Región Seleccionada", "search.filters.current.patents.isOeb": "Región Seleccionada", "search.filters.current.patents.isGranted": "Patentes Concedidas", diff --git a/client/src/pages/search/locales/fr.json b/client/src/pages/search/locales/fr.json index 66bc7e02..d9a36bbb 100644 --- a/client/src/pages/search/locales/fr.json +++ b/client/src/pages/search/locales/fr.json @@ -58,6 +58,8 @@ "search.filters.publications.by-organization-description": "Sélectionnez une ou plusieurs affiliations", "search.filters.publications.by-country": "Filtrer par pays", "search.filters.publications.by-country-description": "Sélectionnez un ou plusieurs pays", + "search.filters.publications.by-tag": "Filter par tag", + "search.filters.publications.by-tag-description": "Sélectionnez un ou plusieurs tag", "search.filters.organizations.by-project": "Filtrer par type de financement", "search.filters.organizations.by-project-description": "Sélectionnez un ou plusieurs types de financement", "search.filters.organizations.by-kind": "Filtrer par secteur", @@ -134,6 +136,7 @@ "search.filters.current.projects.participants.structure.mainAddress.localisationSuggestions": "Localisation d'un participant", "search.filters.current.projects.participants.structure.id": "Participants", "search.filters.current.publications.isOa": "Type d'accès", + "search.filters.current.publications.tags.id": "Tags", "search.filters.current.patents.isInternational": "Région selectionnée", "search.filters.current.patents.isOeb": "Région selectionnée", "search.filters.current.patents.isGranted": "Les brevets délivrés",