Skip to content

Commit

Permalink
fix errors on pipelineRange with null start_ts and end_ts
Browse files Browse the repository at this point in the history
For a new user where the pipeline has not yet processed, pipelineRange will be `{ start_ts: null, end_ts: null }`.
We should handle this appropriately:
-in TimelineScrollList, pipelineEndDate should be undefined instead of trying to call DateTime.fromSeconds with null
-loadDateRange should return early and do nothing
-The early return from fetchTripsInRange should return empty arrays, not void
  • Loading branch information
JGreenlee committed Oct 8, 2024
1 parent 7988b05 commit 667a726
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions www/js/TimelineContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ export const useTimelineContext = (): ContextProps => {

function loadDateRange(range: [string, string]) {
logDebug('Timeline: loadDateRange with newDateRange = ' + range);
if (!pipelineRange) {
logWarn('No pipelineRange yet - early return from loadDateRange');
if (!pipelineRange?.start_ts) {
logWarn('No pipelineRange start_ts yet - early return from loadDateRange');

Check warning on line 180 in www/js/TimelineContext.ts

View check run for this annotation

Codecov / codecov/patch

www/js/TimelineContext.ts#L180

Added line #L180 was not covered by tests
return;
}
const pipelineStartDate = DateTime.fromSeconds(pipelineRange.start_ts).toISODate();
Expand Down Expand Up @@ -220,8 +220,10 @@ export const useTimelineContext = (): ContextProps => {
}

async function fetchTripsInRange(dateRange: [string, string]) {
if (!pipelineRange?.start_ts || !pipelineRange?.end_ts)
return logWarn('No pipelineRange yet - early return');
if (!pipelineRange?.start_ts || !pipelineRange?.end_ts) {
logDebug('No pipelineRange yet, returning empty lists');
return [[], []];

Check warning on line 225 in www/js/TimelineContext.ts

View check run for this annotation

Codecov / codecov/patch

www/js/TimelineContext.ts#L224-L225

Added lines #L224 - L225 were not covered by tests
}
logDebug('Timeline: fetchTripsInRange from ' + dateRange[0] + ' to ' + dateRange[1]);

const [startTs, endTs] = isoDateRangeToTsRange(dateRange);
Expand Down
3 changes: 2 additions & 1 deletion www/js/diary/list/TimelineScrollList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ const TimelineScrollList = ({ listEntries }: Props) => {
</LoadMoreButton>
);

const pipelineEndDate = pipelineRange && DateTime.fromSeconds(pipelineRange.end_ts).toISODate();
const pipelineEndDate =
pipelineRange?.end_ts && DateTime.fromSeconds(pipelineRange.end_ts).toISODate();
const noTravelBanner = (
<Banner visible={true} icon={({ size }) => <Icon source="alert-circle" size={size} />}>
<View style={{ width: '100%' }}>
Expand Down

0 comments on commit 667a726

Please sign in to comment.