diff --git a/client/components/GeoLookupInput/AddGeoLookupInput.tsx b/client/components/GeoLookupInput/AddGeoLookupInput.tsx index e8f46906b..1ae491ad1 100644 --- a/client/components/GeoLookupInput/AddGeoLookupInput.tsx +++ b/client/components/GeoLookupInput/AddGeoLookupInput.tsx @@ -230,6 +230,7 @@ export class AddGeoLookupInput extends React.Component { qcode: location.guid, address: location.address, details: location.details, + translations: location.translations, }; // external address might not be there. @@ -274,6 +275,7 @@ export class AddGeoLookupInput extends React.Component { {initialValue?.name == null ? null : ( { } handleEnterKey() { + const {localSuggests, suggests} = this.props; + const localSuggestLen = localSuggests?.length ?? 0; + if (this.state.activeOptionIndex > -1) { - if (this.state.activeOptionIndex < get(this.props.localSuggests, 'length', -1)) { - this.props.onChange(this.props.localSuggests[this.state.activeOptionIndex]); + if (this.state.activeOptionIndex < (localSuggests.length ?? -1)) { + this.props.onChange(localSuggests[this.state.activeOptionIndex]); return; } - if (this.state.activeOptionIndex === get(this.props.localSuggests, 'length', 0)) { + if (this.state.activeOptionIndex === localSuggestLen) { this.onSearch(); return; } - if (this.state.activeOptionIndex >= get(this.props.localSuggests, 'length', 0) + 1) { - this.props.onChange(this.props.suggests[ - this.state.activeOptionIndex - (get(this.props.localSuggests, 'length', 0) + 1)]); + if (this.state.activeOptionIndex >= localSuggestLen + 1) { + this.props.onChange(suggests[this.state.activeOptionIndex - localSuggestLen + 1]); } } } @@ -100,8 +102,8 @@ export class AddGeoLookupResultsPopUp extends React.Component { handleDownArrowKey() { if (this.state.activeOptionIndex < (1 + // External search button - get(this.props.localSuggests, 'length', 0) + - get(this.props.suggests, 'length', 0)) - 1 + (this.props.localSuggests?.length ?? 0) + + (this.props.suggests?.length ?? 0)) - 1 ) { this.setState({activeOptionIndex: this.state.activeOptionIndex + 1}); @@ -141,10 +143,8 @@ export class AddGeoLookupResultsPopUp extends React.Component { render() { const {gettext} = superdeskApi.localization; - const localSuggests = get(this.props.localSuggests, 'length') > 0 ? - this.props.localSuggests : []; - const suggests = get(this.props.suggests, 'length') > 0 ? - this.props.suggests : []; + const localSuggests = this.props.localSuggests ?? []; + const suggests = this.props.suggests ?? []; const tabLabels = [( { active={index === this.state.activeOptionIndex} /> ))} - {get(localSuggests, 'length') === 0 && ( + {localSuggests.length === 0 && (
  • {gettext('No results found')}
  • @@ -220,14 +220,12 @@ export class AddGeoLookupResultsPopUp extends React.Component { key={index} location={suggest} onClick={this.props.onChange.bind(null, suggest)} - active={( - index + - get(this.props.localSuggests, 'length', 0) + - 1 - ) === this.state.activeOptionIndex} + active={(index + localSuggests.length + 1) + === this.state.activeOptionIndex + } /> ))} - {get(suggests, 'length') === 0 && ( + {suggests.length === 0 && (
  • {gettext('No results found')}
  • diff --git a/client/components/GeoLookupInput/LocationItem.tsx b/client/components/GeoLookupInput/LocationItem.tsx index b1dda096b..01165d1f4 100644 --- a/client/components/GeoLookupInput/LocationItem.tsx +++ b/client/components/GeoLookupInput/LocationItem.tsx @@ -16,6 +16,7 @@ interface IProps { active?: boolean; readOnly?: boolean; onRemoveLocation?(): void; + languageCode?: string; } export class LocationItem extends React.PureComponent { @@ -23,6 +24,10 @@ export class LocationItem extends React.PureComponent { const {gettext} = superdeskApi.localization; const location = this.props.location; + const locationNameComputed = this.props.languageCode + ? location.translations?.name[`name:${this.props.languageCode}`] ?? location.name + : location.name; + return ( { {(this.props.readOnly || this.props.onRemoveLocation == null) ? null : ( diff --git a/client/components/UI/List/ActionMenu.tsx b/client/components/UI/List/ActionMenu.tsx index 0a171d6bf..e337c6c2b 100644 --- a/client/components/UI/List/ActionMenu.tsx +++ b/client/components/UI/List/ActionMenu.tsx @@ -1,24 +1,24 @@ import React from 'react'; -import PropTypes from 'prop-types'; import classNames from 'classnames'; +interface IProps { + children: React.ReactNode; + row?: boolean; + className?: string; +} /** * @ngdoc react * @name ActionMenu * @description Component to encapsulate three-dot action menu in list a item */ -export const ActionMenu = ({children, row}) => ( +export const ActionMenu = ({children, className, row = true}: IProps) => (
    {children}
    ); - -ActionMenu.propTypes = { - children: PropTypes.node.isRequired, - row: PropTypes.bool, -}; - -ActionMenu.defaultProps = {row: true}; diff --git a/client/components/fields/editor/Location.tsx b/client/components/fields/editor/Location.tsx index 4a6ca1b8a..6761bde71 100644 --- a/client/components/fields/editor/Location.tsx +++ b/client/components/fields/editor/Location.tsx @@ -22,7 +22,7 @@ export class EditorFieldLocation extends React.PureComponent { {...this.props} field={field} label={this.props.label ?? gettext('Location')} - value={get(this.props.item, field, this.props.defaultValue)} + value={this.props.item[field] ?? this.props.defaultValue} disableSearch={!this.props.enableExternalSearch} disableAddLocation={this.props.disableAddLocation} readOnly={this.props.disabled} diff --git a/client/interfaces.ts b/client/interfaces.ts index 07a5e666a..0b1188fd2 100644 --- a/client/interfaces.ts +++ b/client/interfaces.ts @@ -389,6 +389,7 @@ export interface IEventLocation { lat: number; lon: number; }; + translations?: ILocation['translations']; } export interface IItemAction {