-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Show recent waypoints when selecting address for distance request #25974
Changes from all commits
c4f93a3
c50feeb
f9dcecf
f58407a
2c9ffa5
e791e02
b818dba
ff8e227
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 |
---|---|---|
|
@@ -5,6 +5,12 @@ import ONYXKEYS from '../../ONYXKEYS'; | |
import * as CollectionUtils from '../CollectionUtils'; | ||
import * as API from '../API'; | ||
|
||
let recentWaypoints = []; | ||
Onyx.connect({ | ||
key: ONYXKEYS.NVP_RECENT_WAYPOINTS, | ||
callback: (val) => (recentWaypoints = val || []), | ||
}); | ||
|
||
const allTransactions = {}; | ||
Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.TRANSACTION, | ||
|
@@ -87,6 +93,12 @@ function saveWaypoint(transactionID, index, waypoint) { | |
}, | ||
}, | ||
}); | ||
const recentWaypointAlreadyExists = _.find(recentWaypoints, (recentWaypoint) => recentWaypoint.address === waypoint.address); | ||
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. FYI this caused a deploy blocker |
||
if (!recentWaypointAlreadyExists) { | ||
const clonedWaypoints = _.clone(recentWaypoints); | ||
clonedWaypoints.unshift(waypoint); | ||
Onyx.merge(ONYXKEYS.NVP_RECENT_WAYPOINTS, clonedWaypoints.slice(0, 5)); | ||
Comment on lines
+98
to
+100
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. I was thinking of doing slice 0, 4 first and add the other item. but not a blocker |
||
} | ||
} | ||
|
||
function removeWaypoint(transactionID, currentIndex) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import React, {useRef} from 'react'; | ||
import _ from 'underscore'; | ||
import lodashGet from 'lodash/get'; | ||
import {View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
|
@@ -53,7 +54,7 @@ const defaultProps = { | |
transaction: {}, | ||
}; | ||
|
||
function WaypointEditor({transactionID, route: {params: {iouType = '', waypointIndex = ''} = {}} = {}, network, translate, transaction}) { | ||
function WaypointEditor({transactionID, route: {params: {iouType = '', waypointIndex = ''} = {}} = {}, network, translate, transaction, recentWaypoints}) { | ||
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. 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. wonder why this wasn't caught during PR CI checks 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. Yes. It got caught in our PR but not here 🤔 🤔 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. this is handled by @allroundexperts now 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. Oh wow, yes... I'm surprised I missed it and doubly surprised that the linter missed it! Thanks for handling this. |
||
const textInput = useRef(null); | ||
const currentWaypoint = lodashGet(transaction, `comment.waypoints.waypoint${waypointIndex}`, {}); | ||
const waypointAddress = lodashGet(currentWaypoint, 'address', ''); | ||
|
@@ -151,6 +152,7 @@ function WaypointEditor({transactionID, route: {params: {iouType = '', waypointI | |
lng: null, | ||
state: null, | ||
}} | ||
predefinedPlaces={recentWaypoints} | ||
/> | ||
</View> | ||
</Form> | ||
|
@@ -169,5 +171,22 @@ export default compose( | |
key: (props) => `${ONYXKEYS.COLLECTION.TRANSACTION}${props.transactionID}`, | ||
selector: (transaction) => (transaction ? {transactionID: transaction.transactionID, comment: {waypoints: lodashGet(transaction, 'comment.waypoints')}} : null), | ||
}, | ||
|
||
recentWaypoints: { | ||
key: ONYXKEYS.NVP_RECENT_WAYPOINTS, | ||
|
||
// Only grab the most recent 5 waypoints because that's all that is shown in the UI. This also puts them into the format of data | ||
// that the google autocomplete component expects for it's "predefined places" feature. | ||
selector: (waypoints) => | ||
_.map(waypoints ? waypoints.slice(0, 5) : [], (waypoint) => ({ | ||
description: waypoint.address, | ||
geometry: { | ||
location: { | ||
lat: waypoint.lat, | ||
lng: waypoint.lng, | ||
}, | ||
}, | ||
})), | ||
}, | ||
}), | ||
)(WaypointEditor); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
type RecentWaypoints = { | ||
/** The full address of the waypoint */ | ||
address: string; | ||
|
||
/** The lattitude of the waypoint */ | ||
lat: number; | ||
|
||
/** The longitude of the waypoint */ | ||
lng: number; | ||
}; | ||
|
||
export default RecentWaypoints; |
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.
NAB. For consistency between inputs and outputs, I think we should use the waypoint shape here:
address
,lat
and `lng. The GooglePlacesAutocomplete is used internally, the props shape conversion should be done inside and not outside. i.e. the Onyx selector should not change the shape of the object.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.
Thanks, I understand your point. This is why I did not go that route (but I did consider it).
<AddressSearch>
component is used in many places.<AddressSearch>
would only be used for ONE of the places the component is implemented and won't be used for any of the other places. This is a waste.<AddressSearch>
makes it very highly coupled to the parent component (because it is assuming knowledge about the data being passed into it). This makes the component harder to reusepredefinedPlaces
prop with this shape allows any other component to use the same feature and not have to worry about conforming to the "waypoint shape".