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

Popup states the correct Masking value #269

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions api/src/paths/public/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe('search', () => {
number_sites: 1,
size_ha: 100,
state_code: 1,
maskedLocation: false,
geometry: '{"type":"Point","coordinates":[50.7,60.9]}'
}
];
Expand Down Expand Up @@ -109,6 +110,7 @@ describe('search', () => {
number_sites: searchList[0].number_sites,
size_ha: searchList[0].size_ha,
state_code: searchList[0].state_code,
maskedLocation: searchList[0].maskedLocation,
geometry: [
{
type: 'Point',
Expand Down
3 changes: 2 additions & 1 deletion api/src/paths/public/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export function getSearchResults(): RequestHandler {
p.state_code,
psc.number_sites,
psc.size_ha,
public.ST_asGeoJSON(psc.geography) as geometry
public.ST_asGeoJSON(psc.geography) as geometry,
psc.geojson#>>'{}' as geojson
FROM
project p
LEFT JOIN
Expand Down
2 changes: 2 additions & 0 deletions api/src/paths/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ describe('search', () => {
number_sites: 1,
size_ha: 100,
state_code: 1,
maskedLocation: false,
geometry: '{"type":"Point","coordinates":[50.7,60.9]}'
}
];
Expand All @@ -133,6 +134,7 @@ describe('search', () => {
number_sites: searchList[0].number_sites,
size_ha: searchList[0].size_ha,
state_code: searchList[0].state_code,
maskedLocation: searchList[0].maskedLocation,
geometry: [
{
type: 'Point',
Expand Down
25 changes: 23 additions & 2 deletions api/src/paths/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,35 @@ const _maskGateKeeper = (originalFeatureArray: string, originalGeoJSON: string)
units: 'meters',
properties: feature.properties
});
featureArray.coordinates[index] = mask.geometry.coordinates;
featureArray.coordinates[index] = mask.geometry.coordinates[0];
}
});
} catch (error) {
console.log('error', error);
throw error;
}

return featureArray;
};

/**
* Check if there are any masked locations in the geojson.
* @param geojsonString
* @returns {boolean}
*/
const _findMaskedLocations = (geojsonString: string) => {
let maskedLocations = false;
try {
const geojson = JSON.parse(geojsonString);
if (geojson && geojson.some((feature: any) => feature.properties.maskedLocation)) {
maskedLocations = true;
}
} catch (error) {
console.log('error', error);
throw error;
}
return maskedLocations;
};
/**
* Extract an array of search result data from DB query.
*
Expand All @@ -167,6 +186,7 @@ export function _extractResults(rows: any[]): any[] {
rows.forEach((row) => {
// Protected shapes must have their geometry masked here
const features = _maskGateKeeper(row.geometry, row.geojson);
const maskedLocations = _findMaskedLocations(row.geojson || '{[]}');

const result: any = {
id: row.id,
Expand All @@ -175,7 +195,8 @@ export function _extractResults(rows: any[]): any[] {
state_code: row.state_code,
number_sites: row.number_sites,
size_ha: row.size_ha,
geometry: [features]
geometry: [features],
maskedLocation: maskedLocations
};

searchResults.push(result);
Expand Down
7 changes: 6 additions & 1 deletion app/src/components/map/MapContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ const convertToCentroidGeoJSON = (features: any) => {
is_project: f.is_project,
state_code: f.state_code,
number_sites: f.number_sites,
size_ha: f.size_ha
size_ha: f.size_ha,
maskedLocation: f.maskedLocation
}
};
})
Expand Down Expand Up @@ -1057,6 +1058,7 @@ const initializeMap = (
const numberSites = prop.number_sites;
const sizeHa = prop.size_ha;
const stateCode = prop.state_code;
const maskedLocation = prop.maskedLocation;

let thumbnail = '';
try {
Expand All @@ -1083,6 +1085,7 @@ const initializeMap = (
number_sites={numberSites}
size_ha={sizeHa}
state_code={stateCode}
maskedLocation={maskedLocation}
thumbnail={thumbnail}
maskDisclaimer={true}
/>
Expand Down Expand Up @@ -1110,6 +1113,7 @@ const initializeMap = (
const numberSites = prop.number_sites;
const sizeHa = prop.size_ha;
const stateCode = prop.state_code;
const maskedLocation = prop.maskedLocation;

let thumbnail = '';
try {
Expand All @@ -1133,6 +1137,7 @@ const initializeMap = (
state_code={stateCode}
thumbnail={thumbnail}
maskDisclaimer={true}
maskedLocation={maskedLocation}
/>
);

Expand Down
5 changes: 0 additions & 5 deletions app/src/components/map/components/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ const MapPopup = (props: any) => {
{maskedLocation && (
<div style={style.attention}>Location sensitive site - see FOIPPA 16, 17, 18 & 18.1.</div>
)}
{maskDisclaimer && (
<div style={style.attention}>
Point location is approximate and does not represent the exact location of the site.
</div>
)}
{!hideButton && (
<div>
<a href={`/${isProject ? 'projects' : 'plans'}/${id}`}>
Expand Down
14 changes: 3 additions & 11 deletions app/src/features/search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { SYSTEM_ROLE } from 'constants/roles';
const SearchPage: React.FC = () => {
const restorationApi = useNertApi();

const [performSearch, setPerformSearch] = useState<boolean>(true);
const [geometries, setGeometries] = useState<Feature[]>([]);

const authStateContext = useAuthStateContext();
Expand Down Expand Up @@ -63,11 +62,6 @@ const SearchPage: React.FC = () => {
? await restorationApi.search.getSearchResults()
: await restorationApi.public.search.getSearchResults();

if (!response) {
setPerformSearch(false);
return;
}

const clusteredPointGeometries: any = [];

response.forEach((result: IGetSearchResultsResponse) => {
Expand All @@ -87,7 +81,6 @@ const SearchPage: React.FC = () => {
}
});

setPerformSearch(false);
setGeometries(clusteredPointGeometries);
} catch (error) {
const apiError = error as APIError;
Expand All @@ -99,11 +92,10 @@ const SearchPage: React.FC = () => {
}
}, [restorationApi.search, restorationApi.public.search, authStateContext.auth]);

// This was the source of the infinite loop.
useEffect(() => {
if (performSearch) {
getSearchResults();
}
}, [performSearch, getSearchResults]);
getSearchResults();
}, []);

const [sidebarOpen, setSidebarOpen] = useState(true);

Expand Down
Loading