Skip to content

Commit

Permalink
positive spatial filter from kml upload working e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
micheal-w-wells committed Sep 21, 2023
1 parent 67a3a3f commit 4d2c759
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 39 deletions.
28 changes: 20 additions & 8 deletions api/src/paths/v2/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,15 @@ function sanitizeActivityFilterObject(filterObject: any, req: any) {
sanitizedTableFilters.push(filter);
break;
}
break;
case 'spatialFilterDrawn':
if (filter.filter) {
clientFilterGeometries.push(filter.filter);
clientFilterGeometries.push(filter.filter?.geometry);
}
break;
case 'spatialFilterUploaded':
if (!isNaN(filter?.filter?.geometry)) {
serverFilterGeometries.push(filter.filter.geometry);
if (!isNaN(parseInt(filter?.filter))) {
serverFilterGeometries.push(parseInt(filter.filter));
}
break;
default:
Expand All @@ -197,11 +198,13 @@ function sanitizeActivityFilterObject(filterObject: any, req: any) {
});
}

sanitizedSearchCriteria.serverFilterGeometries = serverFilterGeometries;
sanitizedSearchCriteria.clientFilterGeometries = clientFilterGeometries;
sanitizedSearchCriteria.clientReqTableFilters = sanitizedTableFilters;
defaultLog.debug({
label: 'getActivitiesBySearchFilterCriteria',
message: 'sanitizedObject',
body: sanitizedSearchCriteria
body: JSON.stringify(sanitizedSearchCriteria, null, 2)
});

return sanitizedSearchCriteria;
Expand Down Expand Up @@ -259,6 +262,9 @@ function getActivitiesBySearchFilterCriteria(): RequestHandler {
}

