Skip to content

Commit f563896

Browse files
authored
EDSC-4660: Fixes issue with removing "Granule ID(s)" value, and changing other values when Granule ID(s) is present (#2046)
* EDSC-4660: Fixes issue with removing "Granule ID(s)" value, and changing other values when Granule ID(s) is present * EDSC-4660: Removes whitespace from input before storing readableGranuleName values
1 parent c456529 commit f563896

6 files changed

Lines changed: 209 additions & 7 deletions

File tree

static/src/js/containers/GranuleFiltersContainer/__tests__/handleFormSubmit.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,40 @@ describe('handleFormSubmit', () => {
7979
expect(setSubmittingMock).toHaveBeenCalledWith(false)
8080
})
8181
})
82+
83+
describe('when readableGranuleName is defined with whitespace', () => {
84+
test('splits the value on the comma and trims whitespace', () => {
85+
useEdscStore.setState({
86+
query: {
87+
changeGranuleQuery: vi.fn()
88+
}
89+
})
90+
91+
const values = {
92+
readableGranuleName: ' 1, 2 , 3 '
93+
}
94+
95+
const config = {
96+
props: {
97+
collectionMetadata: {
98+
conceptId: 'collectionId'
99+
}
100+
},
101+
setSubmitting: setSubmittingMock
102+
}
103+
104+
handleFormSubmit(values, config)
105+
106+
const zustandState = useEdscStore.getState()
107+
const { query } = zustandState
108+
expect(query.changeGranuleQuery).toHaveBeenCalledTimes(1)
109+
expect(query.changeGranuleQuery).toHaveBeenCalledWith({
110+
collectionId: 'collectionId',
111+
query: { readableGranuleName: ['1', '2', '3'] }
112+
})
113+
114+
expect(setSubmittingMock).toHaveBeenCalledTimes(1)
115+
expect(setSubmittingMock).toHaveBeenCalledWith(false)
116+
})
117+
})
82118
})
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
import useEdscStore from '../../../zustand/useEdscStore'
2+
import mapPropsToValues from '../mapPropsToValues'
3+
4+
describe('mapPropsToValues', () => {
5+
describe('when there are no granule query values', () => {
6+
test('should return the expected values', () => {
7+
const expected = {
8+
browseOnly: false,
9+
cloudCover: {
10+
max: '',
11+
min: ''
12+
},
13+
dayNightFlag: '',
14+
equatorCrossingDate: {
15+
endDate: '',
16+
startDate: ''
17+
},
18+
equatorCrossingLongitude: {
19+
max: '',
20+
min: ''
21+
},
22+
gridCoords: '',
23+
onlineOnly: false,
24+
orbitNumber: {
25+
max: '',
26+
min: ''
27+
},
28+
readableGranuleName: '',
29+
temporal: {
30+
endDate: '',
31+
isRecurring: false,
32+
recurringDayEnd: '',
33+
recurringDayStart: '',
34+
startDate: ''
35+
},
36+
tilingSystem: ''
37+
}
38+
39+
const actual = mapPropsToValues()
40+
41+
expect(actual).toEqual(expected)
42+
})
43+
})
44+
45+
describe('when there are granule query values', () => {
46+
test('should return the expected values', () => {
47+
useEdscStore.setState({
48+
collection: {
49+
collectionId: 'collectionId'
50+
},
51+
query: {
52+
collection: {
53+
byId: {
54+
collectionId: {
55+
granules: {
56+
browseOnly: true,
57+
cloudCover: {
58+
max: '100',
59+
min: '0'
60+
},
61+
dayNightFlag: 'DAY',
62+
equatorCrossingDate: {
63+
endDate: '2020-01-01T00:00:00Z',
64+
startDate: '2020-01-01T00:00:00Z'
65+
},
66+
equatorCrossingLongitude: {
67+
max: '100',
68+
min: '0'
69+
},
70+
gridCoords: 'gridCoords',
71+
onlineOnly: true,
72+
orbitNumber: {
73+
max: '100',
74+
min: '0'
75+
},
76+
readableGranuleName: 'readableGranuleName',
77+
temporal: {
78+
endDate: '2020-01-01T00:00:00Z',
79+
isRecurring: true,
80+
recurringDayEnd: '10',
81+
recurringDayStart: '1',
82+
startDate: '2020-01-01T00:00:00Z'
83+
},
84+
tilingSystem: 'tilingSystem'
85+
}
86+
}
87+
}
88+
}
89+
}
90+
})
91+
92+
const expected = {
93+
browseOnly: true,
94+
cloudCover: {
95+
max: '100',
96+
min: '0'
97+
},
98+
dayNightFlag: 'DAY',
99+
equatorCrossingDate: {
100+
endDate: '2020-01-01T00:00:00Z',
101+
startDate: '2020-01-01T00:00:00Z'
102+
},
103+
equatorCrossingLongitude: {
104+
max: '100',
105+
min: '0'
106+
},
107+
gridCoords: 'gridCoords',
108+
onlineOnly: true,
109+
orbitNumber: {
110+
max: '100',
111+
min: '0'
112+
},
113+
readableGranuleName: 'readableGranuleName',
114+
temporal: {
115+
endDate: '2020-01-01T00:00:00Z',
116+
isRecurring: true,
117+
recurringDayEnd: '10',
118+
recurringDayStart: '1',
119+
startDate: '2020-01-01T00:00:00Z'
120+
},
121+
tilingSystem: 'tilingSystem'
122+
}
123+
124+
const actual = mapPropsToValues()
125+
126+
expect(actual).toEqual(expected)
127+
})
128+
129+
describe('when readableGranuleName is an array', () => {
130+
test('should join the array values with a comma', () => {
131+
useEdscStore.setState({
132+
collection: {
133+
collectionId: 'collectionId'
134+
},
135+
query: {
136+
collection: {
137+
byId: {
138+
collectionId: {
139+
granules: {
140+
readableGranuleName: ['readableGranuleName1', 'readableGranuleName2']
141+
}
142+
}
143+
}
144+
}
145+
}
146+
})
147+
148+
const expected = 'readableGranuleName1,readableGranuleName2'
149+
150+
const actual = mapPropsToValues().readableGranuleName
151+
152+
expect(actual).toEqual(expected)
153+
})
154+
})
155+
})
156+
})

