Skip to content

Commit

Permalink
refactore code and use language param
Browse files Browse the repository at this point in the history
  • Loading branch information
devketanpro committed Oct 13, 2023
1 parent 4fe02a2 commit f492c83
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 13 deletions.
5 changes: 4 additions & 1 deletion client/components/Events/EventItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {renderFields} from '../fields';
import {CreatedUpdatedColumn} from '../UI/List/CreatedUpdatedColumn';
import {EventDateTimeColumn} from './EventDateTimeColumn';
import * as actions from '../../actions';
import {getUserInterfaceLanguageFromCV} from '../../utils/users';

interface IState {
hover: boolean;
Expand Down Expand Up @@ -157,6 +158,7 @@ class EventItemComponent extends React.Component<IProps, IState> {
active,
refNode,
listViewType,
filterLanguage
} = this.props;

if (!item) {
Expand All @@ -178,6 +180,7 @@ class EventItemComponent extends React.Component<IProps, IState> {
const isExpired = isItemExpired(item);

const secondaryFields = get(listFields, 'event.secondary_fields', EVENTS.LIST.SECONDARY_FIELDS);
const language = filterLanguage || item.language || getUserInterfaceLanguageFromCV();

return (
<Item
Expand Down Expand Up @@ -217,7 +220,7 @@ class EventItemComponent extends React.Component<IProps, IState> {
<Row>
<span className="sd-overflow-ellipsis sd-list-item--element-grow">
{renderFields(get(listFields, 'event.primary_fields',
EVENTS.LIST.PRIMARY_FIELDS), item, this.props)}
EVENTS.LIST.PRIMARY_FIELDS), item, {}, language)}
</span>
</Row>
<Row>
Expand Down
5 changes: 4 additions & 1 deletion client/components/Planning/PlanningItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
} from '../../utils';
import {renderFields} from '../fields';
import * as actions from '../../actions';
import {getUserInterfaceLanguageFromCV} from '../../utils/users';

interface IState {
hover: boolean;
Expand Down Expand Up @@ -185,6 +186,7 @@ class PlanningItemComponent extends React.Component<IProps, IState> {
agendas,
contacts,
listViewType,
filterLanguage
} = this.props;

if (!item) {
Expand All @@ -198,6 +200,7 @@ class PlanningItemComponent extends React.Component<IProps, IState> {
const isExpired = isItemExpired(item);
const secondaryFields = get(listFields, 'planning.secondary_fields', PLANNING.LIST.SECONDARY_FIELDS);
const {querySelectorParent} = superdeskApi.utilities;
const language = filterLanguage || item.language || getUserInterfaceLanguageFromCV();

return (
<Item
Expand Down Expand Up @@ -236,7 +239,7 @@ class PlanningItemComponent extends React.Component<IProps, IState> {
<Row>
<span className="sd-overflow-ellipsis sd-list-item--element-grow">
{renderFields(get(listFields, 'planning.primary_fields',
PLANNING.LIST.PRIMARY_FIELDS), item, this.props)}
PLANNING.LIST.PRIMARY_FIELDS), item, {}, language)}
</span>

{event && (
Expand Down
4 changes: 2 additions & 2 deletions client/components/fields/headline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import PropTypes from 'prop-types';
import {getTranslatedValue} from '.';
import {IFieldsProps} from '../../interfaces';

export const headline = ({item, filterLanguage}: IFieldsProps) => getTranslatedValue(
filterLanguage, item, 'headline') || item.headline || null;
export const headline = ({item, language}: IFieldsProps) => getTranslatedValue(
language, item, 'headline') || item.headline || null;

headline.propTypes = {
item: PropTypes.shape({
Expand Down
10 changes: 6 additions & 4 deletions client/components/fields/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {sortBy} from 'lodash';

import {IEventOrPlanningItem, IProfileSchema, IRenderPanelType, ISearchProfile, PREVIEW_PANEL} from '../../interfaces';
import {superdeskApi} from '../../superdeskApi';
import {getUserInterfaceLanguageFromCV} from '../../utils/users';

import {name} from './name';
import {slugline} from './slugline';
Expand Down Expand Up @@ -45,9 +44,12 @@ export function registerField(id, component) {
* @param {Object} item
* @param {Object} props
*/
export function renderFields(fields, item, props = {filterLanguage: ''}) {
const language = getUserInterfaceLanguageFromCV();

export function renderFields(
fields:Array<any>|string,
item:IEventOrPlanningItem,
props:Object = {},
language:string = ""

Check failure on line 51 in client/components/fields/index.tsx

View workflow job for this annotation

GitHub Actions / client (14.x)

Strings must use singlequote
) {
return (Array.isArray(fields) ? fields : [fields]).map((id) => {
const Component = registeredFields[id];

Expand Down
4 changes: 2 additions & 2 deletions client/components/fields/name.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import PropTypes from 'prop-types';
import {getTranslatedValue} from '.';
import {IFieldsProps} from '../../interfaces';

export const name = ({item, filterLanguage}: IFieldsProps) => getTranslatedValue(filterLanguage, item, 'name') ||
export const name = ({item, language}: IFieldsProps) => getTranslatedValue(language, item, 'name') ||
item.name || null;

name.propTypes = {
item: PropTypes.shape({
name: PropTypes.string,
}).isRequired,
filterLanguage: PropTypes.string,
language: PropTypes.string,
};
4 changes: 2 additions & 2 deletions client/components/fields/slugline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import {get} from 'lodash';
import {getTranslatedValue} from '.';
import {IFieldsProps} from '../../interfaces';

export const slugline = ({item, filterLanguage}: IFieldsProps) => {
export const slugline = ({item, language}: IFieldsProps) => {
if (!get(item, 'slugline', '')) {
return null;
}

return (
<span className="sd-list-item__slugline">{getTranslatedValue(filterLanguage, item, 'slugline') ||
<span className="sd-list-item__slugline">{getTranslatedValue(language, item, 'slugline') ||
item.slugline}</span>
);
};
Expand Down
2 changes: 1 addition & 1 deletion client/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ export interface IContentTemplate extends IBaseRestApiResponse {

export interface IFieldsProps {
item: IEventOrPlanningItem;
filterLanguage?: string;
language?: string;
}

interface IMainStateSearch<T> {
Expand Down

0 comments on commit f492c83

Please sign in to comment.