Skip to content

Commit

Permalink
Merge pull request #1189 from JGreenlee/timeline-fix-dec2024
Browse files Browse the repository at this point in the history
🐛 Fix draft trips not showing up for (i) unpushed transitions (ii) fresh user
  • Loading branch information
JGreenlee authored Dec 10, 2024
2 parents 3ecb3c5 + 478fc18 commit 97726aa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
12 changes: 6 additions & 6 deletions www/__mocks__/timelineHelperMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,19 @@ export const mockCompDataTwo = {
export const mockTransitions: Array<BEMData<TripTransition>> = [
{
data: {
// mock of a startTransition
// mock of an endTransition
currstate: '',
transition: 'T_EXITED_GEOFENCE',
ts: 1,
transition: 'T_TRIP_ENDED',
ts: 9999,
},
metadata: mockMetaData,
},
{
data: {
// mock of an endTransition
// mock of a startTransition
currstate: '',
transition: 'T_TRIP_ENDED',
ts: 9999,
transition: 'T_EXITED_GEOFENCE',
ts: 1,
},
metadata: mockMetaData,
},
Expand Down
25 changes: 13 additions & 12 deletions www/js/TimelineContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,33 +221,34 @@ export const useTimelineContext = (): ContextProps => {
}

async function fetchTripsInRange(dateRange: [string, string]) {
if (!pipelineRange?.start_ts || !pipelineRange?.end_ts) {
logDebug('No pipelineRange yet, returning empty lists');
return [[], []];
}
logDebug('Timeline: fetchTripsInRange from ' + dateRange[0] + ' to ' + dateRange[1]);

const [startTs, endTs] = isoDateRangeToTsRange(dateRange);
const maxStartTs = Math.max(startTs, pipelineRange.start_ts); // ensure that we don't read before the pipeline start
const minEndTs = Math.min(endTs, pipelineRange.end_ts); // ensure that we don't read after the pipeline end

const readCompositePromise = readAllCompositeTrips(maxStartTs, minEndTs);
let readCompositePromise; // comment
if (!pipelineRange?.start_ts || !pipelineRange?.end_ts) {
readCompositePromise = Promise.resolve([]);
} else {
const maxStartTs = Math.max(startTs, pipelineRange.start_ts); // ensure that we don't read before the pipeline start
const minEndTs = Math.min(endTs, pipelineRange.end_ts); // ensure that we don't read after the pipeline end
readCompositePromise = readAllCompositeTrips(maxStartTs, minEndTs);
}

let readUnprocessedPromise;
if (endTs >= pipelineRange.end_ts) {
if (pipelineRange?.end_ts && pipelineRange.end_ts > endTs) {
readUnprocessedPromise = Promise.resolve([]);
} else {
let lastProcessedTrip: CompositeTrip | undefined;
if (timelineMap) {
lastProcessedTrip = [...timelineMap?.values()]
.reverse()
.find((trip) => trip.origin_key.includes('trip')) as CompositeTrip;
}
readUnprocessedPromise = readUnprocessedTrips(
Math.max(pipelineRange.end_ts, startTs),
Math.max(pipelineRange?.end_ts || 0, startTs),
endTs,
appConfig,
lastProcessedTrip,
);
} else {
readUnprocessedPromise = Promise.resolve([]);
}

const results = await Promise.all([readCompositePromise, readUnprocessedPromise]);
Expand Down
7 changes: 4 additions & 3 deletions www/js/diary/timelineHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ function points2UnprocessedTrip(
};
}

const tsEntrySort = (e1: BEMData<FilteredLocation>, e2: BEMData<FilteredLocation>) =>
const tsEntrySort = (e1: BEMData<{ ts: number }>, e2: BEMData<{ ts: number }>) =>
e1.data.ts - e2.data.ts; // compare timestamps

/**
Expand All @@ -449,10 +449,10 @@ function tripTransitions2UnprocessedTrip(
if (locationList.length == 0) {
return undefined;
}
const sortedLocationList = locationList.sort(tsEntrySort);
locationList.sort(tsEntrySort);
const retainInRange = (loc) =>
tripStartTransition.data.ts <= loc.data.ts && loc.data.ts <= tripEndTransition.data.ts;
const filteredLocationList = sortedLocationList.filter(retainInRange);
const filteredLocationList = locationList.filter(retainInRange);

// Fix for https://github.com/e-mission/e-mission-docs/issues/417
if (filteredLocationList.length == 0) {
Expand Down Expand Up @@ -600,6 +600,7 @@ export function readUnprocessedTrips(
return [];
} else {
logDebug(`Found ${transitionList.length} transitions. yay!`);
transitionList.sort(tsEntrySort);
const tripsList = transitions2TripTransitions(transitionList);
logDebug(`Mapped into ${tripsList.length} trips. yay!`);
const tripFillPromises = tripsList.map((t) =>
Expand Down
4 changes: 3 additions & 1 deletion www/js/onboarding/WelcomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ const WelcomePage = () => {
}

function pasteCode() {
window['cordova'].plugins.clipboard.paste((clipboardContent: string) => {
// if clipboard plugin not available, the callback will be a no-op
const pasteFn = window['cordova'].plugins.clipboard?.paste || ((cb) => cb(''));
pasteFn((clipboardContent: string) => {
addStatReading('paste_token');
try {
if (!clipboardContent?.startsWith('nrelop_') && !clipboardContent?.includes('://')) {
Expand Down

0 comments on commit 97726aa

Please sign in to comment.