Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(admin): filter collection on intersections [EP-3653] #407

Merged
merged 2 commits into from
Jan 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions packages/earth-admin/src/pages-client/places/details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
specific language governing permissions and limitations under the License.
*/

import { groupBy, map, noop } from 'lodash';
import { filter, groupBy, isEmpty, map, noop } from 'lodash';
import { merge } from 'lodash/fp';
import React, { useEffect, useState } from 'react';
import { useForm } from 'react-hook-form';
Expand Down Expand Up @@ -55,7 +55,7 @@ import PlacesService from '@app/services/places';
import { formatArrayToParentheses, formatDate, km2toHa } from '@app/utils';
import { MapComponentContext } from '@app/utils/contexts';

import { IPlace, PLACE_DETAIL_QUERY, PlaceIntersection } from './model';
import { IPlace, LOCATION_TYPE, PLACE_DETAIL_QUERY, PlaceIntersection } from './model';

interface IProps {
path: string;
Expand Down Expand Up @@ -86,7 +86,7 @@ export function PlaceDetail(props: IProps) {

const [place, setPlace] = useState<IPlace>({});
const [mapData, setMapData] = useState({});
const [mappedIntersections, setMappedIntersections] = useState();
const [mappedIntersections, setMappedIntersections] = useState({} as any);
const [geojsonValue, setGeojson] = useState(null);
const [jsonError, setJsonError] = useState(false);
const [serverErrors, setServerErrors] = useState();
Expand Down Expand Up @@ -132,8 +132,14 @@ export function PlaceDetail(props: IProps) {
const renderErrorFor = setupErrors(errors, touched);

useEffect(() => {
place && setMapData({ geojson, bbox: bbox2d });
place && setMappedIntersections(groupBy(intersections, 'type'));
if (place) {
setMapData({ geojson, bbox: bbox2d });

const groupedIntersections = groupBy(intersections, 'type');
const excludeCollection = (item, type) => type !== LOCATION_TYPE.COLLECTION;

setMappedIntersections(filter(groupedIntersections, excludeCollection));
}
}, [place]);

useEffect(() => {
Expand Down Expand Up @@ -486,7 +492,7 @@ export function PlaceDetail(props: IProps) {
</Card>
)}
</div>
{!!intersections && (
{!isEmpty(mappedIntersections) && (
<div className="ng-margin-medium-bottom">
<Card>
<div className="">
Expand Down