1
1
import { Alert , Col , OverlayTrigger , Row , Table , Tooltip , Spinner , Form , DropdownButton , Dropdown , Badge } from "react-bootstrap" ;
2
2
import { useAppDispatch , useAppSelector } from "../../redux/hooks" ;
3
- import { Product , ProductState } from "../../types/graphqlTypes" ;
3
+ import { Product } from "../../types/graphqlTypes" ;
4
4
import { useEffect , useState } from "react" ;
5
5
import { InfoCircle } from "react-bootstrap-icons" ;
6
6
import { generatedProductsLabels , infoIconsToRender , parameterHelp , productsPerPage } from "../../constants/rasterParameterConstants" ;
7
7
import { getUserProducts } from "../../user/userData" ;
8
8
import { useLocation , useNavigate } from "react-router-dom" ;
9
9
import DataPagination from "./DataPagination" ;
10
- import HistoryFilters from "./HistoryFilters" ;
11
- import { Adjust , FilterParameters , OutputGranuleExtentFlagOptions , OutputSamplingGridType , RasterResolution } from "../../types/historyPageTypes" ;
10
+ import HistoryFilters , { getFilterParameters , productPassesFilterCheck } from "./HistoryFilters" ;
12
11
import { setShowReGenerateProductModalTrue } from "../sidebar/actions/modalSlice" ;
13
12
import ReGenerateProductsModal from "./ReGenerateProductsModal" ;
14
- import { setAllUserProducts , setGranulesToReGenerate , setUserProducts , setWaitingForMyDataFiltering , setWaitingForProductsToLoad } from "../sidebar/actions/productSlice" ;
15
-
16
- export const productPassesFilterCheck = ( currentFilters : FilterParameters , cycle : number , pass : number , scene : number , outputGranuleExtentFlag : boolean , status : string , outputSamplingGridType : string , rasterResolution : number , dateGenerated : string , utmZoneAdjust ?: number , mgrsBandAdjust ?: number ) : boolean => {
17
- let productPassesFilter = true
18
- const outputGranuleExtentFlagMap = [ '128 x 128' , '256 x 128' ]
19
-
20
- if ( currentFilters . cycle !== 'none' && currentFilters . cycle !== String ( cycle ) ) {
21
- productPassesFilter = false
22
- }
23
- if ( currentFilters . pass !== 'none' && currentFilters . pass !== String ( pass ) ) {
24
- productPassesFilter = false
25
- }
26
- if ( currentFilters . scene !== 'none' && currentFilters . scene !== String ( scene ) ) {
27
- productPassesFilter = false
28
- }
29
- if ( currentFilters . outputGranuleExtentFlag . length > 0 && ! currentFilters . outputGranuleExtentFlag . includes ( outputGranuleExtentFlagMap [ + outputGranuleExtentFlag ] as OutputGranuleExtentFlagOptions ) ) {
30
- productPassesFilter = false
31
- }
32
- if ( currentFilters . status . length > 0 && ! currentFilters . status . includes ( status as ProductState ) ) {
33
- productPassesFilter = false
34
- }
35
- if ( currentFilters . outputSamplingGridType . length > 0 && ! currentFilters . outputSamplingGridType . includes ( outputSamplingGridType as OutputSamplingGridType ) ) {
36
- productPassesFilter = false
37
- }
38
- if ( currentFilters . rasterResolution . length > 0 && ! currentFilters . rasterResolution . includes ( String ( rasterResolution ) as RasterResolution ) ) {
39
- productPassesFilter = false
40
- }
41
- if ( utmZoneAdjust !== undefined && currentFilters . utmZoneAdjust . length > 0 && ! currentFilters . utmZoneAdjust . includes ( String ( utmZoneAdjust ) as Adjust ) ) {
42
- productPassesFilter = false
43
- }
44
- if ( mgrsBandAdjust !== undefined && currentFilters . mgrsBandAdjust . length > 0 && ! currentFilters . mgrsBandAdjust . includes ( String ( mgrsBandAdjust ) as Adjust ) ) {
45
- productPassesFilter = false
46
- }
47
- if ( currentFilters . startDate !== 'none' && new Date ( dateGenerated ) < currentFilters . startDate ) {
48
- productPassesFilter = false
49
- }
50
- if ( currentFilters . endDate !== 'none' && new Date ( dateGenerated ) > currentFilters . endDate ) {
51
- productPassesFilter = false
52
- }
53
- return productPassesFilter
54
- }
13
+ import { setAllUserProducts , setGranulesToReGenerate , setUserProducts , setWaitingForMyDataFiltering , setWaitingForMyDataFilteringReset , setWaitingForProductsToLoad } from "../sidebar/actions/productSlice" ;
14
+ import { defaultUserProductsLimit } from "../../constants/graphqlQueries" ;
55
15
56
16
const GeneratedProductHistory = ( ) => {
57
17
const dispatch = useAppDispatch ( )
@@ -60,43 +20,49 @@ const GeneratedProductHistory = () => {
60
20
const currentFilters = useAppSelector ( ( state ) => state . product . currentFilters )
61
21
const waitingForProductsToLoad = useAppSelector ( ( state ) => state . product . waitingForProductsToLoad )
62
22
const waitingForMyDataFiltering = useAppSelector ( ( state ) => state . product . waitingForMyDataFiltering )
23
+ const waitingForMyDataFilteringReset = useAppSelector ( ( state ) => state . product . waitingForMyDataFilteringReset )
63
24
const { search } = useLocation ( )
64
25
const navigate = useNavigate ( )
65
26
const [ totalNumberOfProducts , setTotalNumberOfProducts ] = useState < number > ( 0 )
66
27
const [ totalNumberOfFilteredProducts , setTotalNumberOfFilteredProducts ] = useState < number > ( 0 )
67
28
const [ checkedProducts , setCheckedProducts ] = useState < Product [ ] > ( [ ] )
68
29
const [ allChecked , setAllChecked ] = useState < boolean > ( false )
30
+ const [ hasAlreadyLoadedInitialProducts , setHasAlreadyLoadedInitialProducts ] = useState < boolean > ( false )
69
31
70
32
useEffect ( ( ) => {
71
33
// get the data for the first page
72
34
// go through all the user product data to get the id of each one so that
73
35
const fetchData = async ( ) => {
74
36
if ( ! waitingForMyDataFiltering ) dispatch ( setWaitingForProductsToLoad ( true ) )
75
- await getUserProducts ( { limit : '1000000' } ) . then ( response => {
37
+
38
+ const productQueryParameters = getFilterParameters ( currentFilters , defaultUserProductsLimit )
39
+ // add variables for filters
40
+ await getUserProducts ( productQueryParameters ) . then ( response => {
76
41
dispatch ( setWaitingForProductsToLoad ( false ) )
77
42
// filter products for what is in the filter
78
43
const allProducts = response . products as Product [ ]
79
44
setTotalNumberOfProducts ( allProducts . length )
80
45
const filteredProducts = allProducts . filter ( product => {
81
- const { status, utmZoneAdjust, mgrsBandAdjust, outputGranuleExtentFlag , outputSamplingGridType , rasterResolution, timestamp : dateGenerated , cycle , pass , scene , granules } = product
46
+ const { status, utmZoneAdjust, mgrsBandAdjust, rasterResolution} = product
82
47
const statusToUse = status [ 0 ] . state
83
- const outputSamplingGridTypeToUse = outputSamplingGridType === 'GEO' ? 'LAT/LON' : outputSamplingGridType
84
- const productPassesFilter = productPassesFilterCheck ( currentFilters , cycle , pass , scene , outputGranuleExtentFlag , statusToUse , outputSamplingGridTypeToUse , rasterResolution , dateGenerated , utmZoneAdjust , mgrsBandAdjust )
48
+ const productPassesFilter = productPassesFilterCheck ( currentFilters , statusToUse , rasterResolution , utmZoneAdjust , mgrsBandAdjust )
85
49
if ( productPassesFilter ) {
86
50
return product
87
51
} else {
88
52
return null
89
53
}
90
54
} )
91
55
setTotalNumberOfFilteredProducts ( filteredProducts . length )
56
+ setHasAlreadyLoadedInitialProducts ( true )
92
57
dispatch ( setAllUserProducts ( filteredProducts ) )
93
58
const productsPerPageToInt = parseInt ( productsPerPage )
94
59
dispatch ( setUserProducts ( filteredProducts . slice ( 0 , productsPerPageToInt ) ) )
95
60
dispatch ( setWaitingForMyDataFiltering ( false ) )
61
+ dispatch ( setWaitingForMyDataFilteringReset ( false ) )
96
62
} )
97
63
}
98
64
fetchData ( ) . catch ( console . error )
99
- } , [ currentFilters ] ) ;
65
+ } , [ dispatch , currentFilters , waitingForMyDataFiltering , waitingForMyDataFilteringReset ] ) ;
100
66
101
67
// reset all checked checkbox when going to next page
102
68
useEffect ( ( ) => {
@@ -226,7 +192,7 @@ const GeneratedProductHistory = () => {
226
192
</ div >
227
193
{ < DataPagination totalNumberOfProducts = { totalNumberOfProducts } totalNumberOfFilteredProducts = { totalNumberOfFilteredProducts } /> }
228
194
{ ! waitingForProductsToLoad && userProducts . length === 0 ? < Row > { productHistoryAlert ( ) } </ Row > : null }
229
- { waitingForProductsToLoad ? waitingForProductsToLoadSpinner ( ) : null }
195
+ { waitingForProductsToLoad && ! hasAlreadyLoadedInitialProducts ? waitingForProductsToLoadSpinner ( ) : null }
230
196
</ div >
231
197
</ Col >
232
198
</ Row >
0 commit comments