Skip to content

Commit

Permalink
UI state to pass filters to new endpoint in v2
Browse files Browse the repository at this point in the history
  • Loading branch information
micheal-w-wells committed Nov 7, 2023
1 parent 441f4fd commit fce2173
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
28 changes: 17 additions & 11 deletions api/src/paths/v2/iapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ function sanitizeIAPPFilterObject(filterObject: any, req: any) {
body: JSON.stringify(sanitizedSearchCriteria, null, 2)
});


if(filterObject?.CSVType)
{
sanitizedSearchCriteria.isCSV = true;
sanitizedSearchCriteria.CSVType = filterObject.CSVType;
}

return sanitizedSearchCriteria;
}

Expand Down Expand Up @@ -458,37 +465,36 @@ function selectStatement(sqlStatement: SQLStatement, filterObject: any) {
function fromStatement(sqlStatement: SQLStatement, filterObject: any) {
const from = sqlStatement.append(`from sites `);
if (filterObject.isCSV) {
sqlStatement.append(` i `)
switch (filterObject.CSVType) {
case 'site_selection_extract':
sqlStatement.append(SQL` INNER JOIN site_selection_extract pe ON i.site_id = pe.site_id `);
sqlStatement.append(SQL` INNER JOIN site_selection_extract pe ON sites.site_id = pe.site_id `);
break;
case 'survey_extract':
sqlStatement.append(SQL` INNER JOIN survey_extract pe ON i.site_id = pe.site_id`);
sqlStatement.append(SQL` INNER JOIN survey_extract pe ON sites.site_id = pe.site_id`);
break;
case 'chemical_treatment_extract':
sqlStatement.append(SQL` INNER JOIN chemical_treatment_extract pe ON i.site_id = pe.site_id`);
sqlStatement.append(SQL` INNER JOIN chemical_treatment_extract pe ON sites.site_id = pe.site_id`);
break;
case 'mechanical_treatment_extract':
sqlStatement.append(SQL` INNER JOIN mechanical_treatment_extract pe ON i.site_id = pe.site_id`);
sqlStatement.append(SQL` INNER JOIN mechanical_treatment_extract pe ON sites.site_id = pe.site_id`);
break;
case 'chemical_monitoring_extract':
sqlStatement.append(SQL` INNER JOIN chemical_monitoring_extract pe ON i.site_id = pe.site_id`);
sqlStatement.append(SQL` INNER JOIN chemical_monitoring_extract pe ON sites.site_id = pe.site_id`);
break;
case 'mechanical_monitoring_extract':
sqlStatement.append(SQL` INNER JOIN mechanical_monitoring_extract pe ON i.site_id = pe.site_id`);
sqlStatement.append(SQL` INNER JOIN mechanical_monitoring_extract pe ON sites.site_id = pe.site_id`);
break;
case 'biological_treatment_extract':
sqlStatement.append(SQL` INNER JOIN biological_treatment_extract pe ON i.site_id = pe.site_id`);
sqlStatement.append(SQL` INNER JOIN biological_treatment_extract pe ON sites.site_id = pe.site_id`);
break;
case 'biological_monitoring_extract':
sqlStatement.append(SQL` INNER JOIN biological_monitoring_extract pe ON i.site_id = pe.site_id`);
sqlStatement.append(SQL` INNER JOIN biological_monitoring_extract pe ON sites.site_id = pe.site_id`);
break;
case 'biological_dispersal_extract':
sqlStatement.append(SQL` INNER JOIN biological_dispersal_extract pe ON i.site_id = pe.site_id`);
sqlStatement.append(SQL` INNER JOIN biological_dispersal_extract pe ON sites.site_id = pe.site_id`);
break;
default:
sqlStatement.append(SQL` INNER JOIN site_selection_extract pe ON i.site_id = pe.site_id `);
sqlStatement.append(SQL` INNER JOIN site_selection_extract pe ON sites.site_id = pe.site_id `);
break;
}}
return from;
Expand Down
29 changes: 13 additions & 16 deletions appv2/src/state/sagas/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,22 +499,19 @@ function* handle_RECORD_SET_TO_EXCEL_REQUEST(action) {
let networkReturn;
let conditionallyUnnestedURL;
if (set.recordSetType === 'POI') {
let filters = getSearchCriteriaFromFilters(
set?.advancedFilters ? set?.advancedFilters : null,
userSettings?.recordSets ? userSettings?.recordSets : null,
action.payload.id,
true,
set?.gridFilters ? set?.gridFilters : null,
0,
null, // CSV limit
mapState?.layers?.[action.payload.id]?.filters?.sortColumns
? mapState?.layers?.[action.payload.id]?.filters?.sortColumns
: null
);
filters.isCSV = true;
filters.CSVType = action.payload.CSVType;

networkReturn = yield InvasivesAPI_Call('GET', `/api/points-of-interest/`, filters, {});

const currentState = yield select(selectUserSettings);
const mapState = yield select(selectMap);

let filterObject = getRecordFilterObjectFromStateForAPI(action.payload.id, currentState);
//filterObject.page = action.payload.page ? action.payload.page : mapState.recordTables?.[action.payload.recordSetID]?.page;
filterObject.limit = 200000;
filterObject.isCSV = true;
filterObject.CSVType = action.payload.CSVType;

const networkReturn = yield InvasivesAPI_Call('POST', `/api/v2/iapp/`, {
filterObjects: [filterObject]
});

conditionallyUnnestedURL = networkReturn?.data?.result ? networkReturn.data.result : networkReturn?.data;
} else {
Expand Down

0 comments on commit fce2173

Please sign in to comment.