function getActivitiesSQLv2(filterObject: any) {
try
{

let sqlStatement: SQLStatement = SQL``;
sqlStatement = initialWithStatement(sqlStatement);
sqlStatement = additionalCTEStatements(sqlStatement, filterObject);
Expand All @@ -272,6 +278,12 @@ function getActivitiesSQLv2(filterObject: any) {

defaultLog.debug({ label: 'getActivitiesBySearchFilterCriteria', message: 'sql', body: sqlStatement });
return sqlStatement;
}

catch(e) {
defaultLog.debug({ label: 'getActivitiesBySearchFilterCriteria', message: 'error', body: e.message });
throw e
}
}

function initialWithStatement(sqlStatement: SQLStatement) {
Expand Down Expand Up @@ -308,7 +320,7 @@ CurrentNegativeObservations AS (
serverFilterGeometryIDs as (
select unnest(array[79,80]) as id
select unnest(array[${filterObject?.serverFilterGeometries.join(',')}]) as id
),
serverFilterGeometries AS (
Expand Down Expand Up @@ -342,7 +354,7 @@ CurrentNegativeObservations AS (
clientFilterGeometries AS (
SELECT
unnest(array[${filterObject.clientFilterGeometries
.map((geometry) => `st_setsrid(st_geomfromgeojson(${geometry.geometry}, 4326)`)
.map((geometry) => `st_setsrid(st_geomfromgeojson(${geometry?.geometry}, 4326)`)
.join(',')}]) AS geojson
),
Expand Down Expand Up @@ -372,7 +384,7 @@ activities as (
case when CurrentNegativeObservations.current_negative_species is null then false else true end as has_current_negative
`);

if (filterObject?.serverFilterGeometries?.length > 0) {
/*if (filterObject?.serverFilterGeometries?.length > 0) {
sqlStatement.append(`
,case when ServerBoundariesToIntersect.geog is null then false else true end as intersects_server_boundary
`);
Expand All @@ -381,7 +393,7 @@ activities as (
sqlStatement.append(`
,case when ClientBoundariesToIntersect.geog is null then false else true end as intersects_client_boundary
`);
}
}*/

sqlStatement.append(`
from not_deleted_activities a
Expand Down
21 changes: 10 additions & 11 deletions appv2/src/UI/Overlay/Records/RecordSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ const RecordSetFooter = (props) => {

const Filter = (props) => {
const userSettingsState = useSelector((state: any) => state.UserSettings);
const serverBoundariesToDisplay = useSelector((state: any) => state.Map.serverBoundaries).map((boundary) => {
return { label: boundary.name, value: boundary.id };
const serverBoundariesToDisplay = useSelector((state: any) => state.Map.serverBoundaries)?.map((boundary) => {
return { label: boundary.title, value: boundary.id };
});
console.dir(userSettingsState);

Expand Down Expand Up @@ -269,7 +269,6 @@ const Filter = (props) => {
dispatch({
type: RECORDSET_UPDATE_FILTER,
payload: {
filterType: 'tableFilter',
setID: props.setID,
filterID: props.id,
filter: e.target.value
Expand Down Expand Up @@ -333,7 +332,7 @@ const Filter = (props) => {
dispatch({
type: RECORDSET_UPDATE_FILTER,
payload: {
filterType: 'tableFilter',
//filterType: 'tableFilter',
setID: props.setID,
filterID: props.id,
operator: e.target.value
Expand All @@ -354,21 +353,21 @@ const Filter = (props) => {
),
spatialFilterDrawn: (
<>
<option key={Math.random()} value={'CONAINED IN'} label={'CONAINED IN'}>
CONAINED IN
<option key={Math.random()} value={'CONTAINED IN'} label={'CONTAINED IN'}>
CONTAINED IN
</option>
<option key={Math.random()} value={'DOES NOT CONTAIN'} label={'DOES NOT CONTAIN'}>
DOES NOT CONTAIN
<option key={Math.random()} value={'NOT CONTAINED IN'} label={'NOT CONTAINED IN'}>
NOT CONTAINED IN
</option>
</>
),
spatialFilterUploaded: (
<>
<option key={Math.random()} value={'CONAINED IN'} label={'CONAINED IN'}>
<option key={Math.random()} value={'CONTAINED IN'} label={'CONTAINED IN'}>
CONAINED IN
</option>
<option key={Math.random()} value={'NOT CONAINED IN'} label={'NOT CONAINED IN'}>
NOT CONAINED IN
<option key={Math.random()} value={'NOT CONTAINED IN'} label={'NOT CONTAINED IN'}>
NOT CONTAINED IN
</option>
</>
)
Expand Down
35 changes: 17 additions & 18 deletions appv2/src/state/reducers/userSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function createUserSettingsReducer(configuration: AppConfig): (UserSettingsState
id: getUuid(),
field: action.payload.field,
filterType: action.payload.filterType,
operator: action.payload.operator,
operator: action.payload.operator ? action.payload.operator : 'CONTAINS',
filter: action.payload.filter ? action.payload.filter : ''
});
break;
Expand Down Expand Up @@ -180,25 +180,24 @@ function createUserSettingsReducer(configuration: AppConfig): (UserSettingsState
(filter) => filter.id !== action.payload.filterID
);

if (action.payload.filterType) {
const index = draftState.recordSets[action.payload.setID]?.tableFilters.findIndex(
(filter) => filter.id === action.payload.filterID
);
if (index !== -1)
const index = draftState.recordSets[action.payload.setID]?.tableFilters.findIndex(
(filter) => filter.id === action.payload.filterID
);
if (index !== -1)
if (action.payload.filterType) {
draftState.recordSets[action.payload.setID].tableFilters[index].filterType = action.payload.filterType;
}

if (
action.payload.filterType === 'spatialFilterDrawn' ||
action.payload.filterType === 'spatialFilterUploaded'
) {
delete draftState.recordSets[action.payload.setID].tableFilters[index].field;
if (!action.payload.operator) {
draftState.recordSets[action.payload.setID].tableFilters[index].operator = 'CONTAINED IN';
}
delete draftState.recordSets[action.payload.setID].tableFilters[index].field;
if (!action.payload.filter) {
delete draftState.recordSets[action.payload.setID].tableFilters[index].filter;
}
if (
action.payload.filterType === 'spatialFilterDrawn' ||
action.payload.filterType === 'spatialFilterUploaded'
) {
delete draftState.recordSets[action.payload.setID].tableFilters[index].field;
if (!action.payload.operator) {
draftState.recordSets[action.payload.setID].tableFilters[index].operator = 'CONTAINED IN';
}
if (!action.payload.filter) {
delete draftState.recordSets[action.payload.setID].tableFilters[index].filter;
}
}

Expand Down
2 changes: 0 additions & 2 deletions appv2/src/state/sagas/userSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ function* handle_USER_SETTINGS_GET_INITIAL_STATE_REQUEST(action) {
const recordsExpandedState = JSON.parse(localStorage.getItem('records-expanded'));

const recordSets = oldAppState?.recordSets ? oldAppState.recordSets : defaultRecordSet;
const recordsExpanded = recordsExpandedState ? recordsExpandedState : false;

yield put({ type: GET_API_DOC_REQUEST });
yield take(GET_API_DOC_SUCCESS);
Expand All @@ -311,7 +310,6 @@ function* handle_USER_SETTINGS_GET_INITIAL_STATE_REQUEST(action) {
activeActivityDescription: oldDesc,
activeIAPP: IAPPID,
recordSets: recordSets,
recordsExpanded: recordsExpanded
}
});
} catch (e) {
Expand Down

0 comments on commit 4d2c759

Please sign in to comment.