Skip to content

Commit

Permalink
issue/swodlr-ui-106: add stop to save processing time for spatial sea…
Browse files Browse the repository at this point in the history
…rch depending on productsPerPage
  • Loading branch information
jbyrne committed Aug 26, 2024
1 parent 1300525 commit b64e590
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/components/map/WorldMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EditControl } from 'react-leaflet-draw'
import { Session } from '../../authentication/session';
import { lineString } from '@turf/helpers';
import booleanClockwise from '@turf/boolean-clockwise';
import { afterCPSL, afterCPSR, beforeCPS, spatialSearchCollectionConceptId, spatialSearchResultLimit } from '../../constants/rasterParameterConstants';
import { afterCPSL, afterCPSR, beforeCPS, productsPerPage, spatialSearchCollectionConceptId, spatialSearchResultLimit } from '../../constants/rasterParameterConstants';
import { addSpatialSearchResults, setMapFocus, setWaitingForSpatialSearch } from '../sidebar/actions/productSlice';
import { SpatialSearchResult } from '../../types/constantTypes';
import { useLocation, useSearchParams } from 'react-router-dom';
Expand Down Expand Up @@ -120,21 +120,22 @@ const WorldMap = () => {
return polygonString
}).join()

let cursor: string | undefined = 'initialValue'
let cursor: string | null = 'initialValue'
const spatialSearchItems: any[] = []
const productsPerPageInt = parseInt(productsPerPage)
while(cursor !== null) {
if(cursor === 'initialValue') cursor = undefined
if(cursor === 'initialValue') cursor = null
cursor = await fetch('https://graphql.earthdata.nasa.gov/api', {
method: 'POST',
headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ query: getGranules, variables: getSpatialSearchGranuleVariables(polygonUrlString, spatialSearchCollectionConceptId, spatialSearchResultLimit, cursor) })
body: JSON.stringify({ query: getGranules, variables: getSpatialSearchGranuleVariables(polygonUrlString, spatialSearchCollectionConceptId, parseInt(productsPerPage), cursor) })
}).then(async data => {
const responseJson = await data.json()
spatialSearchItems.push(...responseJson.data.granules.items)
return responseJson.data.granules.cursor
return spatialSearchItems.length > productsPerPageInt ? null : responseJson.data.granules.cursor
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/constants/graphqlQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const getGranuleVariables = (cycle: number, pass: number, sceneIds: numbe
return variables
}

export const getSpatialSearchGranuleVariables = (polygon: string, collectionConceptId: string, limit: number, cursor?: string) => {
export const getSpatialSearchGranuleVariables = (polygon: string, collectionConceptId: string, limit: number, cursor: string | null) => {
const variables = {
"params": {
polygon,
Expand Down

0 comments on commit b64e590

Please sign in to comment.