From 779a46576b7cc45ca3f42d7e35af3fb020c9dfe9 Mon Sep 17 00:00:00 2001 From: devketanpro Date: Thu, 12 Oct 2023 11:34:36 +0530 Subject: [PATCH 1/9] Planning: If multilingual Events or Planning items are filtered by language - show them in this language in the list views [SDESK-7060] --- client/components/Events/EventItem.tsx | 5 +++-- client/components/Main/ListGroupItem.tsx | 17 ++++++++++++++--- client/components/Planning/PlanningItem.tsx | 5 +++-- client/components/fields/headline.tsx | 5 ++++- client/components/fields/index.tsx | 19 ++++++++++++++++++- client/components/fields/name.tsx | 4 +++- client/components/fields/slugline.tsx | 9 +++++++-- client/interfaces.ts | 2 ++ 8 files changed, 54 insertions(+), 12 deletions(-) diff --git a/client/components/Events/EventItem.tsx b/client/components/Events/EventItem.tsx index d338bc4de..7371a3c13 100644 --- a/client/components/Events/EventItem.tsx +++ b/client/components/Events/EventItem.tsx @@ -44,7 +44,8 @@ class EventItemComponent extends React.Component { return isItemDifferent(this.props, nextProps) || this.state.hover !== nextState.hover || this.props.minTimeWidth !== nextProps.minTimeWidth || - this.props.lockedItems != nextProps.lockedItems; + this.props.lockedItems != nextProps.lockedItems || + this.props.filterLanguage !== nextProps.filterLanguage; } onItemHoverOn() { @@ -216,7 +217,7 @@ class EventItemComponent extends React.Component { {renderFields(get(listFields, 'event.primary_fields', - EVENTS.LIST.PRIMARY_FIELDS), item)} + EVENTS.LIST.PRIMARY_FIELDS), item, this.props)} diff --git a/client/components/Main/ListGroupItem.tsx b/client/components/Main/ListGroupItem.tsx index 821d628c9..fd1956f88 100644 --- a/client/components/Main/ListGroupItem.tsx +++ b/client/components/Main/ListGroupItem.tsx @@ -1,11 +1,11 @@ import React from 'react'; import {debounce, indexOf} from 'lodash'; - +import {connect} from 'react-redux'; import { IEventListItemProps, IPlanningListItemProps, IEventOrPlanningItem, - IEventItem, IPlanningItem, IBaseListItemProps + IEventItem, IPlanningItem, IBaseListItemProps, ISearchAPIParams } from '../../interfaces'; import {EventItem, EventItemWithPlanning} from '../Events'; @@ -13,6 +13,7 @@ import {PlanningItem} from '../Planning'; import {ITEM_TYPE, EVENTS, PLANNING, MAIN, CLICK_DELAY} from '../../constants'; import {getItemType, eventUtils} from '../../utils'; +import {currentSearchParams} from '../../selectors/search'; interface IProps extends Omit< IEventListItemProps & IPlanningListItemProps, @@ -33,13 +34,18 @@ interface IProps extends Omit< navigateList(increment?: boolean): void; onItemActivate(item: IEventItem, forceActivate?: boolean): void; onItemClick(index: number, item: IEventOrPlanningItem): void; + currentParams:ISearchAPIParams } interface IState { clickedOnce?: boolean; } -export class ListGroupItem extends React.Component { +const mapStateToProps = (state) => ({ + currentParams: currentSearchParams(state), +}); + +class ListGroupComponent extends React.Component { dom: {item: HTMLElement}; _delayedClick: any | undefined; @@ -122,6 +128,7 @@ export class ListGroupItem extends React.Component { listViewType, sortField, minTimeWidth, + currentParams } = this.props; const itemType = getItemType(item); @@ -151,6 +158,7 @@ export class ListGroupItem extends React.Component { ...itemProps, item: item as IEventItem, calendars: calendars, + filterLanguage: currentParams?.language, multiSelected: indexOf(selectedEventIds, item._id) !== -1, [EVENTS.ITEM_ACTIONS.EDIT_EVENT.actionName]: itemActions[EVENTS.ITEM_ACTIONS.EDIT_EVENT.actionName], @@ -193,6 +201,7 @@ export class ListGroupItem extends React.Component { contentTypes: contentTypes, agendas: agendas, date: date, + filterLanguage: currentParams?.language, onAddCoverageClick: onAddCoverageClick, multiSelected: indexOf(selectedPlanningIds, item._id) !== -1, showAddCoverage: showAddCoverage, @@ -265,3 +274,5 @@ export class ListGroupItem extends React.Component { return null; } } + +export const ListGroupItem = connect(mapStateToProps)(ListGroupComponent); \ No newline at end of file diff --git a/client/components/Planning/PlanningItem.tsx b/client/components/Planning/PlanningItem.tsx index 1f78be4be..cb34c22e0 100644 --- a/client/components/Planning/PlanningItem.tsx +++ b/client/components/Planning/PlanningItem.tsx @@ -64,7 +64,8 @@ class PlanningItemComponent extends React.Component { planningUtils.getAgendaNames(this.props.item, this.props.agendas), planningUtils.getAgendaNames(nextProps.item, nextProps.agendas) ) || - this.props.minTimeWidth !== nextProps.minTimeWidth; + this.props.minTimeWidth !== nextProps.minTimeWidth || + this.props.filterLanguage !== nextProps.filterLanguage; } onItemHoverOn() { @@ -235,7 +236,7 @@ class PlanningItemComponent extends React.Component { {renderFields(get(listFields, 'planning.primary_fields', - PLANNING.LIST.PRIMARY_FIELDS), item)} + PLANNING.LIST.PRIMARY_FIELDS), item, this.props)} {event && ( diff --git a/client/components/fields/headline.tsx b/client/components/fields/headline.tsx index 248f1d716..2b80db1f3 100644 --- a/client/components/fields/headline.tsx +++ b/client/components/fields/headline.tsx @@ -1,9 +1,12 @@ import PropTypes from 'prop-types'; +import {getTranslatedValue} from '.'; -export const headline = ({item}) => item.headline || null; +export const headline = ({item, filterLanguage}) => getTranslatedValue(filterLanguage, item, 'headline') || +item.headline || null; headline.propTypes = { item: PropTypes.shape({ headline: PropTypes.string, }).isRequired, + filterLanguage: PropTypes.string, }; \ No newline at end of file diff --git a/client/components/fields/index.tsx b/client/components/fields/index.tsx index 96fdbd8ab..f97cc5ae5 100644 --- a/client/components/fields/index.tsx +++ b/client/components/fields/index.tsx @@ -45,7 +45,7 @@ export function registerField(id, component) { * @param {Object} item * @param {Object} props */ -export function renderFields(fields, item, props = {}) { +export function renderFields(fields, item, props = {filterLanguage: ''}) { const language = getUserInterfaceLanguageFromCV(); return (Array.isArray(fields) ? fields : [fields]).map((id) => { @@ -66,6 +66,23 @@ export function renderFields(fields, item, props = {}) { }); } +/** + * Get translated field value based on languagei + * @param {String} language + * @param {Object} item + * @param {String} fieldName + */ +export function getTranslatedValue(language, item, fieldName) { + if (item.translations) { + const matchingTranslation = item.translations.find( + (translation) => translation.field === fieldName && translation.language === language + ); + + return matchingTranslation ? matchingTranslation.value : null; + } + return null; +} + function getFieldsForPanel(panelType: IRenderPanelType) { switch (panelType) { case 'editor': diff --git a/client/components/fields/name.tsx b/client/components/fields/name.tsx index cbd92e50b..7e4161ba8 100644 --- a/client/components/fields/name.tsx +++ b/client/components/fields/name.tsx @@ -1,9 +1,11 @@ import PropTypes from 'prop-types'; +import {getTranslatedValue} from '.'; -export const name = ({item}) => item.name || null; +export const name = ({item, filterLanguage}) => getTranslatedValue(filterLanguage, item, 'name') || item.name || null; name.propTypes = { item: PropTypes.shape({ name: PropTypes.string, }).isRequired, + filterLanguage: PropTypes.string, }; \ No newline at end of file diff --git a/client/components/fields/slugline.tsx b/client/components/fields/slugline.tsx index afb63a53a..14563dc53 100644 --- a/client/components/fields/slugline.tsx +++ b/client/components/fields/slugline.tsx @@ -2,17 +2,22 @@ import React from 'react'; import PropTypes from 'prop-types'; import {get} from 'lodash'; +import {getTranslatedValue} from '.'; -export const slugline = ({item}) => { +export const slugline = ({item, filterLanguage}) => { if (!get(item, 'slugline', '')) { return null; } - return ({item.slugline}); + return ( + {getTranslatedValue(filterLanguage, item, 'slugline') || + item.slugline} + ); }; slugline.propTypes = { item: PropTypes.shape({ slugline: PropTypes.string, }).isRequired, + filterLanguage: PropTypes.string, }; diff --git a/client/interfaces.ts b/client/interfaces.ts index d07679a52..96c544046 100644 --- a/client/interfaces.ts +++ b/client/interfaces.ts @@ -855,6 +855,7 @@ export interface IBaseListItemProps { export interface IEventListItemProps extends IBaseListItemProps { relatedPlanningText?: string; calendars: Array; + filterLanguage?: string; toggleRelatedPlanning?(event: React.MouseEvent): void; } @@ -863,6 +864,7 @@ export interface IPlanningListItemProps extends IBaseListItemProps; users: Array; desks: Array; + filterLanguage?: string; // showUnlock?: boolean; // Is this used anymore? hideItemActions: boolean; showAddCoverage: boolean; From a23cddd219a2cebcbddff2581cbbfc7e00a0680a Mon Sep 17 00:00:00 2001 From: devketanpro Date: Thu, 12 Oct 2023 16:07:36 +0530 Subject: [PATCH 2/9] add typescript types --- client/components/fields/headline.tsx | 5 +++-- client/components/fields/index.tsx | 8 ++++---- client/components/fields/name.tsx | 4 +++- client/components/fields/slugline.tsx | 3 ++- client/interfaces.ts | 5 +++++ 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/client/components/fields/headline.tsx b/client/components/fields/headline.tsx index 2b80db1f3..31907dc9f 100644 --- a/client/components/fields/headline.tsx +++ b/client/components/fields/headline.tsx @@ -1,8 +1,9 @@ import PropTypes from 'prop-types'; import {getTranslatedValue} from '.'; +import {IFieldsProps} from '../../interfaces'; -export const headline = ({item, filterLanguage}) => getTranslatedValue(filterLanguage, item, 'headline') || -item.headline || null; +export const headline = ({item, filterLanguage}: IFieldsProps) => getTranslatedValue( + filterLanguage, item, 'headline') || item.headline || null; headline.propTypes = { item: PropTypes.shape({ diff --git a/client/components/fields/index.tsx b/client/components/fields/index.tsx index f97cc5ae5..334205e76 100644 --- a/client/components/fields/index.tsx +++ b/client/components/fields/index.tsx @@ -1,7 +1,7 @@ import React from 'react'; import {sortBy} from 'lodash'; -import {IProfileSchema, IRenderPanelType, ISearchProfile, PREVIEW_PANEL} from '../../interfaces'; +import {IEventOrPlanningItem, IProfileSchema, IRenderPanelType, ISearchProfile, PREVIEW_PANEL} from '../../interfaces'; import {superdeskApi} from '../../superdeskApi'; import {getUserInterfaceLanguageFromCV} from '../../utils/users'; @@ -67,12 +67,12 @@ export function renderFields(fields, item, props = {filterLanguage: ''}) { } /** - * Get translated field value based on languagei + * Get translated field value based on language * @param {String} language - * @param {Object} item + * @param {IEventOrPlanningItem} item * @param {String} fieldName */ -export function getTranslatedValue(language, item, fieldName) { +export function getTranslatedValue(language: string, item: IEventOrPlanningItem, fieldName: string): string | null { if (item.translations) { const matchingTranslation = item.translations.find( (translation) => translation.field === fieldName && translation.language === language diff --git a/client/components/fields/name.tsx b/client/components/fields/name.tsx index 7e4161ba8..f4cc66d3b 100644 --- a/client/components/fields/name.tsx +++ b/client/components/fields/name.tsx @@ -1,7 +1,9 @@ import PropTypes from 'prop-types'; import {getTranslatedValue} from '.'; +import {IFieldsProps} from '../../interfaces'; -export const name = ({item, filterLanguage}) => getTranslatedValue(filterLanguage, item, 'name') || item.name || null; +export const name = ({item, filterLanguage}: IFieldsProps) => getTranslatedValue(filterLanguage, item, 'name') || +item.name || null; name.propTypes = { item: PropTypes.shape({ diff --git a/client/components/fields/slugline.tsx b/client/components/fields/slugline.tsx index 14563dc53..5e5bb3317 100644 --- a/client/components/fields/slugline.tsx +++ b/client/components/fields/slugline.tsx @@ -3,8 +3,9 @@ import PropTypes from 'prop-types'; import {get} from 'lodash'; import {getTranslatedValue} from '.'; +import {IFieldsProps} from '../../interfaces'; -export const slugline = ({item, filterLanguage}) => { +export const slugline = ({item, filterLanguage}: IFieldsProps) => { if (!get(item, 'slugline', '')) { return null; } diff --git a/client/interfaces.ts b/client/interfaces.ts index 96c544046..ce6be1e1f 100644 --- a/client/interfaces.ts +++ b/client/interfaces.ts @@ -1581,6 +1581,11 @@ export interface IContentTemplate extends IBaseRestApiResponse { }; } +export interface IFieldsProps { + item: IEventOrPlanningItem; + filterLanguage?: string; +} + interface IMainStateSearch { lastRequestParams: T; fulltext?: string; From d96e09a92128c08cedced0e3078b367bd195cbc3 Mon Sep 17 00:00:00 2001 From: devketanpro Date: Thu, 12 Oct 2023 17:07:05 +0530 Subject: [PATCH 3/9] add the param to a higher up component --- client/apps/Planning/PlanningList.tsx | 5 +++++ client/components/Main/ListGroup.tsx | 5 ++++- client/components/Main/ListGroupItem.tsx | 18 ++++++------------ client/components/Main/ListPanel.tsx | 5 ++++- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/client/apps/Planning/PlanningList.tsx b/client/apps/Planning/PlanningList.tsx index 22af04c36..ea3530982 100644 --- a/client/apps/Planning/PlanningList.tsx +++ b/client/apps/Planning/PlanningList.tsx @@ -16,6 +16,7 @@ import { LIST_VIEW_TYPE, IContactItem, SORT_FIELD, + ICommonSearchParams, } from '../../interfaces'; import * as actions from '../../actions'; @@ -59,6 +60,7 @@ interface IProps { contacts: {[key: string]: IContactItem}; listViewType: LIST_VIEW_TYPE; sortField: SORT_FIELD; + currentSearch: ICommonSearchParams; openPreview(item: IEventOrPlanningItem): void; edit(item: IEventOrPlanningItem): void; @@ -92,6 +94,7 @@ const mapStateToProps = (state) => ({ contacts: selectors.general.contactsById(state), listViewType: selectors.main.getCurrentListViewType(state), sortField: selectors.main.getCurrentSortField(state), + currentSearch: selectors.main.currentSearch(state) }); const mapDispatchToProps = (dispatch) => ({ @@ -168,6 +171,7 @@ export class PlanningListComponent extends React.PureComponent { contacts, listViewType, sortField, + currentSearch } = this.props; return ( @@ -206,6 +210,7 @@ export class PlanningListComponent extends React.PureComponent { listViewType={listViewType} sortField={sortField} indexItems + searchParams= {currentSearch.advancedSearch} /> ); diff --git a/client/components/Main/ListGroup.tsx b/client/components/Main/ListGroup.tsx index 82e469aa6..d3cbac9df 100644 --- a/client/components/Main/ListGroup.tsx +++ b/client/components/Main/ListGroup.tsx @@ -2,7 +2,7 @@ import React from 'react'; import moment from 'moment-timezone'; import {ListGroupItem} from './'; import {Group, Header} from '../UI/List'; -import {IEventOrPlanningItem, LIST_VIEW_TYPE, SORT_FIELD} from '../../interfaces'; +import {ICommonAdvancedSearchParams, IEventOrPlanningItem, LIST_VIEW_TYPE, SORT_FIELD} from '../../interfaces'; import {timeUtils} from '../../utils'; const TIME_COLUMN_MIN_WIDTH = { @@ -78,6 +78,7 @@ interface IProps { listViewType?: string; sortField?: string; listBoxGroupProps: {}; + searchParams:ICommonAdvancedSearchParams; } export class ListGroup extends React.Component { @@ -145,6 +146,7 @@ export class ListGroup extends React.Component { listViewType, sortField, listBoxGroupProps, + searchParams, } = this.props; // with defaults @@ -205,6 +207,7 @@ export class ListGroup extends React.Component { listViewType: listViewType, sortField: sortField, minTimeWidth: minTimeWidth, + searchParams: searchParams, }; if (indexItems) { diff --git a/client/components/Main/ListGroupItem.tsx b/client/components/Main/ListGroupItem.tsx index fd1956f88..8002cbddc 100644 --- a/client/components/Main/ListGroupItem.tsx +++ b/client/components/Main/ListGroupItem.tsx @@ -5,7 +5,7 @@ import { IEventListItemProps, IPlanningListItemProps, IEventOrPlanningItem, - IEventItem, IPlanningItem, IBaseListItemProps, ISearchAPIParams + IEventItem, IPlanningItem, IBaseListItemProps, ISearchAPIParams, ICommonAdvancedSearchParams } from '../../interfaces'; import {EventItem, EventItemWithPlanning} from '../Events'; @@ -28,24 +28,20 @@ interface IProps extends Omit< index: number; navigateDown?: boolean; minTimeWidth?: string; + searchParams?: ICommonAdvancedSearchParams; onDoubleClick(item: IEventOrPlanningItem): void; showRelatedPlannings(item: IEventItem): void; navigateList(increment?: boolean): void; onItemActivate(item: IEventItem, forceActivate?: boolean): void; onItemClick(index: number, item: IEventOrPlanningItem): void; - currentParams:ISearchAPIParams } interface IState { clickedOnce?: boolean; } -const mapStateToProps = (state) => ({ - currentParams: currentSearchParams(state), -}); - -class ListGroupComponent extends React.Component { +export class ListGroupItem extends React.Component { dom: {item: HTMLElement}; _delayedClick: any | undefined; @@ -128,7 +124,7 @@ class ListGroupComponent extends React.Component { listViewType, sortField, minTimeWidth, - currentParams + searchParams, } = this.props; const itemType = getItemType(item); @@ -158,7 +154,7 @@ class ListGroupComponent extends React.Component { ...itemProps, item: item as IEventItem, calendars: calendars, - filterLanguage: currentParams?.language, + filterLanguage: searchParams?.language, multiSelected: indexOf(selectedEventIds, item._id) !== -1, [EVENTS.ITEM_ACTIONS.EDIT_EVENT.actionName]: itemActions[EVENTS.ITEM_ACTIONS.EDIT_EVENT.actionName], @@ -201,7 +197,7 @@ class ListGroupComponent extends React.Component { contentTypes: contentTypes, agendas: agendas, date: date, - filterLanguage: currentParams?.language, + filterLanguage: searchParams?.language, onAddCoverageClick: onAddCoverageClick, multiSelected: indexOf(selectedPlanningIds, item._id) !== -1, showAddCoverage: showAddCoverage, @@ -274,5 +270,3 @@ class ListGroupComponent extends React.Component { return null; } } - -export const ListGroupItem = connect(mapStateToProps)(ListGroupComponent); \ No newline at end of file diff --git a/client/components/Main/ListPanel.tsx b/client/components/Main/ListPanel.tsx index 590d95408..4b503e73e 100644 --- a/client/components/Main/ListPanel.tsx +++ b/client/components/Main/ListPanel.tsx @@ -5,7 +5,7 @@ import {superdeskApi} from '../../superdeskApi'; import {IDesk, IUser} from 'superdesk-api'; import { FILTER_TYPE, - IAgenda, ICalendar, IContactItem, + IAgenda, ICalendar, ICommonAdvancedSearchParams, IContactItem, IEventItem, IEventOrPlanningItem, IG2ContentType, ILockedItems, @@ -68,6 +68,7 @@ interface IProps { listViewType: LIST_VIEW_TYPE; sortField: SORT_FIELD; userInitiatedSearch?: boolean; + searchParams?: ICommonAdvancedSearchParams onItemClick(item: IEventOrPlanningItem): void; onDoubleClick(item: IEventOrPlanningItem): void; @@ -318,6 +319,7 @@ export class ListPanel extends React.Component { contacts, listViewType, sortField, + searchParams } = this.props; let indexFrom = 0; @@ -396,6 +398,7 @@ export class ListPanel extends React.Component { listViewType: listViewType, sortField: sortField, listBoxGroupProps: listBoxGroupProps, + searchParams: searchParams, ...propsForNestedListItems, }; From 65d43baa62ce395d63feb4496bd39622f596a8db Mon Sep 17 00:00:00 2001 From: devketanpro Date: Thu, 12 Oct 2023 17:10:58 +0530 Subject: [PATCH 4/9] remove unwanted code --- client/components/Main/ListGroupItem.tsx | 4 +--- client/components/fields/headline.tsx | 2 +- client/components/fields/name.tsx | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/client/components/Main/ListGroupItem.tsx b/client/components/Main/ListGroupItem.tsx index 8002cbddc..5290de171 100644 --- a/client/components/Main/ListGroupItem.tsx +++ b/client/components/Main/ListGroupItem.tsx @@ -1,11 +1,10 @@ import React from 'react'; import {debounce, indexOf} from 'lodash'; -import {connect} from 'react-redux'; import { IEventListItemProps, IPlanningListItemProps, IEventOrPlanningItem, - IEventItem, IPlanningItem, IBaseListItemProps, ISearchAPIParams, ICommonAdvancedSearchParams + IEventItem, IPlanningItem, IBaseListItemProps, ICommonAdvancedSearchParams } from '../../interfaces'; import {EventItem, EventItemWithPlanning} from '../Events'; @@ -13,7 +12,6 @@ import {PlanningItem} from '../Planning'; import {ITEM_TYPE, EVENTS, PLANNING, MAIN, CLICK_DELAY} from '../../constants'; import {getItemType, eventUtils} from '../../utils'; -import {currentSearchParams} from '../../selectors/search'; interface IProps extends Omit< IEventListItemProps & IPlanningListItemProps, diff --git a/client/components/fields/headline.tsx b/client/components/fields/headline.tsx index 31907dc9f..909b8e076 100644 --- a/client/components/fields/headline.tsx +++ b/client/components/fields/headline.tsx @@ -10,4 +10,4 @@ headline.propTypes = { headline: PropTypes.string, }).isRequired, filterLanguage: PropTypes.string, -}; \ No newline at end of file +}; diff --git a/client/components/fields/name.tsx b/client/components/fields/name.tsx index f4cc66d3b..f29299164 100644 --- a/client/components/fields/name.tsx +++ b/client/components/fields/name.tsx @@ -10,4 +10,4 @@ name.propTypes = { name: PropTypes.string, }).isRequired, filterLanguage: PropTypes.string, -}; \ No newline at end of file +}; From 4fe02a289764576dd0104e5061cfcf07b5504e91 Mon Sep 17 00:00:00 2001 From: devketanpro Date: Fri, 13 Oct 2023 13:05:12 +0530 Subject: [PATCH 5/9] remove unwanted space --- client/apps/Planning/PlanningList.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/apps/Planning/PlanningList.tsx b/client/apps/Planning/PlanningList.tsx index ea3530982..2a77ac744 100644 --- a/client/apps/Planning/PlanningList.tsx +++ b/client/apps/Planning/PlanningList.tsx @@ -210,7 +210,7 @@ export class PlanningListComponent extends React.PureComponent { listViewType={listViewType} sortField={sortField} indexItems - searchParams= {currentSearch.advancedSearch} + searchParams={currentSearch.advancedSearch} /> ); From f492c8355e8d68616941914c4a1d547661309c60 Mon Sep 17 00:00:00 2001 From: devketanpro Date: Fri, 13 Oct 2023 16:31:43 +0530 Subject: [PATCH 6/9] refactore code and use language param --- client/components/Events/EventItem.tsx | 5 ++++- client/components/Planning/PlanningItem.tsx | 5 ++++- client/components/fields/headline.tsx | 4 ++-- client/components/fields/index.tsx | 10 ++++++---- client/components/fields/name.tsx | 4 ++-- client/components/fields/slugline.tsx | 4 ++-- client/interfaces.ts | 2 +- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/client/components/Events/EventItem.tsx b/client/components/Events/EventItem.tsx index 7371a3c13..f61570239 100644 --- a/client/components/Events/EventItem.tsx +++ b/client/components/Events/EventItem.tsx @@ -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; @@ -157,6 +158,7 @@ class EventItemComponent extends React.Component { active, refNode, listViewType, + filterLanguage } = this.props; if (!item) { @@ -178,6 +180,7 @@ class EventItemComponent extends React.Component { const isExpired = isItemExpired(item); const secondaryFields = get(listFields, 'event.secondary_fields', EVENTS.LIST.SECONDARY_FIELDS); + const language = filterLanguage || item.language || getUserInterfaceLanguageFromCV(); return ( { {renderFields(get(listFields, 'event.primary_fields', - EVENTS.LIST.PRIMARY_FIELDS), item, this.props)} + EVENTS.LIST.PRIMARY_FIELDS), item, {}, language)} diff --git a/client/components/Planning/PlanningItem.tsx b/client/components/Planning/PlanningItem.tsx index cb34c22e0..b651f19e3 100644 --- a/client/components/Planning/PlanningItem.tsx +++ b/client/components/Planning/PlanningItem.tsx @@ -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; @@ -185,6 +186,7 @@ class PlanningItemComponent extends React.Component { agendas, contacts, listViewType, + filterLanguage } = this.props; if (!item) { @@ -198,6 +200,7 @@ class PlanningItemComponent extends React.Component { 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 ( { {renderFields(get(listFields, 'planning.primary_fields', - PLANNING.LIST.PRIMARY_FIELDS), item, this.props)} + PLANNING.LIST.PRIMARY_FIELDS), item, {}, language)} {event && ( diff --git a/client/components/fields/headline.tsx b/client/components/fields/headline.tsx index 909b8e076..cd341cb19 100644 --- a/client/components/fields/headline.tsx +++ b/client/components/fields/headline.tsx @@ -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({ diff --git a/client/components/fields/index.tsx b/client/components/fields/index.tsx index 334205e76..09bdca993 100644 --- a/client/components/fields/index.tsx +++ b/client/components/fields/index.tsx @@ -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'; @@ -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|string, + item:IEventOrPlanningItem, + props:Object = {}, + language:string = "" +) { return (Array.isArray(fields) ? fields : [fields]).map((id) => { const Component = registeredFields[id]; diff --git a/client/components/fields/name.tsx b/client/components/fields/name.tsx index f29299164..b99753214 100644 --- a/client/components/fields/name.tsx +++ b/client/components/fields/name.tsx @@ -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, }; diff --git a/client/components/fields/slugline.tsx b/client/components/fields/slugline.tsx index 5e5bb3317..6e9ab5b16 100644 --- a/client/components/fields/slugline.tsx +++ b/client/components/fields/slugline.tsx @@ -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 ( - {getTranslatedValue(filterLanguage, item, 'slugline') || + {getTranslatedValue(language, item, 'slugline') || item.slugline} ); }; diff --git a/client/interfaces.ts b/client/interfaces.ts index ce6be1e1f..13d159f3f 100644 --- a/client/interfaces.ts +++ b/client/interfaces.ts @@ -1583,7 +1583,7 @@ export interface IContentTemplate extends IBaseRestApiResponse { export interface IFieldsProps { item: IEventOrPlanningItem; - filterLanguage?: string; + language?: string; } interface IMainStateSearch { From 77fbca4d099b3388aeed84c4dc328e9e65e4da25 Mon Sep 17 00:00:00 2001 From: devketanpro Date: Fri, 13 Oct 2023 16:34:15 +0530 Subject: [PATCH 7/9] minor change --- client/components/fields/headline.tsx | 2 +- client/components/fields/slugline.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/components/fields/headline.tsx b/client/components/fields/headline.tsx index cd341cb19..637fe9a11 100644 --- a/client/components/fields/headline.tsx +++ b/client/components/fields/headline.tsx @@ -9,5 +9,5 @@ headline.propTypes = { item: PropTypes.shape({ headline: PropTypes.string, }).isRequired, - filterLanguage: PropTypes.string, + language: PropTypes.string, }; diff --git a/client/components/fields/slugline.tsx b/client/components/fields/slugline.tsx index 6e9ab5b16..183a2e205 100644 --- a/client/components/fields/slugline.tsx +++ b/client/components/fields/slugline.tsx @@ -20,5 +20,5 @@ slugline.propTypes = { item: PropTypes.shape({ slugline: PropTypes.string, }).isRequired, - filterLanguage: PropTypes.string, + language: PropTypes.string, }; From 72695f3d128f93434f9f28bd0ee2c998556bc295 Mon Sep 17 00:00:00 2001 From: devketanpro Date: Fri, 13 Oct 2023 16:36:17 +0530 Subject: [PATCH 8/9] fix test --- client/components/fields/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/components/fields/index.tsx b/client/components/fields/index.tsx index 09bdca993..d9f7f808d 100644 --- a/client/components/fields/index.tsx +++ b/client/components/fields/index.tsx @@ -41,14 +41,14 @@ export function registerField(id, component) { /** * Render list of fields for given item * @param {Array|String} fields - * @param {Object} item + * @param {IEventOrPlanningItem} item * @param {Object} props */ export function renderFields( fields:Array|string, item:IEventOrPlanningItem, props:Object = {}, - language:string = "" + language:string = '' ) { return (Array.isArray(fields) ? fields : [fields]).map((id) => { const Component = registeredFields[id]; From f31fdf3c2cb8d1afa9c612eb360fcddb30fe013c Mon Sep 17 00:00:00 2001 From: devketanpro Date: Fri, 13 Oct 2023 17:51:07 +0530 Subject: [PATCH 9/9] add white space --- client/components/fields/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/components/fields/index.tsx b/client/components/fields/index.tsx index d9f7f808d..342a7c811 100644 --- a/client/components/fields/index.tsx +++ b/client/components/fields/index.tsx @@ -45,10 +45,10 @@ export function registerField(id, component) { * @param {Object} props */ export function renderFields( - fields:Array|string, - item:IEventOrPlanningItem, - props:Object = {}, - language:string = '' + fields: Array|string, + item: IEventOrPlanningItem, + props: Object = {}, + language: string = '' ) { return (Array.isArray(fields) ? fields : [fields]).map((id) => { const Component = registeredFields[id];