Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remaining fixes for stt 24 #2044

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 79 additions & 79 deletions client/components/Planning/PlanningItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import {connect} from 'react-redux';
import {get, isEqual} from 'lodash';
import {OverlayTrigger, Tooltip} from 'react-bootstrap';
import {Menu, Spacer} from 'superdesk-ui-framework/react';
import {Menu, Spacer, SpacerBlock} from 'superdesk-ui-framework/react';

import {superdeskApi} from '../../superdeskApi';
import {
Expand Down Expand Up @@ -246,89 +246,86 @@ class PlanningItemComponent extends React.Component<IProps, IState> {
{renderFields(get(listFields, 'planning.primary_fields',
PLANNING.LIST.PRIMARY_FIELDS), item, {}, language)}
</span>

{event && (
<span className="sd-no-wrap">
<Icon className="icon-event" color={ICON_COLORS.DARK_BLUE_GREY} />&nbsp;
<EventDateTime item={event} />
</span>
)}
</Row>
<Row classes="sd-overflow--visible"> {/** overflow is needed for coverage icons */}
{isExpired && (
<Label
text={gettext('Expired')}
iconType="alert"
isHollow={true}
/>
)}
{secondaryFields.includes('state') && renderFields('state', item) }
{eventUtils.isEventCompleted(event) && (
<Label
text={gettext('Event Completed')}
iconType="success"
isHollow={true}
/>
)}
{secondaryFields.includes('featured') &&
renderFields('featured', item, {tooltipFlowDirection: 'right'})}

{secondaryFields.includes('agendas') &&
renderFields('agendas', item, {
fieldsProps: {
agendas: {
agendas: planningUtils.getAgendaNames(item, agendas),

<Spacer h gap="8" justifyContent="space-between" noWrap>
<Spacer h gap="8" justifyContent="start" noWrap>
{isExpired && (
<Label
text={gettext('Expired')}
iconType="alert"
isHollow={true}
/>
)}
{secondaryFields.includes('state') && renderFields('state', item) }

{eventUtils.isEventCompleted(event) && (
<Label
text={gettext('Event Completed')}
iconType="success"
isHollow={true}
/>
)}
{secondaryFields.includes('featured') &&
renderFields('featured', item, {tooltipFlowDirection: 'right'})}

{secondaryFields.includes('agendas') &&
renderFields('agendas', item, {
fieldsProps: {
agendas: {
agendas: planningUtils.getAgendaNames(item, agendas),
},
},
},
noGrow: true,
})}
noGrow: true,
})}

{(() => {
const relatedEvents = this.props.item.related_events ?? [];
const {relatedEventsUI} = this.props;
{(() => {
const relatedEvents = this.props.item.related_events ?? [];
const {relatedEventsUI} = this.props;

if (relatedEvents.length < 1 || relatedEventsUI == null) {
return null;
}
if (relatedEvents.length < 1 || relatedEventsUI == null) {
return null;
}

return (
<a
className="sd-line-input__input--related-item-link"
onClick={(event) => {
event.stopPropagation();
return (
<a
className="sd-line-input__input--related-item-link"
onClick={(event) => {
event.stopPropagation();

relatedEventsUI.setVisibility(!relatedEventsUI.visible);
}}
>
<Spacer h gap="4" alignItems="center" noWrap>
<span
style={{
paddingBlockStart: 1, // fixing icon alignment
}}
>
<i className="icon-event" />
</span>
<span>
{
relatedEventsUI.visible
? gettextPlural(
relatedEvents.length,
'Hide 1 event',
'Hide {{n}} events',
{n: relatedEvents.length},
)
: gettextPlural(
relatedEvents.length,
'Show 1 event',
'Show {{n}} events',
{n: relatedEvents.length},
)
}
</span>
</Spacer>
</a>
);
})()}
relatedEventsUI.setVisibility(!relatedEventsUI.visible);
}}
>
<Spacer h gap="4" alignItems="center" noWrap>
<span
style={{
paddingBlockStart: 1, // fixing icon alignment
}}
>
<i className="icon-event" />
</span>
<span>
{
relatedEventsUI.visible
? gettextPlural(
relatedEvents.length,
'Hide 1 event',
'Hide {{n}} events',
{n: relatedEvents.length},
)
: gettextPlural(
relatedEvents.length,
'Show 1 event',
'Show {{n}} events',
{n: relatedEvents.length},
)
}
</span>
</Spacer>
</a>
);
})()}
</Spacer>

{secondaryFields.includes('coverages') && renderFields('coverages', item, {
date,
Expand All @@ -339,7 +336,10 @@ class PlanningItemComponent extends React.Component<IProps, IState> {
contacts,
filterLanguage,
})}
</Row>
</Spacer>

<SpacerBlock v gap="8" />

</Column>
{listViewType === LIST_VIEW_TYPE.SCHEDULE ? null : (
<CreatedUpdatedColumn
Expand Down
74 changes: 26 additions & 48 deletions client/components/Planning/PlanningItemWithEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react';
import {NestedItem} from '../../components/UI/List';
import {PlanningItem} from '../Planning/PlanningItem';
import {IEventItem, IEventListItemProps, IPlanningListItemProps} from 'interfaces';
import {planningApi, superdeskApi} from '../../superdeskApi';
import {superdeskApi} from '../../superdeskApi';
import {EventItem} from '../../components/Events';
import {Loader} from 'superdesk-ui-framework/react';
import {eventUtils} from '../../utils';

interface IProps {
planningProps: IPlanningListItemProps;
Expand All @@ -14,60 +14,31 @@ interface IProps {

interface IState {
expanded: boolean;
events: {status: 'not-initialized'} | {status: 'loading'} | {status: 'ready'; items: Array<IEventItem>};
}

export class PlanningItemWithEvents extends React.Component<IProps, IState> {
private _mounted: boolean;

constructor(props: IProps) {
super(props);

this._mounted = false;

this.state = {
expanded: false,
events: {status: 'not-initialized'},
};

this.loadEvents = this.loadEvents.bind(this);
this.setVisibility = this.setVisibility.bind(this);
}

componentDidMount(): void {
this._mounted = true;
}

componentWillUnmount(): void {
this._mounted = false;
}

private loadEvents(): void {
planningApi.events.getByIds(this.props.relatedEventIds, 'draft').then((response) => {
if (this._mounted) { // would be good to use an AbortSignal.
this.setState({events: {status: 'ready', items: response}});
}
});
}

private setVisibility(expanded: boolean) {
const nextState: IState = {
...this.state,
expanded: expanded,
};

if (nextState.expanded === true && this.state.events.status === 'not-initialized') {
nextState.events = {status: 'loading'};

this.loadEvents();
}

this.setState(nextState);
}

render() {
const {planningProps} = this.props;
const {assertNever} = superdeskApi.helpers;
const {WithLiveResources} = superdeskApi.components;

return (
<NestedItem
Expand All @@ -81,24 +52,31 @@ export class PlanningItemWithEvents extends React.Component<IProps, IState> {
/>
)}
nestedChildren={(() => {
switch (this.state.events.status) {
case 'not-initialized':
if (this.state.expanded !== true) {
return null;
case 'loading':
return (
<Loader />
);
case 'ready':
return this.state.events.items.map((event) => (
<EventItem
{...this.props.getEventProps(event)}
multiSelectDisabled
key={event._id}
/>
));
default:
assertNever(this.state.events);
}

return (
<WithLiveResources resources={[{resource: 'events', ids: this.props.relatedEventIds}]}>
{([res]) => (
<div>
{
res._items.map((item) => {
const event = eventUtils.modifyForClient(item);

return (
<EventItem
{...this.props.getEventProps(event)}
multiSelectDisabled
key={event._id}
/>
);
})
}
</div>
)}
</WithLiveResources>
);
})()}
expanded={this.state.expanded}
/>
Expand Down
3 changes: 1 addition & 2 deletions client/components/UI/List/Row.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, {CSSProperties} from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

interface IProps {
children: Array<JSX.Element> | JSX.Element;
children: React.ReactNode;
classes?: string;
paddingBottom?: boolean;
testId?: string;
Expand Down
3 changes: 3 additions & 0 deletions client/utils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,9 @@ function getLocalEndDate(event: IEventItem): moment.Moment {
return moment(event.dates.end);
}

function modifyForClient(event: IEventItem): IEventItem; // overload

// eslint-disable-next-line no-redeclare
function modifyForClient(event: Partial<IEventItem>): Partial<IEventItem> {
sanitizeItemFields(event);

Expand Down
Loading