Commit ac233dd6 authored by Fabien Amarger's avatar Fabien Amarger
Browse files

feat: [BienCulturelClass] Filter by the graph source

parent 82fad1c046aa
Pipeline #15220 failed with stages
in 3 minutes and 24 seconds
...@@ -61,6 +61,10 @@ const BienCulturelClass: React.FC<BienCulturelClassProps> = (props) => { ...@@ -61,6 +61,10 @@ const BienCulturelClass: React.FC<BienCulturelClassProps> = (props) => {
function toggleSelectedType(type: string): void { function toggleSelectedType(type: string): void {
selectedType === type ? setSelectedType(null) : setSelectedType(type); selectedType === type ? setSelectedType(null) : setSelectedType(type);
} }
const [selectedGraph, setSelectedGraph] = React.useState<string | null>(null);
function toggleSelectedGraph(graph: string): void {
selectedGraph === graph ? setSelectedGraph(null) : setSelectedGraph(graph);
}
React.useEffect(() => { React.useEffect(() => {
Promise.all( Promise.all(
...@@ -122,15 +126,44 @@ const BienCulturelClass: React.FC<BienCulturelClassProps> = (props) => { ...@@ -122,15 +126,44 @@ const BienCulturelClass: React.FC<BienCulturelClassProps> = (props) => {
center = L.latLngBounds(bienCulturelLocations.map(({ location }) => [location.lat, location.lng])).getCenter(); center = L.latLngBounds(bienCulturelLocations.map(({ location }) => [location.lat, location.lng])).getCenter();
} }
const allGraphSource: string[] = [];
if (bienCulturelInstances !== null) {
for (const instance of bienCulturelInstances) {
if (instance.graph !== undefined && !allGraphSource.includes(instance.graph)) {
allGraphSource.push(instance.graph);
}
}
}
return ( return (
<> <>
<h1>{label}</h1> <h1>{label}</h1>
{types !== null ? ( {types !== null ? (
types.map((type) => ( <div>
<span onClick={() => toggleSelectedType(type)} style={{ cursor: 'pointer' }}> <h3>Filtrer par type alternatif : </h3>
<URIBadge key={type} uri={type} dataFetcher={dataFetcher} selected={selectedType === type} /> {types.map((type) => (
</span> <span onClick={() => toggleSelectedType(type)} style={{ cursor: 'pointer' }}>
)) <URIBadge
key={type}
uri={type}
dataFetcher={dataFetcher}
selected={selectedType === type}
/>
</span>
))}
</div>
) : (
<></>
)}
{allGraphSource.length > 0 ? (
<div>
<h3>Filtrer par source : </h3>
{allGraphSource.map((currentGraph) => (
<span onClick={() => toggleSelectedGraph(currentGraph)} style={{ cursor: 'pointer' }}>
<URIBadge key={currentGraph} uri={currentGraph} selected={selectedGraph === currentGraph} />
</span>
))}
</div>
) : ( ) : (
<></> <></>
)} )}
...@@ -144,6 +177,7 @@ const BienCulturelClass: React.FC<BienCulturelClassProps> = (props) => { ...@@ -144,6 +177,7 @@ const BienCulturelClass: React.FC<BienCulturelClassProps> = (props) => {
.filter( .filter(
({ bienCulturel }) => selectedType === null || bienCulturel.typeUris.includes(selectedType) ({ bienCulturel }) => selectedType === null || bienCulturel.typeUris.includes(selectedType)
) )
.filter(({ bienCulturel }) => selectedGraph === null || bienCulturel.graph === selectedGraph)
.map((bienCulturelLocation) => ( .map((bienCulturelLocation) => (
<Marker <Marker
key={bienCulturelLocation.bienCulturel.locationUri} key={bienCulturelLocation.bienCulturel.locationUri}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment