From 87264baa8ba76f3c4a64fd3521099b8efff2d8bd Mon Sep 17 00:00:00 2001 From: Mihoub Debache Date: Tue, 7 Nov 2023 14:30:47 +0100 Subject: [PATCH] fix(geographical-categories): display sidemenu and filter map --- src/components/map/index.js | 9 +- .../[id]/elements-lies.js | 84 +++++++++-------- .../[id]/presentation.js | 59 +----------- .../[id]/structuresList.js | 91 +++++++++---------- src/pages/categories-geographiques/index.js | 63 +++++++++---- 5 files changed, 138 insertions(+), 168 deletions(-) diff --git a/src/components/map/index.js b/src/components/map/index.js index d85477f1..f4e885fb 100644 --- a/src/components/map/index.js +++ b/src/components/map/index.js @@ -6,10 +6,11 @@ import { MapContainer, Marker, TileLayer, Tooltip, useMap } from 'react-leaflet' const getIcon = (color = '#0078f3') => divIcon({ html: ` - - - - + + + + + `, diff --git a/src/pages/categories-geographiques/[id]/elements-lies.js b/src/pages/categories-geographiques/[id]/elements-lies.js index d4a97995..588e2a3f 100644 --- a/src/pages/categories-geographiques/[id]/elements-lies.js +++ b/src/pages/categories-geographiques/[id]/elements-lies.js @@ -1,4 +1,5 @@ -import { Badge, Col, Container, Row, Title } from '@dataesr/react-dsfr'; +import { Badge, Col, Row, TextInput, Title } from '@dataesr/react-dsfr'; +import { useState } from 'react'; import useFetch from '../../../hooks/useFetch'; import useUrl from '../../../hooks/useUrl'; @@ -12,9 +13,24 @@ export default function GeographicalCategoryRelatedElements() { data: dataStructures, isLoading: structuresLoading, } = useFetch(`${url}/structures`); + const [filter, setFilter] = useState(''); const exceptionGps = []; const exception = useFetch('/geographical-exceptions'); + const filterMarkers = (data) => data + .filter((item) => (item?.currentLocalisation?.geometry?.coordinates || []).length === 2) + .filter((item) => item.currentName.usualName.toLowerCase().includes(filter.toLowerCase())) + .map((item) => ({ + label: item.currentName.usualName, + latLng: [item.currentLocalisation.geometry.coordinates[1], item.currentLocalisation.geometry.coordinates[0]], + address: `{${item.currentLocalisation?.address || ''}, + ${item.currentLocalLocalisation?.postalCode || ''} ${item.currentLocalisation?.locality || ''}, ${item.currentLocalisation?.country}}`, + })); + + const filteredMarkers = filterMarkers(dataStructures?.data || []); + const handleFilterChange = (e) => { + setFilter(e.target.value); + }; if (exception?.data?.data) { const geographicalCategoryIds = exception.data.data.map((item) => item.geographicalCategoryId); @@ -36,32 +52,22 @@ export default function GeographicalCategoryRelatedElements() { if (structuresLoading) { structuresContent = ; } else if (dataStructures?.data?.length > 0) { + const filteredCardsData = dataStructures.data.filter((item) => item.currentName.usualName.toLowerCase().includes(filter.toLowerCase())); structuresContent = ( <> Structures associées - + - + - (item?.currentLocalisation?.geometry?.coordinates || []).length === 2) - .map((item) => ({ - label: item.currentName.usualName, - latLng: [item.currentLocalisation.geometry.coordinates[1], item.currentLocalisation.geometry.coordinates[0]], - address: `{${item.currentLocalisation?.address || ''}, - ${item.currentLocalisation?.postalCode || ''} ${item.currentLocalisation?.locality || ''}, ${item.currentLocalisation?.country}}`, - })) - } - /> + - + + + @@ -69,22 +75,20 @@ export default function GeographicalCategoryRelatedElements() { Autres structures associées en dehors du territoire - - - (item?.currentLocalisation?.geometry?.coordinates || []).length === 2) - .map((item) => ({ - label: item.resource.currentName.displayName, - latLng: [item.currentLocalisation.geometry.coordinates[1], item.currentLocalisation.geometry.coordinates[0]], - address: `${item.currentLocalisation?.address || ''}, + + (item?.currentLocalisation?.geometry?.coordinates || []).length === 2) + .map((item) => ({ + label: item.resource.currentName.displayName, + latLng: [item.currentLocalisation.geometry.coordinates[1], item.currentLocalisation.geometry.coordinates[0]], + address: `${item.currentLocalisation?.address || ''}, ${item.currentLocalisation?.postalCode || ''} ${item.currentLocalisation?.locality || ''}, ${item.currentLocalisation?.country}`, - })) - } - /> - - + })) + } + /> + @@ -93,12 +97,14 @@ export default function GeographicalCategoryRelatedElements() { } return ( - - {/* - Catégorie parente - - {data?.closestParent && } */} + + {structuresContent} - + ); } diff --git a/src/pages/categories-geographiques/[id]/presentation.js b/src/pages/categories-geographiques/[id]/presentation.js index 00f4f41f..215af40a 100644 --- a/src/pages/categories-geographiques/[id]/presentation.js +++ b/src/pages/categories-geographiques/[id]/presentation.js @@ -2,16 +2,13 @@ import { Badge, Col, Row, Title } from '@dataesr/react-dsfr'; import useFetch from '../../../hooks/useFetch'; import useUrl from '../../../hooks/useUrl'; import KeyValueCard from '../../../components/card/key-value-card'; -import Wiki from '../../../components/blocs/wiki'; import { PageSpinner } from '../../../components/spinner'; import Error from '../../../components/errors'; import Map from '../../../components/map/geographical-categories-map'; import { ExceptionStructuresList, - StructuresList, } from './structuresList'; -import { Bloc, BlocActionButton, BlocContent, BlocTitle } from '../../../components/bloc'; -import { exportGeographicalCategoriesStructuresToCsv } from '../../../components/blocs/relations/utils/exports'; +import { BlocTitle } from '../../../components/bloc'; import GeographicalTags from '../../../components/blocs/geographical-tags'; export default function GeographicalCategoryPresentationPage() { @@ -61,8 +58,6 @@ export default function GeographicalCategoryPresentationPage() { })); } - const identifiers = []; - return ( <> { @@ -80,7 +75,6 @@ export default function GeographicalCategoryPresentationPage() { ) } - { data?.parent && ( @@ -91,43 +85,14 @@ export default function GeographicalCategoryPresentationPage() { ) } - - + - - - - - Structures associées - <Badge - className="fr-ml-1w fr-mr-1w" - colorFamily="yellow-tournesol" - text={dataStructures?.totalCount.toString() || '0'} - /> - - - - exportGeographicalCategoriesStructuresToCsv({ - data: dataStructures?.data, - fileName: `structure_${data?.nameFr}`, - })} - > - Télécharger la liste - - - - - - { exceptionGps?.length > 0 && ( @@ -150,26 +115,6 @@ export default function GeographicalCategoryPresentationPage() { ) } - {identifiers.length > 0 && ( - - - Identifiants - - - bloc content - - - - )} - - {data?.wikidata && ( - <> - Présence sur le web - - - - - )} ); } diff --git a/src/pages/categories-geographiques/[id]/structuresList.js b/src/pages/categories-geographiques/[id]/structuresList.js index 0465c03a..955a0346 100644 --- a/src/pages/categories-geographiques/[id]/structuresList.js +++ b/src/pages/categories-geographiques/[id]/structuresList.js @@ -1,4 +1,4 @@ -import { Badge, Col, Icon, Row, Tile, TextInput } from '@dataesr/react-dsfr'; +import { Badge, Col, Icon, Row, Tile } from '@dataesr/react-dsfr'; import PropTypes from 'prop-types'; import { Link as RouterLink } from 'react-router-dom'; import { useState } from 'react'; @@ -18,41 +18,34 @@ const getDescription = (item) => { }; export function StructuresList({ data }) { - const [filter, setFilter] = useState(''); + const [filter] = useState(''); if (!data && !data?.data) { return null; } const list = data .filter((item) => item.currentName.usualName.toLowerCase().indexOf(filter.toLowerCase()) > -1) .map((item) => ( - - - -
-

- - - {getName(item)} - -

-

{getDescription(item)}

-
-
- -
+ + +
+

+ + + {getName(item)} + +

+

{getDescription(item)}

+
+
+ )); return ( - <> - setFilter(e.target.value)} - value={filter} - /> -
- - -
- + + + + + ); } @@ -80,23 +74,24 @@ export function ExceptionStructuresList({ exceptionGps }) { } const list = exceptionGps.map((item) => ( - - -
-

- - - {getName(item)} - -

- {item?.resource?.structureStatus === 'inactive' ? ( - - ) : null} -

{getDescription(item)}

-
-
- - + + + +
+

+ + + {getName(item)} + +

+ {item?.resource?.structureStatus === 'inactive' ? ( + + ) : null} +

{getDescription(item)}

+
+
+ +
)); return ; diff --git a/src/pages/categories-geographiques/index.js b/src/pages/categories-geographiques/index.js index 05d0587c..f5e48d47 100644 --- a/src/pages/categories-geographiques/index.js +++ b/src/pages/categories-geographiques/index.js @@ -2,9 +2,9 @@ import { Link as RouterLink, Outlet } from 'react-router-dom'; import { Badge, BadgeGroup, Breadcrumb, BreadcrumbItem, - Col, Container, Row, - // Icon, - // SideMenu, SideMenuLink, + Col, Container, Icon, Row, + SideMenu, + SideMenuLink, Title, } from '@dataesr/react-dsfr'; import useFetch from '../../hooks/useFetch'; @@ -17,11 +17,14 @@ import GeographicalCategoriesRelatedElements from './[id]/elements-lies'; import Error from '../../components/errors'; import usePageTitle from '../../hooks/usePageTitle'; import { GEOGRAPHICAL_CATEGORIES_LABELS_MAPPER } from '../../utils/constants'; +import Wiki from '../../components/blocs/wiki'; +import { Bloc, BlocContent, BlocTitle } from '../../components/bloc'; function GeographicalCategoriesByIdPage() { const { url } = useUrl(); const { data, isLoading, error } = useFetch(url); usePageTitle(`Catégorie géographique · ${data?.nameFr}`); + const identifiers = []; if (isLoading) return ; if (error) return ; @@ -29,7 +32,7 @@ function GeographicalCategoriesByIdPage() { return ( - {/* + }> @@ -45,8 +48,7 @@ function GeographicalCategoriesByIdPage() { - */} - + }> @@ -60,21 +62,42 @@ function GeographicalCategoriesByIdPage() { {data.usualNameFr} - - - {`${data.nameFr} (${GEOGRAPHICAL_CATEGORIES_LABELS_MAPPER[data.level]})`} - <BadgeGroup className="fr-pt-1w"> - <Badge text="Catégorie géographique" colorFamily="blue-ecume" /> - <CopyBadgeButton - colorFamily="yellow-tournesol" - text={data.id} - lowercase - /> - </BadgeGroup> - - - + + + + {`${data.nameFr} (${GEOGRAPHICAL_CATEGORIES_LABELS_MAPPER[data.level]})`} + <BadgeGroup className="fr-pt-1w"> + <Badge text="Catégorie géographique" colorFamily="blue-ecume" /> + <CopyBadgeButton + colorFamily="yellow-tournesol" + text={data.id} + lowercase + /> + </BadgeGroup> + + + + + {identifiers.length > 0 && ( + + + Identifiants + + + Contenue a modifier asap + + + + )} + {data?.wikidata && ( + <> + Présence sur le web + + + + + )} );