Skip to content

Commit

Permalink
fix: card persona and search Medici
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed Nov 18, 2024
1 parent 499d436 commit 3b60b11
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 38 deletions.
77 changes: 57 additions & 20 deletions src/components/Blocks/SearchMap/Body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Chip,
ChipLabel,
} from 'design-react-kit';
import { omit } from 'lodash';
import { OSMMap } from 'volto-venue';
import { getQueryStringResults } from '@plone/volto/actions';
import { flattenToAppURL } from '@plone/volto/helpers';
Expand Down Expand Up @@ -87,22 +88,28 @@ const LeafIcon = (options, item) => {
};

const resultsReducer = (items) => {
const geolocated_items = [...items]
.map((item) => {
let i = { ...item };
//per i medici (ct 'Persona')
if (!hasGeolocation(item) && item.struttura_ricevimento?.length > 0) {
const struttura = item.struttura_ricevimento[0];
if (hasGeolocation(struttura)) {
//copia il campo geolocation della struttura dentro all'item, per poterlo mostrare come punto sulla mappa
i.geolocation = struttura.geolocation;
}
}
return i;
})
.filter((item) => hasGeolocation(item));

return geolocated_items;
//questo filtro è inutile, perchè questi conti li fa già il parametro 'has_geolocation' che si passa nella query
//let geolocated_items = [];
// items.forEach((item) => {
// //se l'oggetto è una Persona con stutture collegate con geolocation, o ha una sua geolocation, la aggiungo, altrimenti no.
// if (item['@type'] === 'Persona') {
// const strutture = [
// ...(item.struttura_ricevimento ?? []),
// ...(item.struttura_in_cui_opera ?? []),
// ].filter((s) => hasGeolocation(s));

// if (hasGeolocation(item) || strutture.length > 0) {
// geolocated_items.push(item);
// }
// } else {
// if (hasGeolocation(item)) {
// geolocated_items.push(item);
// }
// }
// });
//return geolocated_items;

return items;
};

/*
Expand Down Expand Up @@ -195,6 +202,7 @@ const SearchMapBody = ({ data, id, path, properties, block, inEditMode }) => {
metadata_fields: [
'tipologia_struttura',
'struttura_ricevimento',
'struttura_in_cui_opera',
'incarico_metadata',
], //'_all',
query: query,
Expand All @@ -208,10 +216,15 @@ const SearchMapBody = ({ data, id, path, properties, block, inEditMode }) => {
);
};

const calculateMarkers = () => {
let points = items.map((item) => {
let point = {
...item,
const getPoint = (item, title) => {
let point = { ...item };
if (title) {
point.title = title;
}

if (hasGeolocation(item)) {
point = {
...point,
...(item.geolocation
? item.geolocation
: { latitude: item.latitude, longitude: item.longitude }),
Expand All @@ -230,6 +243,30 @@ const SearchMapBody = ({ data, id, path, properties, block, inEditMode }) => {
),
popupContent: mapPinDirections(point, intl),
};
}
return null;
};

const calculateMarkers = () => {
let points = [];
items.forEach((item) => {
const point = getPoint(item);
if (point) {
points.push(point);
}

if (item['@type'] === 'Persona') {
const strutture = [
...(item.struttura_ricevimento ?? []),
...(item.struttura_in_cui_opera ?? []),
].filter((s) => hasGeolocation(s));
strutture.forEach((s) => {
const point_s = getPoint(s, item.title);
if (point_s) {
points.push(point_s);
}
});
}
});
setMarkers(points);
};
Expand Down
34 changes: 16 additions & 18 deletions src/components/Cards/CardPersona/CardPersona.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export const CardPersona = ({
? incarico_field[incarico_field.length - 1]
: null;

const strutture = [
...(item.struttura_ricevimento ?? []),
...(item.struttura_in_cui_opera ?? []),
];

return (
<Card className={cx('shadow rounded card-persona no-after', className)}>
<CardBody className="d-flex">
Expand All @@ -85,33 +90,26 @@ export const CardPersona = ({
)}
{size !== 'small' && (
<>
{item.struttura_ricevimento?.length > 0 ? (
{hasGeolocation(item) && (
<div className="mb-2 mt-2">
<Address item={item} showDistance={showDistance} />
</div>
)}

{strutture.map((s) => (
<div className="mb-2 mt-2">
<div>
<UniversalLink
item={
!isEditMode ? item.struttura_ricevimento[0] : null
}
item={!isEditMode ? s : null}
href={isEditMode ? '#' : ''}
className="fw-bold"
>
{item.struttura_ricevimento[0].title}
{s.title}
</UniversalLink>
</div>
<Address
item={item.struttura_ricevimento[0]}
showDistance={showDistance}
/>
<Address item={s} showDistance={showDistance} />
</div>
) : (
<>
{hasGeolocation(item) && (
<div className="mb-2 mt-2">
<Address item={item} showDistance={showDistance} />
</div>
)}
</>
)}
))}
</>
)}
</CardText>
Expand Down

0 comments on commit 3b60b11

Please sign in to comment.