Skip to content

Commit 8638ca0

Browse files
committed
Updates
1 parent c5f43eb commit 8638ca0

File tree

3 files changed

+58
-40
lines changed

3 files changed

+58
-40
lines changed

app/src/features/surveys/observations/observations-table/grid-column-definitions/sampling-information/periods/SamplePeriodDataGridEditCell.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ export const SamplePeriodDataGridEditCell = <DataGridType extends GridValidRowMo
5454
);
5555
// The options for the autocomplete
5656
const [options, setOptions] = useState<SamplingInformationCachedPeriod[]>(
57-
samplingInformationCache.getPeriodsForRow(dataGridProps.row.method_technique_id)
57+
samplingInformationCache.getPeriodsForRow(
58+
dataGridProps.row.survey_sample_site_id,
59+
dataGridProps.row.method_technique_id
60+
)
5861
);
5962
// The survey sample site id and method technique id for the current set of options
6063
// These are used to detect if the site or technique value in the data grid state has changed, and therefore the

app/src/features/surveys/observations/observations-table/grid-column-definitions/sampling-information/techniques/MethodTechniqueDataGridEditCell.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const MethodTechniqueDataGridEditCell = <DataGridType extends GridValidRo
9090
return;
9191
}
9292

93-
const options: SamplingInformationCachedTechnique[] = response.techniques.map((item) => ({
93+
const options = response.techniques.map((item) => ({
9494
method_technique_id: item.method_technique_id,
9595
survey_sample_site_id: surveySampleSiteId,
9696
method_response_metric_id: item.method_response_metric_id,

app/src/features/surveys/observations/observations-table/grid-column-definitions/sampling-information/useSamplingInformationCache.tsx

+53-38
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,22 @@ export type SamplingInformationCache = {
5959
cachedSamplingInformationRef: MutableRefObject<SamplingInformationCacheRef | undefined>;
6060
initCachedSamplingInformationRef: (params: { periods?: GetSamplingPeriod[] }) => void;
6161
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;
6471
getCurrentSite: (surveySampleSiteId: number) => SamplingInformationCachedSite | null;
6572
getCurrentTechnique: (methodTechniqueId: number) => SamplingInformationCachedTechnique | null;
6673
getCurrentPeriod: (surveySamplePeriodId: number) => SamplingInformationCachedPeriod | null;
67-
getTechniquesForRow: (surveySampleSiteId?: number | null) => SamplingInformationCachedTechnique[];
74+
getTechniquesForRow: (surveySampleSiteId: number | null) => SamplingInformationCachedTechnique[];
6875
getPeriodsForRow: (
69-
surveySampleSiteId?: number | null,
70-
methodTechniqueId?: number | null
76+
surveySampleSiteId: number | null,
77+
methodTechniqueId: number | null
7178
) => SamplingInformationCachedPeriod[];
7279
};
7380

@@ -193,11 +200,11 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
193200
/**
194201
* Update the cache with new method techniques. Will ignore techniques that are already in the cache.
195202
*
196-
* @param {SamplingInformationCachedTechnique[]} techniques
203+
* @param {((SamplingInformationCachedTechnique & { survey_sample_site_id: number | null })[])} techniques
197204
* @return {*}
198205
*/
199206
const updateCachedMethodTechniques = (
200-
techniques: (SamplingInformationCachedTechnique & { survey_sample_site_id?: number })[]
207+
techniques: (SamplingInformationCachedTechnique & { survey_sample_site_id: number | null })[]
201208
) => {
202209
if (!cachedSamplingInformationRef.current) {
203210
return;
@@ -209,7 +216,9 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
209216
for (const technique of techniques) {
210217
if (!techniquesMap[technique.method_technique_id]) {
211218
// 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;
213222
}
214223

215224
if (technique.survey_sample_site_id) {
@@ -233,11 +242,17 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
233242
/**
234243
* Update the cache with new sampling periods. Will ignore periods that are already in the cache.
235244
*
236-
* @param {SamplingInformationCachedPeriod[]} periods
245+
* @param {((SamplingInformationCachedPeriod & {
246+
* survey_sample_site_id: number | null;
247+
* method_technique_id: number | null;
248+
* })[])} periods
237249
* @return {*}
238250
*/
239251
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+
})[]
241256
) => {
242257
if (!cachedSamplingInformationRef.current) {
243258
return;
@@ -249,7 +264,9 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
249264
for (const period of periods) {
250265
if (!periodsMap[period.survey_sample_period_id]) {
251266
// 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;
253270
}
254271

255272
if (period.survey_sample_site_id && period.method_technique_id) {
@@ -273,51 +290,49 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
273290
/**
274291
* Return the site object for the provided site id.
275292
*
276-
* @param {(number | null)} [siteId]
293+
* @param {(number | null)} surveySampleSiteId
277294
* @return {*} {(SamplingInformationCachedSite | null)}
278295
*/
279-
const findSite = (siteId?: number | null): SamplingInformationCachedSite | null => {
280-
if (!siteId) {
296+
const findSite = (surveySampleSiteId: number | null): SamplingInformationCachedSite | null => {
297+
if (!surveySampleSiteId) {
281298
return null;
282299
}
283300

284-
return cachedSamplingInformationRef.current?.sites[siteId] ?? null;
301+
return cachedSamplingInformationRef.current?.sites[surveySampleSiteId] ?? null;
285302
};
286303

287304
/**
288305
* Return the technique object for the provided technique id.
289306
*
290-
* @param {(number | null)} [techniqueId]
307+
* @param {(number | null)} techniqueId
291308
* @return {*} {(SamplingInformationCachedTechnique | null)}
292309
*/
293-
const findTechnique = (techniqueId?: number | null): SamplingInformationCachedTechnique | null => {
294-
if (!techniqueId) {
310+
const findTechnique = (methodTechniqueId: number | null): SamplingInformationCachedTechnique | null => {
311+
if (!methodTechniqueId) {
295312
return null;
296313
}
297314

298-
return cachedSamplingInformationRef.current?.techniques[techniqueId] ?? null;
315+
return cachedSamplingInformationRef.current?.techniques[methodTechniqueId] ?? null;
299316
};
300317

301318
/**
302319
* Return the period object for the provided period id.
303320
*
304-
* @param {(number | null)} [periodId]
321+
* @param {(number | null)} surveySamplePeriodId
305322
* @return {*} {(SamplingInformationCachedPeriod | null)}
306323
*/
307-
const findPeriod = (periodId?: number | null): SamplingInformationCachedPeriod | null => {
308-
if (!periodId) {
324+
const findPeriod = (surveySamplePeriodId: number | null): SamplingInformationCachedPeriod | null => {
325+
if (!surveySamplePeriodId) {
309326
return null;
310327
}
311328

312-
return cachedSamplingInformationRef.current?.periods[periodId] ?? null;
329+
return cachedSamplingInformationRef.current?.periods[surveySamplePeriodId] ?? null;
313330
};
314331

315332
/**
316333
* Get the currently selected site for the row.
317334
*
318-
* @template DataGridType
319-
* @param {GridRenderCellParams<DataGridType>} dataGridProps
320-
* @param {(MutableRefObject<SamplingInformationCacheRef | undefined>)} cachedSamplingInformationRef
335+
* @param {number} surveySampleSiteId
321336
* @return {*} {(SamplingInformationCachedSite | null)}
322337
*/
323338
const getCurrentSite = (surveySampleSiteId: number): SamplingInformationCachedSite | null => {
@@ -347,10 +362,10 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
347362
/**
348363
* Get all valid techniques for the currently selected site.
349364
*
350-
* @param {(number | null)} [surveySampleSiteId]
365+
* @param {(number | null)} surveySampleSiteId
351366
* @return {*} {SamplingInformationCachedTechnique[]}
352367
*/
353-
const getTechniquesForRow = (surveySampleSiteId?: number | null): SamplingInformationCachedTechnique[] => {
368+
const getTechniquesForRow = (surveySampleSiteId: number | null): SamplingInformationCachedTechnique[] => {
354369
if (!surveySampleSiteId) {
355370
return [];
356371
}
@@ -363,20 +378,20 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
363378

364379
// Get all techniques for the matching technique ids
365380
return methodTechniqueIds
366-
.map((techniqueId) => cachedSamplingInformationRef.current?.techniques[techniqueId])
381+
.map((methodTechniqueId) => cachedSamplingInformationRef.current?.techniques[methodTechniqueId])
367382
.filter((value): value is SamplingInformationCachedTechnique => value !== undefined);
368383
};
369384

370385
/**
371386
* Get all valid periods for the currently selected site and technique.
372387
*
373-
* @param {(number | null)} [surveySampleSiteId]
374-
* @param {(number | null)} [methodTechniqueId]
388+
* @param {(number | null)} surveySampleSiteId
389+
* @param {(number | null)} methodTechniqueId
375390
* @return {*} {SamplingInformationCachedPeriod[]}
376391
*/
377392
const getPeriodsForRow = (
378-
surveySampleSiteId?: number | null,
379-
methodTechniqueId?: number | null
393+
surveySampleSiteId: number | null,
394+
methodTechniqueId: number | null
380395
): SamplingInformationCachedPeriod[] => {
381396
if (!surveySampleSiteId || !methodTechniqueId) {
382397
return [];
@@ -398,21 +413,21 @@ export const useSamplingInformationCache = (): SamplingInformationCache => {
398413
/**
399414
* Get a key for the site technique index.
400415
*
401-
* @param {(number | null)} [surveySampleSiteId]
416+
* @param {(number | null)} surveySampleSiteId
402417
* @return {*} {IndexKey}
403418
*/
404-
const _getSiteTechniqueKey = (surveySampleSiteId?: number | null): IndexKey => {
419+
const _getSiteTechniqueKey = (surveySampleSiteId: number | null): IndexKey => {
405420
return `${surveySampleSiteId ?? null}`;
406421
};
407422

408423
/**
409424
* Get a key for the technique period index.
410425
*
411-
* @param {(number | null)} [surveySampleSiteId]
412-
* @param {(number | null)} [methodTechniqueId]
426+
* @param {(number | null)} surveySampleSiteId
427+
* @param {(number | null)} methodTechniqueId
413428
* @return {*} {IndexKey}
414429
*/
415-
const _getTechniquePeriodKey = (surveySampleSiteId?: number | null, methodTechniqueId?: number | null): IndexKey => {
430+
const _getTechniquePeriodKey = (surveySampleSiteId: number | null, methodTechniqueId: number | null): IndexKey => {
416431
return `${surveySampleSiteId ?? null}-${methodTechniqueId ?? null}`;
417432
};
418433

0 commit comments

Comments
 (0)