Skip to content

Commit 2933cfd

Browse files
authored
fix: preserve all dates for non-periodic datasets with summaries.datetime (#1967)
Closes: #1966 ### Description of Changes - Fix regression where non-periodic datasets with discrete dates in summaries.datetime only show the first 2 dates in the timeline instead of all dates - Skip normalizeDomain() for non-periodic data when domain has >2 discrete dates from summaries.datetime ### Notes & Questions About Changes _{Add additonal notes and outstanding questions here related to changes in this pull request}_ ### Validation / Testing - Using the deploy [preview in this PR](US-GHG-Center/veda-config-ghg#845), test the dataset mentioned in #1966 - Smoke test other datasets to make sure there are no regressions
2 parents 9d4847b + 75f8ce6 commit 2933cfd

File tree

2 files changed

+101
-4
lines changed

2 files changed

+101
-4
lines changed

packages/veda-ui/src/components/exploration/hooks/use-stac-metadata-data.spec.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,84 @@ describe('fetchStacDatasetById', () => {
171171
]);
172172
expect(result.renders).toEqual([{ id: 'r2' }]);
173173
});
174+
175+
it('preserves all dates for non-periodic data with summaries.datetime', async () => {
176+
mockedGet.mockResolvedValueOnce({
177+
data: {
178+
summaries: {
179+
datetime: [
180+
'2000-01-01T00:00:00Z',
181+
'2005-01-01T00:00:00Z',
182+
'2010-01-01T00:00:00Z',
183+
'2015-01-01T00:00:00Z',
184+
'2020-01-01T00:00:00Z'
185+
]
186+
},
187+
extent: {
188+
temporal: {
189+
interval: [['2000-01-01T00:00:00Z', '2020-01-01T00:00:00Z']]
190+
}
191+
},
192+
'dashboard:is_periodic': false,
193+
'dashboard:time_density': 'year'
194+
}
195+
});
196+
197+
const dataset = {
198+
data: { id: 'd6', type: 'raster', stacCol: 'col6' }
199+
} as any;
200+
201+
const { fetchStacDatasetById } = await import(
202+
'./use-stac-metadata-datasets'
203+
);
204+
const result = await fetchStacDatasetById(dataset, 'http://fake');
205+
206+
// Should preserve all 5 dates, not just the first 2
207+
expect(result.domain).toEqual([
208+
'2000-01-01T00:00:00Z',
209+
'2005-01-01T00:00:00Z',
210+
'2010-01-01T00:00:00Z',
211+
'2015-01-01T00:00:00Z',
212+
'2020-01-01T00:00:00Z'
213+
]);
214+
expect(result.isPeriodic).toBe(false);
215+
});
216+
217+
it('preserves all dates for non-periodic wmts with summaries.datetime', async () => {
218+
mockedGet.mockResolvedValueOnce({
219+
data: {
220+
summaries: {
221+
datetime: [
222+
'2000-01-01T00:00:00Z',
223+
'2005-01-01T00:00:00Z',
224+
'2010-01-01T00:00:00Z'
225+
]
226+
},
227+
extent: {
228+
temporal: {
229+
interval: [['2000-01-01T00:00:00Z', '2010-01-01T00:00:00Z']]
230+
}
231+
},
232+
'dashboard:is_periodic': false,
233+
'dashboard:time_density': 'year'
234+
}
235+
});
236+
237+
const dataset = {
238+
data: { id: 'd7', type: 'wmts', stacCol: 'col7' }
239+
} as any;
240+
241+
const { fetchStacDatasetById } = await import(
242+
'./use-stac-metadata-datasets'
243+
);
244+
const result = await fetchStacDatasetById(dataset, 'http://fake');
245+
246+
// Should preserve all 3 dates, not just the first 2
247+
expect(result.domain).toEqual([
248+
'2000-01-01T00:00:00Z',
249+
'2005-01-01T00:00:00Z',
250+
'2010-01-01T00:00:00Z'
251+
]);
252+
expect(result.isPeriodic).toBe(false);
253+
});
174254
});

packages/veda-ui/src/components/exploration/hooks/use-stac-metadata-datasets.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ export async function fetchStacDatasetById(
127127
domain: normalizeDomain(featuresApiData.extent.temporal.interval[0])
128128
};
129129
} else if (type === 'wms' || type === 'wmts') {
130-
let domain = data.summaries?.datetime?.[0]
130+
const fromSummaries = !!data.summaries?.datetime?.[0];
131+
let domain = fromSummaries
131132
? data.summaries.datetime
132133
: data.extent.temporal.interval[0];
133134

@@ -138,9 +139,18 @@ export async function fetchStacDatasetById(
138139
domain = [tempStart.toISOString(), new Date().toISOString()];
139140
}
140141

142+
// For non-periodic data with discrete dates from summaries.datetime,
143+
// keep all dates instead of normalizing to just start/end.
144+
// Only skip normalization if domain has >2 dates (normalization would truncate them).
145+
const shouldKeepAllDates =
146+
fromSummaries &&
147+
!commonTimeseriesParams.isPeriodic &&
148+
!data['dashboard:is_timeless'] &&
149+
domain.length > 2;
150+
141151
return {
142152
...commonTimeseriesParams,
143-
domain: normalizeDomain(domain)
153+
domain: shouldKeepAllDates ? domain : normalizeDomain(domain)
144154
};
145155
} else if (type === 'cmr') {
146156
const domain = data.summaries?.datetime?.[0]
@@ -157,7 +167,8 @@ export async function fetchStacDatasetById(
157167
domain: [domainStart, normalized[1]]
158168
};
159169
} else {
160-
const domain = data.summaries?.datetime?.[0]
170+
const fromSummaries = !!data.summaries?.datetime?.[0];
171+
const domain = fromSummaries
161172
? data.summaries.datetime
162173
: data.extent.temporal.interval[0];
163174

@@ -167,9 +178,15 @@ export async function fetchStacDatasetById(
167178
throw new Error('Invalid datetime domain');
168179
}
169180

181+
// For non-periodic data with discrete dates from summaries.datetime,
182+
// keep all dates instead of normalizing to just start/end.
183+
// Only skip normalization if domain has >2 dates (normalization would truncate them).
184+
const shouldKeepAllDates =
185+
fromSummaries && !commonTimeseriesParams.isPeriodic && domain.length > 2;
186+
170187
return {
171188
...commonTimeseriesParams,
172-
domain: normalizeDomain(domain),
189+
domain: shouldKeepAllDates ? domain : normalizeDomain(domain),
173190
renders
174191
};
175192
}

0 commit comments

Comments
 (0)