static/src/js/containers/GranuleFiltersContainer/handleFormSubmit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ export const handleFormSubmit = (values, { props, setSubmitting }) => {
77

88
let granuleFilters = { ...values }
99

10-
// `readableGranuleName` needs to be sent as an array, split on the ','
10+
// `readableGranuleName` needs to be sent as an array, split on the ',' and trim any whitespace
1111
if (readableGranuleName) {
1212
granuleFilters = {
1313
...granuleFilters,
14-
readableGranuleName: readableGranuleName.split(',')
14+
readableGranuleName: readableGranuleName.split(',').map((name) => name.trim())
1515
}
1616
}
1717

static/src/js/containers/GranuleFiltersContainer/mapPropsToValues.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ export const mapPropsToValues = () => {
7575
recurringDayEnd: temporalRecurringDayEnd || '',
7676
isRecurring: temporalIsRecurring || false
7777
},
78-
readableGranuleName: readableGranuleName || ''
78+
readableGranuleName: Array.isArray(readableGranuleName)
79+
? readableGranuleName.join(',')
80+
: readableGranuleName || ''
7981
}
8082
}
8183

static/src/js/zustand/slices/__tests__/createQuerySlice.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ describe('createQuerySlice', () => {
368368
state.query.collection.byId.collectionId = {
369369
granules: {
370370
...initialGranuleQuery,
371+
readableGranuleName: ['granuleName'],
371372
pageNum: 2
372373
}
373374
}
@@ -390,6 +391,7 @@ describe('createQuerySlice', () => {
390391

391392
expect(updatedQuery.collection.byId.collectionId.granules).toEqual({
392393
...initialGranuleQuery,
394+
readableGranuleName: ['granuleName'],
393395
pageNum: 3
394396
})
395397

static/src/js/zustand/slices/createQuerySlice.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,22 @@ const createQuerySlice: ImmerStateCreator<QuerySlice> = (set, get) => ({
105105
}
106106
}
107107

108-
const prunedQuery = pruneFilters(query)
109-
110-
if (isEmpty(prunedQuery)) {
108+
if (isEmpty(query)) {
111109
state.query.collection.byId[collectionId].granules = {
112110
...initialGranuleQuery
113111
}
114112
} else {
113+
const currentGranuleQuery = state.query.collection.byId[collectionId]?.granules || {}
114+
115+
const mergedQuery = {
116+
...currentGranuleQuery,
117+
...query
118+
}
119+
120+
const prunedQuery = pruneFilters(mergedQuery)
121+
115122
state.query.collection.byId[collectionId].granules = {
116123
...initialGranuleQuery,
117-
...state.query.collection.byId[collectionId]?.granules,
118124
...prunedQuery
119125
}
120126
}

0 commit comments

Comments
 (0)