Skip to content

Commit

Permalink
Get translated location (superdesk#2065)
Browse files Browse the repository at this point in the history
* Get translated location

* Type improvements
  • Loading branch information
thecalcc authored Aug 22, 2024
1 parent a2698bd commit 9a0e1f2
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 60 deletions.
1 change: 1 addition & 0 deletions client/components/GeoLookupInput/AddGeoLookupInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export class AddGeoLookupInput extends React.Component<IProps, IState> {

{this.state.openSuggestsPopUp && (
<AddGeoLookupResultsPopUp
languageCode={this.props.language}
localSuggests={this.state.localSearchResults}
suggests={this.state.searchResults}
onCancel={this.closeSuggestsPopUp}
Expand Down
2 changes: 2 additions & 0 deletions client/components/GeoLookupInput/AddGeoLookupResultsPopUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface IProps {
onAddNewLocation(): void;
onPopupOpen?(): void;
onPopupClose?(): void;
languageCode?: string;
}

enum TAB_INDEX {
Expand Down Expand Up @@ -194,6 +195,7 @@ export class AddGeoLookupResultsPopUp extends React.Component<IProps, IState> {
<LocationLookupResultItem
key={index}
location={suggest}
languageCode={this.props.languageCode}
onClick={this.props.onChange.bind(null, suggest)}
active={index === this.state.activeOptionIndex}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface IProps {
onClick?(): void;
active?: boolean;
location: Partial<ILocation>;
languageCode?: string;
}

export class LocationLookupResultItem extends React.PureComponent<IProps> {
Expand All @@ -23,7 +24,7 @@ export class LocationLookupResultItem extends React.PureComponent<IProps> {
)}
>
<span className="sd-overflow-ellipsis">
{getLocationsShortName(this.props.location)}
{getLocationsShortName(this.props.location, this.props.languageCode)}
</span>
</li>
);
Expand Down
6 changes: 3 additions & 3 deletions client/components/GeoLookupInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import {AddGeoLookupInput, GeoLookupInputComponent} from './AddGeoLookupInput';
import {AddGeoLookupInput} from './AddGeoLookupInput';

import {LineInput, Label} from '../UI/Form';
import {ILocation} from '../../interfaces';
Expand All @@ -17,14 +17,14 @@ interface IProps {
readOnly?: boolean;
boxed?: boolean;
noMargin?: boolean;
refNode?: React.RefObject<GeoLookupInputComponent>;
refNode?: React.RefObject<any>;
language?: string;
onChange(field: string, value?: Partial<ILocation>): void;
onFocus?(): void;
popupContainer?(): HTMLElement;
onPopupOpen?(): void;
onPopupClose?(): void;
showAddLocationForm(props: any): void;
showAddLocationForm?(props: any): Promise<ILocation | undefined>;
}

export class GeoLookupInput extends React.PureComponent<IProps> {
Expand Down
69 changes: 24 additions & 45 deletions client/components/UI/Form/LineInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,32 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

interface IProps {
required?: boolean;
invalid?: boolean;
readOnly?: boolean;
boxed?: boolean;
isSelect?: boolean;
noMargin?: boolean;
noLabel?: boolean;
withButton?: boolean;
labelLeft?: boolean;
labelLeftAuto?: boolean;
hint?: string;
message?: string;
borderBottom?: boolean;
onClick?: (e: any) => void;
halfWidth?: boolean;
children?: React.ReactNode;
className?: string;
}

/**
* @ngdoc react
* @name LineInput
* @description Component to style input component in a line-input style
*/
export const LineInput = ({
children,
required,
invalid,
readOnly,
Expand All @@ -19,13 +38,14 @@ export const LineInput = ({
withButton,
labelLeft,
labelLeftAuto,
borderBottom = true,
halfWidth,
children,
hint,
message,
className,
borderBottom,
onClick,
halfWidth,
}) => (
}: IProps): JSX.Element => (
<div
className={classNames(
'sd-line-input',
Expand All @@ -52,44 +72,3 @@ export const LineInput = ({
{message && <div className="sd-line-input__message">{message}</div>}
</div>
);

export const LineInputProps = {
required: PropTypes.bool,
invalid: PropTypes.bool,
readOnly: PropTypes.bool,
boxed: PropTypes.bool,
isSelect: PropTypes.bool,
noMargin: PropTypes.bool,
noLabel: PropTypes.bool,
withButton: PropTypes.bool,
labelLeft: PropTypes.bool,
labelLeftAuto: PropTypes.bool,
hint: PropTypes.string,
message: PropTypes.string,
borderBottom: PropTypes.bool,
onClick: PropTypes.func,
halfWidth: PropTypes.bool,
};

export const LineInputDefaultProps = {
required: false,
invalid: false,
readOnly: false,
boxed: false,
isSelect: false,
noMargin: false,
noLabel: false,
withButton: false,
labelLeft: false,
labelLeftAuto: false,
borderBottom: true,
halfWidth: false,
};

LineInput.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
...LineInputProps,
};

LineInput.defaultProps = {...LineInputDefaultProps};
15 changes: 6 additions & 9 deletions client/components/UI/Popup/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

interface IProps {
children?: React.ReactNode;
className?: string;
noPadding?: boolean;
}
/**
* @ngdoc react
* @name Content
* @description Component to hold contents of a popup
*/
const Content = ({children, className, noPadding}) => (
const Content = ({children, className, noPadding}: IProps) => (
<div
className={classNames(
'popup__menu-content',
Expand All @@ -19,12 +24,4 @@ const Content = ({children, className, noPadding}) => (
</div>
);

Content.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
noPadding: PropTypes.bool,
};

Content.defaultProps = {noPadding: false};

export default Content;
4 changes: 2 additions & 2 deletions client/utils/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ export function formatLocationToAddress(item: Partial<ILocation> | IEventLocatio
formattedAddress;
}

export function getLocationsShortName(location: Partial<ILocation>) {
export function getLocationsShortName(location: Partial<ILocation>, languageCode?: string) {
const formattedAddress = formatLocationToAddress(location);
const title = location.address?.title ?? location.name;
const title = location.translations?.name?.[`name:${languageCode}`] ?? location.address?.title ?? location.name;

return title ?
`${title}, ${formattedAddress}` :
Expand Down

0 comments on commit 9a0e1f2

Please sign in to comment.