-
Notifications
You must be signed in to change notification settings - Fork 4k
fix: Keep the sole GPS segment when a trip is stopped after one recorded point #101027
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
Changes from all commits
3e793b4
77648b2
d854560
24651fa
bdaec22
259baa1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||||||||||
| import type {Coordinate} from '@components/MapView/MapViewTypes'; | ||||||||||||
|
|
||||||||||||
| import {BACKGROUND_LOCATION_TRACKING_TASK_NAME} from '@pages/iou/request/step/IOURequestStepDistanceGPS/const'; | ||||||||||||
| import {BACKGROUND_LOCATION_TRACKING_TASK_NAME, GPS_DISTANCE_INTERVAL_METERS} from '@pages/iou/request/step/IOURequestStepDistanceGPS/const'; | ||||||||||||
| import {stopGpsTripNotification} from '@pages/iou/request/step/IOURequestStepDistanceGPS/GPSNotifications'; | ||||||||||||
|
|
||||||||||||
| import type {GpsDraftDetails} from '@src/types/onyx'; | ||||||||||||
|
|
@@ -140,7 +140,10 @@ async function stopGpsTrip(isOffline: boolean, gpsPoints: GPSPoint[][], skipLast | |||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (isLastSegmentEmptyOrHasOnlyOnePoint(lastSegment)) { | ||||||||||||
| removeLastSegment(gpsPoints); | ||||||||||||
| // Dropping the sole segment would leave no points, which reads as a trip that never started | ||||||||||||
| if (gpsPoints.length > 1) { | ||||||||||||
| removeLastSegment(gpsPoints); | ||||||||||||
| } | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this part is the core fix - restores exactly the guard that #90237 added and #91418 deleted. The other 6 filesA stopped trip with exactly one point was previously an unreachable state, so everything downstream of
|
||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
@@ -187,6 +190,11 @@ function isTripStopped(gpsDraftDetails: GpsDraftDetails | undefined): boolean { | |||||||||||
| return !gpsDraftDetails?.isTracking && getTotalGpsTripPoints(gpsDraftDetails) > 0; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| function canGpsTripBeTrimmed(gpsDraftDetails: GpsDraftDetails | undefined): boolean { | ||||||||||||
| // Trimming cannot shorten a trip below one location interval, so a trip no longer than that has nothing to trim | ||||||||||||
| return isTripStopped(gpsDraftDetails) && (gpsDraftDetails?.distanceInMeters ?? 0) > GPS_DISTANCE_INTERVAL_METERS; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| function getGpsPoints(gpsDraftDetails: GpsDraftDetails | undefined): GPSPoint[][] { | ||||||||||||
| return gpsDraftDetails?.gpsPoints ?? [[]]; | ||||||||||||
| } | ||||||||||||
|
|
@@ -227,6 +235,7 @@ export { | |||||||||||
| getGPSRoutes, | ||||||||||||
| getGPSWaypoints, | ||||||||||||
| stopGpsTrip, | ||||||||||||
| canGpsTripBeTrimmed, | ||||||||||||
| getStringifiedGPSCoordinates, | ||||||||||||
| addressFromGpsPoint, | ||||||||||||
| coordinatesToString, | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import {removeLastSegment} from '@libs/actions/GPSDraftDetails'; | ||
|
|
||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type GpsDraftDetails from '@src/types/onyx/GpsDraftDetails'; | ||
| import type {GPSPoint} from '@src/types/onyx/GpsDraftDetails'; | ||
| import type {Unit} from '@src/types/onyx/Policy'; | ||
|
|
||
| import Onyx from 'react-native-onyx'; | ||
|
|
||
| import getOnyxValue from '../utils/getOnyxValue'; | ||
| import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
|
|
||
| const point = (lat: number, long: number): GPSPoint => ({lat, long}); | ||
|
|
||
| const stoppedTrip = (gpsPoints: GPSPoint[][]): GpsDraftDetails => ({ | ||
| gpsPoints, | ||
| distanceInMeters: 0, | ||
| isTracking: false, | ||
| reportID: '1', | ||
| unit: 'mi' as Unit, | ||
| }); | ||
|
|
||
| const getStoredPoints = async (): Promise<GPSPoint[][] | undefined> => { | ||
| await waitForBatchedUpdates(); | ||
| return (await getOnyxValue(ONYXKEYS.GPS_DRAFT_DETAILS))?.gpsPoints; | ||
| }; | ||
|
|
||
| describe('GPSDraftDetails actions', () => { | ||
| beforeAll(() => { | ||
| Onyx.init({keys: ONYXKEYS}); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| await Onyx.clear(); | ||
| }); | ||
|
|
||
| describe('removeLastSegment', () => { | ||
| it('drops the last segment of a resumed trip', async () => { | ||
| const gpsPoints = [[point(0, 0), point(0, 1)], [point(1, 0)]]; | ||
| await Onyx.set(ONYXKEYS.GPS_DRAFT_DETAILS, stoppedTrip(gpsPoints)); | ||
|
|
||
| removeLastSegment(gpsPoints); | ||
|
|
||
| expect(await getStoredPoints()).toEqual([[point(0, 0), point(0, 1)]]); | ||
| }); | ||
|
|
||
| it('keeps the only segment of a trip', async () => { | ||
| const gpsPoints = [[point(0, 0)]]; | ||
| await Onyx.set(ONYXKEYS.GPS_DRAFT_DETAILS, stoppedTrip(gpsPoints)); | ||
|
|
||
| removeLastSegment(gpsPoints); | ||
|
|
||
| expect(await getStoredPoints()).toEqual([[point(0, 0)]]); | ||
| }); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth verifying on device
This adds
zoomLevel={waypointsZoomLevel}to theCamera- a prop it never had.During tracking with one point recorded,
singlePointCoordinateis truthy, so the Camera now getscenterCoordinate+zoomLevel: 15whilefollowUserLocationis also true.rnmapbox should let follow-mode win, but controlled camera props fighting follow-mode has been flaky historically.
Confirm the map still tracks the user normally between the first and second recorded point.