@@ -59,15 +59,22 @@ export type SamplingInformationCache = {
59
59
cachedSamplingInformationRef : MutableRefObject < SamplingInformationCacheRef | undefined > ;
60
60
initCachedSamplingInformationRef : ( params : { periods ?: GetSamplingPeriod [ ] } ) => void ;
61
61
updateCachedSamplingSites : ( sites : SamplingInformationCachedSite [ ] ) => void ;
62
- updateCachedMethodTechniques : ( techniques : SamplingInformationCachedTechnique [ ] ) => void ;
63
- updateCachedSamplingPeriods : ( periods : SamplingInformationCachedPeriod [ ] ) => void ;
62
+ updateCachedMethodTechniques : (
63
+ techniques : ( SamplingInformationCachedTechnique & { survey_sample_site_id : number | null } ) [ ]
64
+ ) => void ;
65
+ updateCachedSamplingPeriods : (
66
+ periods : ( SamplingInformationCachedPeriod & {
67
+ survey_sample_site_id : number | null ;
68
+ method_technique_id : number | null ;
69
+ } ) [ ]
70
+ ) => void ;
64
71
getCurrentSite : ( surveySampleSiteId : number ) => SamplingInformationCachedSite | null ;
65
72
getCurrentTechnique : ( methodTechniqueId : number ) => SamplingInformationCachedTechnique | null ;
66
73
getCurrentPeriod : ( surveySamplePeriodId : number ) => SamplingInformationCachedPeriod | null ;
67
- getTechniquesForRow : ( surveySampleSiteId ? : number | null ) => SamplingInformationCachedTechnique [ ] ;
74
+ getTechniquesForRow : ( surveySampleSiteId : number | null ) => SamplingInformationCachedTechnique [ ] ;
68
75
getPeriodsForRow : (
69
- surveySampleSiteId ? : number | null ,
70
- methodTechniqueId ? : number | null
76
+ surveySampleSiteId : number | null ,
77
+ methodTechniqueId : number | null
71
78
) => SamplingInformationCachedPeriod [ ] ;
72
79
} ;
73
80
@@ -193,11 +200,11 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
193
200
/**
194
201
* Update the cache with new method techniques. Will ignore techniques that are already in the cache.
195
202
*
196
- * @param {SamplingInformationCachedTechnique[] } techniques
203
+ * @param {(( SamplingInformationCachedTechnique & { survey_sample_site_id: number | null })[]) } techniques
197
204
* @return {* }
198
205
*/
199
206
const updateCachedMethodTechniques = (
200
- techniques : ( SamplingInformationCachedTechnique & { survey_sample_site_id ? : number } ) [ ]
207
+ techniques : ( SamplingInformationCachedTechnique & { survey_sample_site_id : number | null } ) [ ]
201
208
) => {
202
209
if ( ! cachedSamplingInformationRef . current ) {
203
210
return ;
@@ -209,7 +216,9 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
209
216
for ( const technique of techniques ) {
210
217
if ( ! techniquesMap [ technique . method_technique_id ] ) {
211
218
// If the technique is not already in the map, add it
212
- techniquesMap [ technique . method_technique_id ] = technique ;
219
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
220
+ const { survey_sample_site_id, ...rest } = technique ;
221
+ techniquesMap [ technique . method_technique_id ] = rest ;
213
222
}
214
223
215
224
if ( technique . survey_sample_site_id ) {
@@ -233,11 +242,17 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
233
242
/**
234
243
* Update the cache with new sampling periods. Will ignore periods that are already in the cache.
235
244
*
236
- * @param {SamplingInformationCachedPeriod[] } periods
245
+ * @param {((SamplingInformationCachedPeriod & {
246
+ * survey_sample_site_id: number | null;
247
+ * method_technique_id: number | null;
248
+ * })[])} periods
237
249
* @return {* }
238
250
*/
239
251
const updateCachedSamplingPeriods = (
240
- periods : ( SamplingInformationCachedPeriod & { survey_sample_site_id ?: number ; method_technique_id ?: number } ) [ ]
252
+ periods : ( SamplingInformationCachedPeriod & {
253
+ survey_sample_site_id : number | null ;
254
+ method_technique_id : number | null ;
255
+ } ) [ ]
241
256
) => {
242
257
if ( ! cachedSamplingInformationRef . current ) {
243
258
return ;
@@ -249,7 +264,9 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
249
264
for ( const period of periods ) {
250
265
if ( ! periodsMap [ period . survey_sample_period_id ] ) {
251
266
// If the period is not already in the map, add it
252
- periodsMap [ period . survey_sample_period_id ] = period ;
267
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
268
+ const { survey_sample_site_id, method_technique_id, ...rest } = period ;
269
+ periodsMap [ period . survey_sample_period_id ] = rest ;
253
270
}
254
271
255
272
if ( period . survey_sample_site_id && period . method_technique_id ) {
@@ -273,51 +290,49 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
273
290
/**
274
291
* Return the site object for the provided site id.
275
292
*
276
- * @param {(number | null) } [siteId]
293
+ * @param {(number | null) } surveySampleSiteId
277
294
* @return {* } {(SamplingInformationCachedSite | null)}
278
295
*/
279
- const findSite = ( siteId ? : number | null ) : SamplingInformationCachedSite | null => {
280
- if ( ! siteId ) {
296
+ const findSite = ( surveySampleSiteId : number | null ) : SamplingInformationCachedSite | null => {
297
+ if ( ! surveySampleSiteId ) {
281
298
return null ;
282
299
}
283
300
284
- return cachedSamplingInformationRef . current ?. sites [ siteId ] ?? null ;
301
+ return cachedSamplingInformationRef . current ?. sites [ surveySampleSiteId ] ?? null ;
285
302
} ;
286
303
287
304
/**
288
305
* Return the technique object for the provided technique id.
289
306
*
290
- * @param {(number | null) } [ techniqueId]
307
+ * @param {(number | null) } techniqueId
291
308
* @return {* } {(SamplingInformationCachedTechnique | null)}
292
309
*/
293
- const findTechnique = ( techniqueId ? : number | null ) : SamplingInformationCachedTechnique | null => {
294
- if ( ! techniqueId ) {
310
+ const findTechnique = ( methodTechniqueId : number | null ) : SamplingInformationCachedTechnique | null => {
311
+ if ( ! methodTechniqueId ) {
295
312
return null ;
296
313
}
297
314
298
- return cachedSamplingInformationRef . current ?. techniques [ techniqueId ] ?? null ;
315
+ return cachedSamplingInformationRef . current ?. techniques [ methodTechniqueId ] ?? null ;
299
316
} ;
300
317
301
318
/**
302
319
* Return the period object for the provided period id.
303
320
*
304
- * @param {(number | null) } [periodId]
321
+ * @param {(number | null) } surveySamplePeriodId
305
322
* @return {* } {(SamplingInformationCachedPeriod | null)}
306
323
*/
307
- const findPeriod = ( periodId ? : number | null ) : SamplingInformationCachedPeriod | null => {
308
- if ( ! periodId ) {
324
+ const findPeriod = ( surveySamplePeriodId : number | null ) : SamplingInformationCachedPeriod | null => {
325
+ if ( ! surveySamplePeriodId ) {
309
326
return null ;
310
327
}
311
328
312
- return cachedSamplingInformationRef . current ?. periods [ periodId ] ?? null ;
329
+ return cachedSamplingInformationRef . current ?. periods [ surveySamplePeriodId ] ?? null ;
313
330
} ;
314
331
315
332
/**
316
333
* Get the currently selected site for the row.
317
334
*
318
- * @template DataGridType
319
- * @param {GridRenderCellParams<DataGridType> } dataGridProps
320
- * @param {(MutableRefObject<SamplingInformationCacheRef | undefined>) } cachedSamplingInformationRef
335
+ * @param {number } surveySampleSiteId
321
336
* @return {* } {(SamplingInformationCachedSite | null)}
322
337
*/
323
338
const getCurrentSite = ( surveySampleSiteId : number ) : SamplingInformationCachedSite | null => {
@@ -347,10 +362,10 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
347
362
/**
348
363
* Get all valid techniques for the currently selected site.
349
364
*
350
- * @param {(number | null) } [ surveySampleSiteId]
365
+ * @param {(number | null) } surveySampleSiteId
351
366
* @return {* } {SamplingInformationCachedTechnique[]}
352
367
*/
353
- const getTechniquesForRow = ( surveySampleSiteId ? : number | null ) : SamplingInformationCachedTechnique [ ] => {
368
+ const getTechniquesForRow = ( surveySampleSiteId : number | null ) : SamplingInformationCachedTechnique [ ] => {
354
369
if ( ! surveySampleSiteId ) {
355
370
return [ ] ;
356
371
}
@@ -363,20 +378,20 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
363
378
364
379
// Get all techniques for the matching technique ids
365
380
return methodTechniqueIds
366
- . map ( ( techniqueId ) => cachedSamplingInformationRef . current ?. techniques [ techniqueId ] )
381
+ . map ( ( methodTechniqueId ) => cachedSamplingInformationRef . current ?. techniques [ methodTechniqueId ] )
367
382
. filter ( ( value ) : value is SamplingInformationCachedTechnique => value !== undefined ) ;
368
383
} ;
369
384
370
385
/**
371
386
* Get all valid periods for the currently selected site and technique.
372
387
*
373
- * @param {(number | null) } [ surveySampleSiteId]
374
- * @param {(number | null) } [ methodTechniqueId]
388
+ * @param {(number | null) } surveySampleSiteId
389
+ * @param {(number | null) } methodTechniqueId
375
390
* @return {* } {SamplingInformationCachedPeriod[]}
376
391
*/
377
392
const getPeriodsForRow = (
378
- surveySampleSiteId ? : number | null ,
379
- methodTechniqueId ? : number | null
393
+ surveySampleSiteId : number | null ,
394
+ methodTechniqueId : number | null
380
395
) : SamplingInformationCachedPeriod [ ] => {
381
396
if ( ! surveySampleSiteId || ! methodTechniqueId ) {
382
397
return [ ] ;
@@ -398,21 +413,21 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
398
413
/**
399
414
* Get a key for the site technique index.
400
415
*
401
- * @param {(number | null) } [ surveySampleSiteId]
416
+ * @param {(number | null) } surveySampleSiteId
402
417
* @return {* } {IndexKey}
403
418
*/
404
- const _getSiteTechniqueKey = ( surveySampleSiteId ? : number | null ) : IndexKey => {
419
+ const _getSiteTechniqueKey = ( surveySampleSiteId : number | null ) : IndexKey => {
405
420
return `${ surveySampleSiteId ?? null } ` ;
406
421
} ;
407
422
408
423
/**
409
424
* Get a key for the technique period index.
410
425
*
411
- * @param {(number | null) } [ surveySampleSiteId]
412
- * @param {(number | null) } [ methodTechniqueId]
426
+ * @param {(number | null) } surveySampleSiteId
427
+ * @param {(number | null) } methodTechniqueId
413
428
* @return {* } {IndexKey}
414
429
*/
415
- const _getTechniquePeriodKey = ( surveySampleSiteId ? : number | null , methodTechniqueId ? : number | null ) : IndexKey => {
430
+ const _getTechniquePeriodKey = ( surveySampleSiteId : number | null , methodTechniqueId : number | null ) : IndexKey => {
416
431
return `${ surveySampleSiteId ?? null } -${ methodTechniqueId ?? null } ` ;
417
432
} ;
418
433
0 commit comments