Skip to content

Commit

Permalink
Planning: If multilingual Events or Planning items are filtered by la…
Browse files Browse the repository at this point in the history
…nguage - show them in this language in the list views [SDESK-7060]
  • Loading branch information
devketanpro committed Oct 12, 2023
1 parent a727285 commit 779a465
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 12 deletions.
5 changes: 3 additions & 2 deletions client/components/Events/EventItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class EventItemComponent extends React.Component<IProps, IState> {
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() {
Expand Down Expand Up @@ -216,7 +217,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)}
EVENTS.LIST.PRIMARY_FIELDS), item, this.props)}
</span>
</Row>
<Row>
Expand Down
17 changes: 14 additions & 3 deletions client/components/Main/ListGroupItem.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
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';
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,
Expand All @@ -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<IProps, IState> {
const mapStateToProps = (state) => ({
currentParams: currentSearchParams(state),
});

class ListGroupComponent extends React.Component<IProps, IState> {
dom: {item: HTMLElement};
_delayedClick: any | undefined;

Expand Down Expand Up @@ -122,6 +128,7 @@ export class ListGroupItem extends React.Component<IProps, IState> {
listViewType,
sortField,
minTimeWidth,
currentParams
} = this.props;
const itemType = getItemType(item);

Expand Down Expand Up @@ -151,6 +158,7 @@ export class ListGroupItem extends React.Component<IProps, IState> {
...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],
Expand Down Expand Up @@ -193,6 +201,7 @@ export class ListGroupItem extends React.Component<IProps, IState> {
contentTypes: contentTypes,
agendas: agendas,
date: date,
filterLanguage: currentParams?.language,
onAddCoverageClick: onAddCoverageClick,
multiSelected: indexOf(selectedPlanningIds, item._id) !== -1,
showAddCoverage: showAddCoverage,
Expand Down Expand Up @@ -265,3 +274,5 @@ export class ListGroupItem extends React.Component<IProps, IState> {
return null;
}
}

export const ListGroupItem = connect(mapStateToProps)(ListGroupComponent);
5 changes: 3 additions & 2 deletions client/components/Planning/PlanningItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class PlanningItemComponent extends React.Component<IProps, IState> {
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() {
Expand Down Expand Up @@ -235,7 +236,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)}
PLANNING.LIST.PRIMARY_FIELDS), item, this.props)}
</span>

{event && (
Expand Down
5 changes: 4 additions & 1 deletion client/components/fields/headline.tsx
Original file line number Diff line number Diff line change
@@ -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,
};
19 changes: 18 additions & 1 deletion client/components/fields/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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':
Expand Down
4 changes: 3 additions & 1 deletion client/components/fields/name.tsx
Original file line number Diff line number Diff line change
@@ -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,
};
9 changes: 7 additions & 2 deletions client/components/fields/slugline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<span className="sd-list-item__slugline">{item.slugline}</span>);
return (
<span className="sd-list-item__slugline">{getTranslatedValue(filterLanguage, item, 'slugline') ||
item.slugline}</span>
);
};

slugline.propTypes = {
item: PropTypes.shape({
slugline: PropTypes.string,
}).isRequired,
filterLanguage: PropTypes.string,
};
2 changes: 2 additions & 0 deletions client/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ export interface IBaseListItemProps<T> {
export interface IEventListItemProps extends IBaseListItemProps<IEventItem> {
relatedPlanningText?: string;
calendars: Array<ICalendar>;
filterLanguage?: string;
toggleRelatedPlanning?(event: React.MouseEvent): void;
}

Expand All @@ -863,6 +864,7 @@ export interface IPlanningListItemProps extends IBaseListItemProps<IPlanningItem
agendas: Array<IAgenda>;
users: Array<IUser>;
desks: Array<IDesk>;
filterLanguage?: string;
// showUnlock?: boolean; // Is this used anymore?
hideItemActions: boolean;
showAddCoverage: boolean;
Expand Down

0 comments on commit 779a465

Please sign in to comment.