Skip to content

Commit

Permalink
Store location translations, render location name for selected langua…
Browse files Browse the repository at this point in the history
…ge (#2067)
  • Loading branch information
thecalcc authored Aug 23, 2024
1 parent 9a0e1f2 commit 38baeab
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 33 deletions.
2 changes: 2 additions & 0 deletions client/components/GeoLookupInput/AddGeoLookupInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export class AddGeoLookupInput extends React.Component<IProps, IState> {
qcode: location.guid,
address: location.address,
details: location.details,
translations: location.translations,
};

// external address might not be there.
Expand Down Expand Up @@ -274,6 +275,7 @@ export class AddGeoLookupInput extends React.Component<IProps, IState> {
<React.Fragment>
{initialValue?.name == null ? null : (
<LocationItem
languageCode={this.props.language}
location={initialValue}
onRemoveLocation={this.removeLocation}
readOnly={readOnly}
Expand Down
36 changes: 17 additions & 19 deletions client/components/GeoLookupInput/AddGeoLookupResultsPopUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,31 @@ export class AddGeoLookupResultsPopUp extends React.Component<IProps, IState> {
}

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]);
}
}
}

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});

Expand Down Expand Up @@ -141,10 +143,8 @@ export class AddGeoLookupResultsPopUp extends React.Component<IProps, IState> {

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 = [(
<TabLabel
key="internal"
Expand Down Expand Up @@ -200,7 +200,7 @@ export class AddGeoLookupResultsPopUp extends React.Component<IProps, IState> {
active={index === this.state.activeOptionIndex}
/>
))}
{get(localSuggests, 'length') === 0 && (
{localSuggests.length === 0 && (
<li className="addgeolookup__item">
{gettext('No results found')}
</li>
Expand All @@ -220,14 +220,12 @@ export class AddGeoLookupResultsPopUp extends React.Component<IProps, IState> {
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 && (
<li className="addgeolookup__item">
{gettext('No results found')}
</li>
Expand Down
9 changes: 7 additions & 2 deletions client/components/GeoLookupInput/LocationItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ interface IProps {
active?: boolean;
readOnly?: boolean;
onRemoveLocation?(): void;
languageCode?: string;
}

export class LocationItem extends React.PureComponent<IProps> {
render() {
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 (
<Item
noBg={!this.props.active}
Expand All @@ -33,10 +38,10 @@ export class LocationItem extends React.PureComponent<IProps> {
<Column grow={true} border={false}>
<Row paddingBottom>
<Location
name={this.props.location.name}
name={locationNameComputed}
address={formatLocationToAddress(this.props.location)}
multiLine={true}
details={get(location, 'details[0]')}
details={location.details?.[0]}
/>
<ActionMenu className="pull-right">
{(this.props.readOnly || this.props.onRemoveLocation == null) ? null : (
Expand Down
22 changes: 11 additions & 11 deletions client/components/UI/List/ActionMenu.tsx
Original file line number Diff line number Diff line change
@@ -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) => (
<div
className={classNames('sd-list-item__action-menu',
{'sd-list-item__action-menu--direction-row': row})}
className={classNames(
'sd-list-item__action-menu',
{'sd-list-item__action-menu--direction-row': row},
className,
)}
>
{children}
</div>
);

ActionMenu.propTypes = {
children: PropTypes.node.isRequired,
row: PropTypes.bool,
};

ActionMenu.defaultProps = {row: true};
2 changes: 1 addition & 1 deletion client/components/fields/editor/Location.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class EditorFieldLocation extends React.PureComponent<IProps> {
{...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}
Expand Down
1 change: 1 addition & 0 deletions client/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ export interface IEventLocation {
lat: number;
lon: number;
};
translations?: ILocation['translations'];
}

export interface IItemAction {
Expand Down

0 comments on commit 38baeab

Please sign in to comment.