@@ -19,7 +19,7 @@ import {
1919 UserLocationIcon
2020} from "./options" ;
2121import * as S from "./styled" ;
22- import { generateLabel } from "./utils" ;
22+ import { generateLabel , getCombinedLabel } from "./utils" ;
2323
2424// FIXME have a better key generator for options
2525let optionKey = 0 ;
@@ -98,7 +98,8 @@ class LocationField extends Component {
9898 /* FIXME only disabled this because it'd take longer to refactor */
9999 /* eslint-disable-next-line */
100100 this . setState ( {
101- value : location !== null ? location . name : "" ,
101+ // location could be null if none is set
102+ value : location ?. name || "" ,
102103 geocodedFeatures : [ ]
103104 } ) ;
104105 }
@@ -114,7 +115,8 @@ class LocationField extends Component {
114115 */
115116 getValueFromLocation = ( ) => {
116117 const { hideExistingValue, location } = this . props ;
117- return location && ! hideExistingValue ? location . name : "" ;
118+ const label = location ?. name || "" ;
119+ return location && ! hideExistingValue ? label : "" ;
118120 } ;
119121
120122 setLocation ( location , resultType ) {
@@ -326,11 +328,19 @@ class LocationField extends Component {
326328 operatorIconMap
327329 } = this . props ;
328330 const { activeIndex } = this . state ;
331+
332+ // generate the friendly labels for this feature
333+ const { main, secondary } = generateLabel ( feature . properties ) ;
334+
329335 // Create the selection handler
330336 const locationSelected = ( ) => {
331337 getGeocoder ( geocoderConfig )
332338 . getLocationFromGeocodedFeature ( feature )
333339 . then ( geocodedLocation => {
340+ // add the friendly location labels for use later on
341+ geocodedLocation . main = main ;
342+ geocodedLocation . secondary = secondary ;
343+ geocodedLocation . name = getCombinedLabel ( feature . properties ) ;
334344 // Set the current location
335345 this . setLocation ( geocodedLocation , "GEOCODE" ) ;
336346 // Add to the location search history. This is intended to
@@ -360,7 +370,6 @@ class LocationField extends Component {
360370 classNames . push ( `layer-${ layer } ` ) ;
361371
362372 // Create and return the option menu item
363- const { main, secondary } = generateLabel ( feature . properties ) ;
364373 return (
365374 < Option
366375 classes = { classNames . join ( " " ) }
@@ -539,13 +548,14 @@ class LocationField extends Component {
539548
540549 // Add to the selection handler lookup (for use in onKeyDown)
541550 this . locationSelectedLookup [ itemIndex ] = locationSelected ;
542-
543551 // Create and return the option menu item
544552 const option = (
545553 < Option
546554 icon = { sessionOptionIcon }
547555 key = { optionKey ++ }
548- title = { sessionLocation . name }
556+ // just use the name if there is no main/secondary field
557+ title = { sessionLocation . main || sessionLocation . name }
558+ subTitle = { sessionLocation . secondary || "" }
549559 onClick = { locationSelected }
550560 isActive = { itemIndex === activeIndex }
551561 />
@@ -856,7 +866,9 @@ LocationField.propTypes = {
856866 location : PropTypes . shape ( {
857867 lat : PropTypes . number ,
858868 lon : PropTypes . number ,
859- name : PropTypes . string
869+ name : PropTypes . string ,
870+ main : PropTypes . string ,
871+ secondary : PropTypes . string
860872 } ) ,
861873 /**
862874 * A custom component for rendering the icon displayed to the left of the text
0 commit comments