Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weā€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

šŸ› Fix draft trips not showing up for (i) unpushed transitions (ii) fresh user #1189

Merged
merged 4 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading