Skip to content
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

Store location translations, render location name for selected language #2067

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 7 additions & 2 deletions client/components/GeoLookupInput/LocationItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@ import {Button} from '../UI';
import {Location} from '../Location';

import {onEventCapture} from '../../utils';
import {formatLocationToAddress} from '../../utils/locations';
import {formatLocationToAddress, getLocationsShortName} from '../../utils/locations';

interface IProps {
location?: ILocation | IEventLocation;
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,7 +38,7 @@ 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]')}
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
Loading