diff --git a/client/components/Events/EventItem.tsx b/client/components/Events/EventItem.tsx index f9385615c..2e5fee0aa 100644 --- a/client/components/Events/EventItem.tsx +++ b/client/components/Events/EventItem.tsx @@ -46,6 +46,7 @@ class EventItemComponent extends React.Component { this.state.hover !== nextState.hover || this.props.minTimeWidth !== nextProps.minTimeWidth || this.props.lockedItems != nextProps.lockedItems || + (this.props.relatedEventsUI && this.props.relatedEventsUI.visible != nextProps.relatedEventsUI.visible) || this.props.filterLanguage !== nextProps.filterLanguage; } @@ -143,7 +144,7 @@ class EventItemComponent extends React.Component { } render() { - const {gettext} = superdeskApi.localization; + const {gettext, gettextPlural} = superdeskApi.localization; const {querySelectorParent} = superdeskApi.utilities; const { @@ -151,7 +152,6 @@ class EventItemComponent extends React.Component { onItemClick, lockedItems, activeFilter, - toggleRelatedPlanning, onMultiSelectClick, calendars, listFields, @@ -260,22 +260,44 @@ class EventItemComponent extends React.Component { {secondaryFields.includes('files') && renderFields('files', item)} + {(() => { + const {relatedEventsUI} = this.props; - {(hasPlanning) && ( - - - - - {this.props.relatedPlanningText} - - - - )} + { + event.stopPropagation(); + relatedEventsUI.setVisibility(!relatedEventsUI.visible); + }} + > + + + {relatedPlanningText} + + + + ); + })()} {secondaryFields.includes('location') && renderFields('location', item)} @@ -300,4 +322,4 @@ class EventItemComponent extends React.Component { } } -export const EventItem = connect()(EventItemComponent); \ No newline at end of file +export const EventItem = connect()(EventItemComponent); diff --git a/client/components/Events/EventItemWithPlanning.tsx b/client/components/Events/EventItemWithPlanning.tsx index 3a7a4c35e..f597e2049 100644 --- a/client/components/Events/EventItemWithPlanning.tsx +++ b/client/components/Events/EventItemWithPlanning.tsx @@ -48,8 +48,7 @@ export class EventItemWithPlanning extends React.Component { this.handleKeyDown = this.handleKeyDown.bind(this); } - toggleRelatedPlanning(evt) { - evt.stopPropagation(); + toggleRelatedPlanning(isOpen) { if (!this.state.openPlanningItems) { this.props.showRelatedPlannings(get(this.props, 'eventProps.item', {})); } @@ -58,7 +57,7 @@ export class EventItemWithPlanning extends React.Component { this.setState({ activeIndex: activeIndex, - openPlanningItems: !this.state.openPlanningItems, + openPlanningItems: isOpen, }); this.activateItem(activeIndex, false); @@ -205,13 +204,8 @@ export class EventItemWithPlanning extends React.Component { } render() { - const {gettextPlural} = superdeskApi.localization; const planningItems = get(this.props, 'eventProps.item.planning_ids', []).length; - const relatedPlanningText = this.state.openPlanningItems - ? gettextPlural(planningItems, 'Hide 1 planning item', 'Hide {{n}} planning items', {n: planningItems}) - : gettextPlural(planningItems, 'Show 1 planning item', 'Show {{n}} planning items', {n: planningItems}); - const getPlannings = (item) => ( get(this.props.relatedPlanningsInList, item._id, []).map((plan, index) => { const planningProps = { @@ -226,12 +220,20 @@ export class EventItemWithPlanning extends React.Component { const eventProps = { ...this.props.eventProps, - toggleRelatedPlanning: this.toggleRelatedPlanning, - relatedPlanningText: relatedPlanningText, + relatedPlanningsCount: planningItems, }; // Event is always indexed as 0 - const eventItem = ; + const eventItem = ( + + ); return ( { } export interface IEventListItemProps extends IBaseListItemProps { - relatedPlanningText?: string; calendars: Array; filterLanguage?: string; - toggleRelatedPlanning?(event: React.MouseEvent): void; + relatedPlanningsCount: number; + relatedEventsUI?: { + visible: boolean; + setVisibility(value: boolean): void; + }; } export interface IPlanningListItemProps extends IBaseListItemProps {