Skip to content

Commit

Permalink
nih
Browse files Browse the repository at this point in the history
  • Loading branch information
trevlenb2 committed Dec 2, 2023
1 parent d280f1e commit 9856b0a
Show file tree
Hide file tree
Showing 6 changed files with 405 additions and 108 deletions.
160 changes: 98 additions & 62 deletions src/features/planSimulation/components/Simulation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,9 @@ const Simulation = () => {
identifier: mapData?.identifier,
method: mapData?.method
};
if (mapData.source) {
newVar.source = mapData.source;
}
} else {
newVar = {
features: {},
Expand All @@ -681,6 +684,9 @@ const Simulation = () => {
useEffect(() => {
if (mapDataLoad) {
setMapData(mapData => {
if (mapData) {
mapData.source = mapDataLoad.source;
}
let newMapData: PlanningLocationResponseTagged = initializeNewMapData(mapData);

if (mapDataLoad.features) {
Expand Down Expand Up @@ -1042,9 +1048,11 @@ const Simulation = () => {
return val;
});

lowestLocations.forEach(lowestLocation => {
getLocationHierarchyFromLowestLocation(lowestLocation, mapData);
});
if (!mapData.source || mapData.source !== 'uploadHandler') {
lowestLocations.forEach(lowestLocation => {
getLocationHierarchyFromLowestLocation(lowestLocation, mapData);
});
}
}

let min = Number.MAX_VALUE;
Expand Down Expand Up @@ -1230,69 +1238,97 @@ const Simulation = () => {
</Col>
</Row>
</Form.Group>
<Form.Group className="my-3">
<Row className="align-items-center">
<Col md={5} lg={5}>
<OverlayTrigger
placement="top"
overlay={<Tooltip id="meta-tooltip">{t('simulationPage.selectParentToSearchWithin')}</Tooltip>}
>
<Form.Label>{t('simulationPage.geographicLevel')}:</Form.Label>
</OverlayTrigger>
</Col>
<Container
as={'div'}
color={'grey'}
style={{ border: '1px', borderColor: 'grey' }}
className="rounded-1 border"
>
<Row>
<Col>
<Form.Select
onChange={e => {
if (e.target.value && selectedHierarchy && selectedHierarchy.type) {
getLocationList(selectedHierarchy.identifier, selectedHierarchy.type, e.target.value).then(
res => {
setLocationList(res);
<div className=" my-3 ">
Filter locations by a Parent Location{' '}
<span style={{ color: 'lightgray' }} className={'small'}>
(Search results will be locations within this parent location)
</span>
</div>
<Form.Group className="my-3">
<Row className="align-items-center">
<Col md={5} lg={5}>
<OverlayTrigger
placement="top"
overlay={
<Tooltip id="meta-tooltip">{t('simulationPage.selectParentToSearchWithin')}</Tooltip>
}
);
} else {
setLocationList([]);
}
setSelectedLocation(null);
}}
>
<option value={''}>{t('simulationPage.selectGeographicLevel')}...</option>
{nodeList.map(el => (
<option key={el} value={el}>
{el}
</option>
))}
</Form.Select>
</Col>
</Row>
</Form.Group>
<Form.Group className="my-3">
<Row className="align-items-center">
<Col md={5} lg={5}>
<OverlayTrigger
placement="top"
overlay={
<Tooltip id="meta-tooltip">{t('simulationPage.selectParentLocationToSearchWithin')}</Tooltip>
}
>
<Form.Label>{t('simulationPage.location')}:</Form.Label>
</OverlayTrigger>
</Col>
<Col>
<Select
placeholder="Select Location..."
className="custom-react-select-container "
classNamePrefix="custom-react-select"
id="team-assign-select"
isClearable
value={selectedLocation}
options={locationList.reduce((prev, current) => {
return [...prev, { label: current.name, value: current.identifier }];
}, [])}
onChange={newValue => setSelectedLocation(newValue)}
/>
>
<Form.Label>{t('simulationPage.geographicLevel')}:</Form.Label>
</OverlayTrigger>
</Col>
<Col>
<Form.Select
onChange={e => {
if (e.target.value && selectedHierarchy && selectedHierarchy.type) {
getLocationList(
selectedHierarchy.identifier,
selectedHierarchy.type,
e.target.value
).then(res => {
setLocationList(res);
});
} else {
setLocationList([]);
}
setSelectedLocation(null);
}}
>
<option value={''}>
{selectedHierarchy
? t('simulationPage.selectGeographicLevel')
: t('simulationPage.selectHierarchy')}
...
</option>
{nodeList.map(el => (
<option key={el} value={el}>
{el}
</option>
))}
</Form.Select>
</Col>
</Row>
</Form.Group>
<Form.Group className="my-3">
<Row className="align-items-center">
<Col md={5} lg={5}>
<OverlayTrigger
placement="top"
overlay={
<Tooltip id="meta-tooltip">
{t('simulationPage.selectParentLocationToSearchWithin')}
</Tooltip>
}
>
<Form.Label>{t('simulationPage.location')}:</Form.Label>
</OverlayTrigger>
</Col>
<Col>
<Select
placeholder="Select Location..."
className="custom-react-select-container "
classNamePrefix="custom-react-select"
id="team-assign-select"
isClearable
value={selectedLocation}
options={locationList.reduce((prev, current) => {
return [...prev, { label: current.name, value: current.identifier }];
}, [])}
onChange={newValue => setSelectedLocation(newValue)}
/>
</Col>
</Row>
</Form.Group>
</Col>
</Row>
</Form.Group>
</Container>
<Form.Group className="my-3">
<Row className="align-items-center">
<Col md={5} lg={5}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,9 @@ const SimulationMapView = ({
useEffect(() => {
if (chunkedData) {
if (
chunkedData?.features.length > 0 &&
chunkedData?.features?.length > 0 &&
(!chunkedData?.parents ||
chunkedData?.parents.length === 0 ||
chunkedData?.parents?.length === 0 ||
(chunkedData.source && chunkedData.source === 'uploadHandler'))
) {
let layerList: Set<string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,32 @@ const DownloadSimulationResultsModal = ({ inputData, closeHandler, hierarchyIden
): Promise<string> => {
let features = Object.keys(mapDataCurrent.features).map(key => mapDataCurrent.features[key]);

let parents = Object.keys(mapDataCurrent.parents).map(key => mapDataCurrent.parents[key]);

parents.forEach(parentFeature => {
if (parentFeature && parentFeature.identifier) {
if (
!mapDataCurrent.features[parentFeature.identifier] ||
mapDataCurrent.features[parentFeature.identifier] == null
) {
if (parentFeature.properties) {
parentFeature.properties['isParent'] = true;
}
}
}
});

if (!includeParentData) {
parents = parents.filter(parentFeature => !parentFeature.properties?.isParent);
}
// let parents = Object.keys(mapDataCurrent.parents).map(key => mapDataCurrent.parents[key]);
//
// parents.forEach(parentFeature => {
// if (parentFeature && parentFeature.identifier) {
// if (
// !mapDataCurrent.features[parentFeature.identifier] ||
// mapDataCurrent.features[parentFeature.identifier] == null
// ) {
// if (parentFeature.properties) {
// parentFeature.properties['isParent'] = true;
// }
// }
// }
// });
//
// if (!includeParentData) {
// parents = parents.filter(parentFeature => !parentFeature.properties?.isParent);
// }

if (fileTypeSelector === 'FeatureCollection') {
let featureCollection: {
type: 'FeatureCollection';
identifier: string;
features: Feature<Point | Polygon | MultiPolygon, Properties>[];
} = {
features: parents,
features: features,
type: 'FeatureCollection',
identifier: 'simulation-data'
};
Expand Down Expand Up @@ -374,8 +374,8 @@ const DownloadSimulationResultsModal = ({ inputData, closeHandler, hierarchyIden
<Form.Label className="text-danger">{errors.filenameJSON.message}</Form.Label>
)}
</Form.Group>
{getIncludeParentSlider()}
{getFullHierarchySlider()}
{/*{getIncludeParentSlider()}*/}
{/*{getFullHierarchySlider()}*/}
<Form.Group className="my-3">
<Form.Label>GeoJson file type</Form.Label>
<Form.Select {...register('fileTypeSelector')} defaultValue={'FeatureCollection'}>
Expand Down
Loading

0 comments on commit 9856b0a

Please sign in to comment.