From 05d43c3db9064f3fe40e6e1a739d79e42a39b135 Mon Sep 17 00:00:00 2001 From: someone-here Date: Thu, 19 Oct 2023 07:42:09 +0530 Subject: [PATCH 01/12] Added 'name' field to waypoint --- src/components/AddressSearch/index.js | 20 ++++++++++++++++++- src/components/DistanceEReceipt.js | 3 ++- .../DistanceRequest/DistanceRequestFooter.js | 1 + .../DistanceRequestRenderItem.js | 3 ++- src/components/transactionPropTypes.js | 3 +++ src/libs/TransactionUtils.ts | 9 ++++++++- src/pages/iou/WaypointEditor.js | 8 ++++++++ src/types/onyx/RecentWaypoint.ts | 3 +++ src/types/onyx/Transaction.ts | 3 +++ 9 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/components/AddressSearch/index.js b/src/components/AddressSearch/index.js index 3e676b811c16..308b1bca6fb4 100644 --- a/src/components/AddressSearch/index.js +++ b/src/components/AddressSearch/index.js @@ -74,6 +74,9 @@ const propTypes = { /** A description of the location (usually the address) */ description: PropTypes.string, + /** The main name of the location */ + name: PropTypes.name, + /** Data required by the google auto complete plugin to know where to put the markers on the map */ geometry: PropTypes.shape({ /** Data about the location */ @@ -90,6 +93,7 @@ const propTypes = { /** A map of inputID key names */ renamedInputKeys: PropTypes.shape({ + name: PropTypes.string, street: PropTypes.string, street2: PropTypes.string, city: PropTypes.string, @@ -124,6 +128,7 @@ const defaultProps = { isLimitedToUSA: false, canUseCurrentLocation: false, renamedInputKeys: { + name: 'name', street: 'addressStreet', street2: 'addressStreet2', city: 'addressCity', @@ -170,6 +175,7 @@ function AddressSearch(props) { address: lodashGet(details, 'description', ''), lat: lodashGet(details, 'geometry.location.lat', 0), lng: lodashGet(details, 'geometry.location.lng', 0), + name: lodashGet(details, 'name', ''), }); } return; @@ -220,7 +226,7 @@ function AddressSearch(props) { const values = { street: `${streetNumber} ${streetName}`.trim(), - + name: lodashGet(details, 'name', ''), // Autocomplete returns any additional valid address fragments (e.g. Apt #) as subpremise. street2: subpremise, // Make sure country is updated first, since city and state will be reset if the country changes @@ -291,6 +297,7 @@ function AddressSearch(props) { getCurrentPosition( (successData) => { + console.log(successData); if (!shouldTriggerGeolocationCallbacks.current) { return; } @@ -301,6 +308,7 @@ function AddressSearch(props) { const location = { lat: successData.coords.latitude, lng: successData.coords.longitude, + name: CONST.YOUR_LOCATION_TEXT, address: CONST.YOUR_LOCATION_TEXT, }; props.onPress(location); @@ -382,6 +390,16 @@ function AddressSearch(props) { /> } + renderRow={(data) => { + const title = data.isPredefinedPlace ? data.name : data.structured_formatting.main_text; + const subtitle = data.isPredefinedPlace ? data.description: data.structured_formatting.secondary_text; + return ( + + {title} + {subtitle} + + ); + }} renderHeaderComponent={renderHeaderComponent} onPress={(data, details) => { saveLocationDetails(data, details); diff --git a/src/components/DistanceEReceipt.js b/src/components/DistanceEReceipt.js index f866de0b885e..2f40a866898e 100644 --- a/src/components/DistanceEReceipt.js +++ b/src/components/DistanceEReceipt.js @@ -91,7 +91,8 @@ function DistanceEReceipt({transaction}) { key={key} > {translate(descriptionKey)} - {waypoint.address || ''} + {waypoint.name || ''} + {waypoint.address || ''} ); })} diff --git a/src/components/DistanceRequest/DistanceRequestFooter.js b/src/components/DistanceRequest/DistanceRequestFooter.js index b0f6e0410ad5..c01a3cd77aa4 100644 --- a/src/components/DistanceRequest/DistanceRequestFooter.js +++ b/src/components/DistanceRequest/DistanceRequestFooter.js @@ -27,6 +27,7 @@ const propTypes = { lat: PropTypes.number, lng: PropTypes.number, address: PropTypes.string, + name: PropTypes.string, }), ), diff --git a/src/components/DistanceRequest/DistanceRequestRenderItem.js b/src/components/DistanceRequest/DistanceRequestRenderItem.js index 4e4eeee881c5..a96442eeff15 100644 --- a/src/components/DistanceRequest/DistanceRequestRenderItem.js +++ b/src/components/DistanceRequest/DistanceRequestRenderItem.js @@ -14,6 +14,7 @@ const propTypes = { lat: PropTypes.number, lng: PropTypes.number, address: PropTypes.string, + name: PropTypes.string, }), ), @@ -68,7 +69,7 @@ function DistanceRequestRenderItem({waypoints, item, onSecondaryInteraction, get return ( { + console.log(values); const waypoint = { lat: values.lat, lng: values.lng, address: values.address, + name: values.name, }; Transaction.saveWaypoint(transactionID, waypointIndex, waypoint, isEditingWaypoint); @@ -230,6 +236,7 @@ function WaypointEditor({route: {params: {iouType = '', transactionID = '', wayp maxInputLength={CONST.FORM_CHARACTER_LIMIT} renamedInputKeys={{ address: `waypoint${waypointIndex}`, + name: `waypoint${waypointIndex}`, city: null, country: null, street: null, @@ -264,6 +271,7 @@ export default withOnyx({ // that the google autocomplete component expects for it's "predefined places" feature. selector: (waypoints) => _.map(waypoints ? waypoints.slice(0, 5) : [], (waypoint) => ({ + name: waypoint.name, description: waypoint.address, geometry: { location: { diff --git a/src/types/onyx/RecentWaypoint.ts b/src/types/onyx/RecentWaypoint.ts index 79aded8ede98..151ce7da04f7 100644 --- a/src/types/onyx/RecentWaypoint.ts +++ b/src/types/onyx/RecentWaypoint.ts @@ -1,4 +1,7 @@ type RecentWaypoint = { + /** The name of the waypoint */ + name: string; + /** The full address of the waypoint */ address: string; diff --git a/src/types/onyx/Transaction.ts b/src/types/onyx/Transaction.ts index 21be3c49497e..bf8365a571a7 100644 --- a/src/types/onyx/Transaction.ts +++ b/src/types/onyx/Transaction.ts @@ -4,6 +4,9 @@ import CONST from '../../CONST'; import RecentWaypoint from './RecentWaypoint'; type Waypoint = { + /** The name of the waypoint */ + name?: string; + /** The full address of the waypoint */ address?: string; From 89e0fa4fdc0679d02dac5a8d27d6850cd91bc089 Mon Sep 17 00:00:00 2001 From: someone-here Date: Thu, 19 Oct 2023 07:48:25 +0530 Subject: [PATCH 02/12] Fix lint --- src/components/AddressSearch/index.js | 9 +++++++-- src/libs/TransactionUtils.ts | 2 +- src/types/onyx/Transaction.ts | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/AddressSearch/index.js b/src/components/AddressSearch/index.js index 308b1bca6fb4..ed71f772af84 100644 --- a/src/components/AddressSearch/index.js +++ b/src/components/AddressSearch/index.js @@ -392,11 +392,16 @@ function AddressSearch(props) { } renderRow={(data) => { const title = data.isPredefinedPlace ? data.name : data.structured_formatting.main_text; - const subtitle = data.isPredefinedPlace ? data.description: data.structured_formatting.secondary_text; + const subtitle = data.isPredefinedPlace ? data.description : data.structured_formatting.secondary_text; return ( {title} - {subtitle} + + {subtitle} + ); }} diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index d19177fe575a..50be94cf857d 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -403,7 +403,7 @@ function waypointHasValidAddress(waypoint: RecentWaypoint | Waypoint): boolean { return !!waypoint?.address?.trim(); } -/** +/** * Checks if a waypoint has a valid name */ function waypointHasValidName(waypoint: RecentWaypoint | Waypoint): boolean { diff --git a/src/types/onyx/Transaction.ts b/src/types/onyx/Transaction.ts index bf8365a571a7..3933ec2205db 100644 --- a/src/types/onyx/Transaction.ts +++ b/src/types/onyx/Transaction.ts @@ -6,7 +6,7 @@ import RecentWaypoint from './RecentWaypoint'; type Waypoint = { /** The name of the waypoint */ name?: string; - + /** The full address of the waypoint */ address?: string; From 68060f3cc0757d4e2e90364aaf6be603a41aee6e Mon Sep 17 00:00:00 2001 From: someone-here Date: Thu, 19 Oct 2023 07:51:47 +0530 Subject: [PATCH 03/12] Remove console logs --- src/components/AddressSearch/index.js | 1 - src/pages/iou/WaypointEditor.js | 1 - 2 files changed, 2 deletions(-) diff --git a/src/components/AddressSearch/index.js b/src/components/AddressSearch/index.js index ed71f772af84..355b2dd4a8c7 100644 --- a/src/components/AddressSearch/index.js +++ b/src/components/AddressSearch/index.js @@ -297,7 +297,6 @@ function AddressSearch(props) { getCurrentPosition( (successData) => { - console.log(successData); if (!shouldTriggerGeolocationCallbacks.current) { return; } diff --git a/src/pages/iou/WaypointEditor.js b/src/pages/iou/WaypointEditor.js index f9fbed1c4bf0..0567228d8278 100644 --- a/src/pages/iou/WaypointEditor.js +++ b/src/pages/iou/WaypointEditor.js @@ -163,7 +163,6 @@ function WaypointEditor({route: {params: {iouType = '', transactionID = '', wayp }; const selectWaypoint = (values) => { - console.log(values); const waypoint = { lat: values.lat, lng: values.lng, From 7c9d15af19dd02037706fa9cb9dd560888d522b0 Mon Sep 17 00:00:00 2001 From: someone-here Date: Thu, 19 Oct 2023 20:38:02 +0530 Subject: [PATCH 04/12] Correct Proptypes --- src/components/AddressSearch/index.js | 2 +- src/components/transactionPropTypes.js | 2 +- src/pages/iou/WaypointEditor.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/AddressSearch/index.js b/src/components/AddressSearch/index.js index 355b2dd4a8c7..678df037ce4c 100644 --- a/src/components/AddressSearch/index.js +++ b/src/components/AddressSearch/index.js @@ -75,7 +75,7 @@ const propTypes = { description: PropTypes.string, /** The main name of the location */ - name: PropTypes.name, + name: PropTypes.string, /** Data required by the google auto complete plugin to know where to put the markers on the map */ geometry: PropTypes.shape({ diff --git a/src/components/transactionPropTypes.js b/src/components/transactionPropTypes.js index 7d29a8215605..e3e06bb00c01 100644 --- a/src/components/transactionPropTypes.js +++ b/src/components/transactionPropTypes.js @@ -47,7 +47,7 @@ export default PropTypes.shape({ address: PropTypes.string, /** The name of the waypoint */ - name: PropTypes.name, + name: PropTypes.string, }), }), diff --git a/src/pages/iou/WaypointEditor.js b/src/pages/iou/WaypointEditor.js index 0567228d8278..878d85501943 100644 --- a/src/pages/iou/WaypointEditor.js +++ b/src/pages/iou/WaypointEditor.js @@ -46,7 +46,7 @@ const propTypes = { recentWaypoints: PropTypes.arrayOf( PropTypes.shape({ /** The name of the location */ - name: PropTypes.name, + name: PropTypes.string, /** A description of the location (usually the address) */ description: PropTypes.string, From 034549f3ba499d31b3e2409dc6235b1861325fe1 Mon Sep 17 00:00:00 2001 From: Esh Tanya Gupta <77237602+esh-g@users.noreply.github.com> Date: Thu, 19 Oct 2023 23:42:42 +0530 Subject: [PATCH 05/12] Edit comment Co-authored-by: Manan --- src/components/AddressSearch/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AddressSearch/index.js b/src/components/AddressSearch/index.js index 678df037ce4c..11a6ae547074 100644 --- a/src/components/AddressSearch/index.js +++ b/src/components/AddressSearch/index.js @@ -74,7 +74,7 @@ const propTypes = { /** A description of the location (usually the address) */ description: PropTypes.string, - /** The main name of the location */ + /** The name of the location */ name: PropTypes.string, /** Data required by the google auto complete plugin to know where to put the markers on the map */ From be1585a87c69aaa8017871e72dd91341afc1fcd4 Mon Sep 17 00:00:00 2001 From: someone-here Date: Thu, 19 Oct 2023 23:47:51 +0530 Subject: [PATCH 06/12] Remove unnecessary comments --- src/libs/TransactionUtils.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 50be94cf857d..156b4c241656 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -396,16 +396,10 @@ function getAllReportTransactions(reportID?: string): Transaction[] { return transactions.filter((transaction) => `${transaction.reportID}` === `${reportID}`); } -/** - * Checks if a waypoint has a valid address - */ function waypointHasValidAddress(waypoint: RecentWaypoint | Waypoint): boolean { return !!waypoint?.address?.trim(); } -/** - * Checks if a waypoint has a valid name - */ function waypointHasValidName(waypoint: RecentWaypoint | Waypoint): boolean { return !!waypoint?.name?.trim(); } From 5df39feaa63fa60ec25138e9e946fead310ca19c Mon Sep 17 00:00:00 2001 From: someone-here Date: Fri, 20 Oct 2023 15:36:36 +0530 Subject: [PATCH 07/12] Handle case if 'name' not defined --- src/components/AddressSearch/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/AddressSearch/index.js b/src/components/AddressSearch/index.js index 11a6ae547074..8decb2cf43e1 100644 --- a/src/components/AddressSearch/index.js +++ b/src/components/AddressSearch/index.js @@ -394,12 +394,12 @@ function AddressSearch(props) { const subtitle = data.isPredefinedPlace ? data.description : data.structured_formatting.secondary_text; return ( - {title} + {title ? title : subtitle} - {subtitle} + {title && subtitle ? subtitle : ''} ); From ce6c906fac78fc6752e919fbdadc3cd71a387cc2 Mon Sep 17 00:00:00 2001 From: someone-here Date: Fri, 20 Oct 2023 15:39:34 +0530 Subject: [PATCH 08/12] Fix lint --- src/components/AddressSearch/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AddressSearch/index.js b/src/components/AddressSearch/index.js index 8decb2cf43e1..0849b6e075a4 100644 --- a/src/components/AddressSearch/index.js +++ b/src/components/AddressSearch/index.js @@ -394,7 +394,7 @@ function AddressSearch(props) { const subtitle = data.isPredefinedPlace ? data.description : data.structured_formatting.secondary_text; return ( - {title ? title : subtitle} + {title || subtitle} Date: Sat, 21 Oct 2023 20:50:52 +0530 Subject: [PATCH 09/12] Changes requested in review --- src/components/AddressSearch/index.js | 11 +++-------- src/components/DistanceEReceipt.js | 6 ++++-- .../DistanceRequest/DistanceRequestRenderItem.js | 5 ++++- src/libs/TransactionUtils.ts | 6 +----- src/pages/iou/WaypointEditor.js | 3 +-- src/types/onyx/RecentWaypoint.ts | 4 ++-- src/types/onyx/Transaction.ts | 2 +- 7 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/components/AddressSearch/index.js b/src/components/AddressSearch/index.js index 0849b6e075a4..909801bd7ec7 100644 --- a/src/components/AddressSearch/index.js +++ b/src/components/AddressSearch/index.js @@ -172,10 +172,10 @@ function AddressSearch(props) { // amount of data massaging needs to happen for what the parent expects to get from this function. if (_.size(details)) { props.onPress({ - address: lodashGet(details, 'description', ''), + address: lodashGet(details, 'description'), lat: lodashGet(details, 'geometry.location.lat', 0), lng: lodashGet(details, 'geometry.location.lng', 0), - name: lodashGet(details, 'name', ''), + name: lodashGet(details, 'name'), }); } return; @@ -395,12 +395,7 @@ function AddressSearch(props) { return ( {title || subtitle} - - {title && subtitle ? subtitle : ''} - + {title && subtitle && {subtitle}} ); }} diff --git a/src/components/DistanceEReceipt.js b/src/components/DistanceEReceipt.js index 2f40a866898e..16b3faa9dd25 100644 --- a/src/components/DistanceEReceipt.js +++ b/src/components/DistanceEReceipt.js @@ -85,14 +85,16 @@ function DistanceEReceipt({transaction}) { } else { descriptionKey += 'stop'; } + const title = waypoint.name || waypoint.address; + const subtitle = waypoint.name && waypoint.address ? waypoint.address : undefined; return ( {translate(descriptionKey)} - {waypoint.name || ''} - {waypoint.address || ''} + {title} + {subtitle && {subtitle}} ); })} diff --git a/src/components/DistanceRequest/DistanceRequestRenderItem.js b/src/components/DistanceRequest/DistanceRequestRenderItem.js index a96442eeff15..0e54635e82cc 100644 --- a/src/components/DistanceRequest/DistanceRequestRenderItem.js +++ b/src/components/DistanceRequest/DistanceRequestRenderItem.js @@ -66,10 +66,13 @@ function DistanceRequestRenderItem({waypoints, item, onSecondaryInteraction, get waypointIcon = Expensicons.DotIndicator; } + const waypoint = lodashGet(waypoints, [`waypoint${index}`], {}); + const title = waypoint.name || waypoint.address; + return ( Date: Mon, 23 Oct 2023 23:04:44 +0530 Subject: [PATCH 10/12] secondary text style when name missing --- src/components/AddressSearch/index.js | 4 ++-- src/components/DistanceEReceipt.js | 6 ++---- src/pages/iou/WaypointEditor.js | 1 - 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/components/AddressSearch/index.js b/src/components/AddressSearch/index.js index 909801bd7ec7..c0e32099ff2f 100644 --- a/src/components/AddressSearch/index.js +++ b/src/components/AddressSearch/index.js @@ -394,8 +394,8 @@ function AddressSearch(props) { const subtitle = data.isPredefinedPlace ? data.description : data.structured_formatting.secondary_text; return ( - {title || subtitle} - {title && subtitle && {subtitle}} + {title && {title}} + {subtitle} ); }} diff --git a/src/components/DistanceEReceipt.js b/src/components/DistanceEReceipt.js index 16b3faa9dd25..98f50b1f682f 100644 --- a/src/components/DistanceEReceipt.js +++ b/src/components/DistanceEReceipt.js @@ -85,16 +85,14 @@ function DistanceEReceipt({transaction}) { } else { descriptionKey += 'stop'; } - const title = waypoint.name || waypoint.address; - const subtitle = waypoint.name && waypoint.address ? waypoint.address : undefined; return ( {translate(descriptionKey)} - {title} - {subtitle && {subtitle}} + {waypoint.name && {waypoint.name}} + {waypoint.address && {waypoint.address}} ); })} diff --git a/src/pages/iou/WaypointEditor.js b/src/pages/iou/WaypointEditor.js index 6dde7e0e724b..03ce3cba28bd 100644 --- a/src/pages/iou/WaypointEditor.js +++ b/src/pages/iou/WaypointEditor.js @@ -234,7 +234,6 @@ function WaypointEditor({route: {params: {iouType = '', transactionID = '', wayp maxInputLength={CONST.FORM_CHARACTER_LIMIT} renamedInputKeys={{ address: `waypoint${waypointIndex}`, - name: null, city: null, country: null, street: null, From 67e53222afce04d94703d34f772a31b900fe8b43 Mon Sep 17 00:00:00 2001 From: someone-here Date: Mon, 23 Oct 2023 23:11:48 +0530 Subject: [PATCH 11/12] Unset name for current location --- src/components/AddressSearch/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/AddressSearch/index.js b/src/components/AddressSearch/index.js index c0e32099ff2f..bbab1ee35ba6 100644 --- a/src/components/AddressSearch/index.js +++ b/src/components/AddressSearch/index.js @@ -307,7 +307,6 @@ function AddressSearch(props) { const location = { lat: successData.coords.latitude, lng: successData.coords.longitude, - name: CONST.YOUR_LOCATION_TEXT, address: CONST.YOUR_LOCATION_TEXT, }; props.onPress(location); From 55ffbda2b6696ca2e92ab165e4b78a3a9389d7b3 Mon Sep 17 00:00:00 2001 From: someone-here Date: Mon, 23 Oct 2023 23:16:35 +0530 Subject: [PATCH 12/12] Remove name from input keys --- src/components/AddressSearch/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/AddressSearch/index.js b/src/components/AddressSearch/index.js index bbab1ee35ba6..035b7f43cdf5 100644 --- a/src/components/AddressSearch/index.js +++ b/src/components/AddressSearch/index.js @@ -93,7 +93,6 @@ const propTypes = { /** A map of inputID key names */ renamedInputKeys: PropTypes.shape({ - name: PropTypes.string, street: PropTypes.string, street2: PropTypes.string, city: PropTypes.string, @@ -128,7 +127,6 @@ const defaultProps = { isLimitedToUSA: false, canUseCurrentLocation: false, renamedInputKeys: { - name: 'name', street: 'addressStreet', street2: 'addressStreet2', city: 'addressCity',