Skip to content

Commit

Permalink
Stt 15 (superdesk#2004)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc authored Jul 2, 2024
1 parent f910266 commit 7df17ff
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 38 deletions.
6 changes: 4 additions & 2 deletions client/components/Planning/PlanningEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface IProps {
submitFailed: boolean;
itemManager: IFormItemManager;

event?: IEventItem;
events?: Array<IEventItem>;
addNewsItemToPlanning?: IArticle;
inModalView: boolean;
activeNav?: string;
Expand Down Expand Up @@ -83,6 +83,7 @@ interface IState {
}

const mapStateToProps = (state) => ({
events: selectors.events.storedEvents(state),
newsCoverageStatus: selectors.general.newsCoverageStatus(state),
currentAgenda: selectors.planning.currentAgenda(state),
desk: selectors.general.currentDeskId(state),
Expand Down Expand Up @@ -499,7 +500,8 @@ class PlanningEditorComponent extends React.Component<IProps, IState> {
files: this.props.files,
},
associated_event: {
event: this.props.event,
events: (this.props.item.related_events ?? [])
.map((relatedEvent) => this.props.events[relatedEvent._id]),
},
coverages: {
onChange: this.onCoverageChange,
Expand Down
45 changes: 28 additions & 17 deletions client/components/Planning/PlanningPreviewContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {ContentBlock} from '../UI/SidePanel';
import {EventMetadata} from '../Events';
import {FeatureLabel} from './FeaturedPlanning';
import {previewGroupToProfile, renderGroupedFieldsForPanel} from '../fields';
import {getRelatedEventIdsForPlanning} from '../../utils/planning';

interface IProps {
item: IPlanningItem;
Expand All @@ -40,11 +41,13 @@ interface IProps {
session: ISession;
lockedItems: ILockedItems;
formProfile: IFormProfiles;
event?: IEventItem;
relatedEvents?: Array<IEventItem>;
newsCoverageStatus: Array<IPlanningNewsCoverageStatus>;
onEditEvent(): void; // TODO - match code
inner?: boolean;
noPadding?: boolean;

// TODO: Multiple related events - If BE supports bulk fetch for an array of events use it
fetchEventFiles(event: IEventItem): void; // TODO - match code
fetchPlanningFiles(item: IPlanningItem): void; // TODO - match code
hideRelatedItems?: boolean;
Expand All @@ -56,7 +59,7 @@ interface IProps {

const mapStateToProps = (state, ownProps) => ({
item: selectors.planning.currentPlanning(state) || ownProps.item,
event: selectors.events.planningWithEventDetails(state),
relatedEvents: selectors.events.getRelatedEventsForPlanning(state),
session: selectors.general.session(state),
privileges: selectors.general.privileges(state),
users: selectors.general.users(state),
Expand All @@ -77,8 +80,10 @@ const mapDispatchToProps = (dispatch) => ({
export class PlanningPreviewContentComponent extends React.PureComponent<IProps> {
componentWillMount() {
// If the planning item is associated with an event, get its files
if (this.props.event) {
this.props.fetchEventFiles(this.props.event);
if ((this.props.relatedEvents?.length ?? 0) > 0) {
this.props.relatedEvents.forEach((relatedEvent) => (
this.props.fetchEventFiles(relatedEvent)
));
}

this.props.fetchPlanningFiles(this.props.item);
Expand All @@ -89,7 +94,7 @@ export class PlanningPreviewContentComponent extends React.PureComponent<IProps>
const {item,
users,
formProfile,
event,
relatedEvents,
desks,
newsCoverageStatus,
onEditEvent,
Expand Down Expand Up @@ -133,6 +138,9 @@ export class PlanningPreviewContentComponent extends React.PureComponent<IProps>
/>
);

const primaryEventId = getRelatedEventIdsForPlanning(this.props.item, 'primary')[0];
const primaryRelatedEvent = (relatedEvents ?? []).find((relatedEvent) => relatedEvent._id === primaryEventId);

return (
<ContentBlock noPadding={noPadding}>
<div className="side-panel__content-block--flex">
Expand All @@ -153,7 +161,8 @@ export class PlanningPreviewContentComponent extends React.PureComponent<IProps>
verbose={true}
withExpiredStatus={true}
/>
{eventUtils.isEventCompleted(event) && (
{/* TODO: How do we display event status when there's multiple? Primary only? */}
{eventUtils.isEventCompleted(primaryRelatedEvent) && (
<Label
text={gettext('Event Completed')}
iconType="success"
Expand Down Expand Up @@ -200,19 +209,21 @@ export class PlanningPreviewContentComponent extends React.PureComponent<IProps>
)}
{!hideRelatedItems && event && (
<h3 className="side-panel__heading--big">
{gettext('Associated Event')}
{gettext('Associated Events')}
</h3>
)}
{!hideRelatedItems && event && (
<EventMetadata
event={event}
dateOnly={true}
onEditEvent={onEditEvent.bind(null, event)}
lockedItems={lockedItems}
createUploadLink={getFileDownloadURL}
files={files}
hideEditIcon={hideEditIcon}
/>
{!hideRelatedItems && (relatedEvents?.length ?? 0) > 0 && (
relatedEvents.map((relatedEvent) => (
<EventMetadata
key={`related_event--${relatedEvent._id}`}
event={relatedEvent}
dateOnly={true}
onEditEvent={onEditEvent.bind(null, relatedEvent)}
createUploadLink={getFileDownloadURL}
files={files}
hideEditIcon={hideEditIcon}
/>
))
)}
{!hasCoverage ? null : (
<React.Fragment>
Expand Down
2 changes: 1 addition & 1 deletion client/components/Planning/PlanningPreviewHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ PlanningPreviewHeaderComponent.propTypes = {

const mapStateToProps = (state) => ({
item: selectors.planning.currentPlanning(state),
event: selectors.events.planningWithEventDetails(state),
event: selectors.events.getRelatedEventsForPlanning(state),
session: selectors.general.session(state),
privileges: selectors.general.privileges(state),
users: selectors.general.users(state),
Expand Down
14 changes: 7 additions & 7 deletions client/components/fields/editor/AssociatedEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as selectors from '../../../selectors';
import {EventMetadata} from '../../Events';

interface IProps extends IEditorFieldProps {
event?: IEventItem;
events?: Array<IEventItem>;
lockedItems: ILockedItems;
files: Array<IFile>;
tabEnabled?: boolean; // defaults to true
Expand All @@ -22,22 +22,22 @@ const mapStateToProps = (state) => ({

class EditorFieldAssociatedEventComponent extends React.PureComponent<IProps> {
render() {
return this.props.event == null ? null : (
return (this.props.events?.length ?? 0) < 1 ? null : this.props.events.map((event) => (
<EventMetadata
key={event._id}
ref={this.props.refNode}
testId={this.props.testId}
event={this.props.event}
lockedItems={this.props.lockedItems}
testId={`${this.props.testId}--${event._id}`}
event={event}
navigation={{}}
createUploadLink={getFileDownloadURL}
files={this.props.files}
tabEnabled={this.props.tabEnabled ?? true}
/>
);
));
}
}

export const EditorFieldAssociatedEvent = connect(
export const EditorFieldAssociatedEvents = connect(
mapStateToProps,
null,
null,
Expand Down
4 changes: 2 additions & 2 deletions client/components/fields/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {EditorFieldEventRelatedPlannings} from './EventRelatedPlannings/EventRel
import {EditorFieldPlanningDateTime} from './PlanningDateTime';
import {EditorFieldNotForPublication} from './NotForPublication';
import {EditorFieldOverrideAutoAssignToWorkflow} from './OverrideAutoAssignToWorkflow';
import {EditorFieldAssociatedEvent} from './AssociatedEvent';
import {EditorFieldAssociatedEvents} from './AssociatedEvent';
import {EditorFieldCoverages} from './Coverages';
import {EditorFieldGenre} from './Genre';
import {EditorFieldNewsCoverageStatus} from './NewsCoverageStatus';
Expand Down Expand Up @@ -127,7 +127,7 @@ export const FIELD_TO_EDITOR_COMPONENT = {
marked_for_not_publication: EditorFieldNotForPublication,
'flags.overide_auto_assign_to_workflow': EditorFieldOverrideAutoAssignToWorkflow,
overide_auto_assign_to_workflow: EditorFieldOverrideAutoAssignToWorkflow,
associated_event: EditorFieldAssociatedEvent,
associated_event: EditorFieldAssociatedEvents,
coverages: EditorFieldCoverages,
genre: EditorFieldGenre,
news_coverage_status: EditorFieldNewsCoverageStatus,
Expand Down
10 changes: 5 additions & 5 deletions client/selectors/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,21 @@ export const getRelatedPlanningsForModalEvent = createSelector(
(itemId, events, plannings, agendas) => getRelatedPlanningsForEvent(itemId, events, plannings, agendas)
);

export const planningWithEventDetails = createSelector<
export const getRelatedEventsForPlanning = createSelector<
IPlanningAppState,
IPlanningItem | null,
{[eventId: string]: IEventItem},
IEventItem | null
Array<IEventItem> | null
>(
[currentPlanning, storedEvents],
(item, events) => {
if (item == null) {
return null;
}

const relatedEventIds = getRelatedEventIdsForPlanning(item, 'primary');

return relatedEventIds.length > 0 ? events[relatedEventIds[0]] : null;
return (item.related_events?.length ?? 0) > 0
? item.related_events.map((relatedEvent) => events[relatedEvent._id])
: null;
}
);

Expand Down
7 changes: 3 additions & 4 deletions client/utils/planning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,14 @@ function canCancelAllCoverage(

function canAddAsEvent(
planning: IPlanningItem,
event: IEventItem | null,
session: ISession,
privileges: IPrivileges,
locks: ILockedItems
): boolean {
return (
!!privileges[PRIVILEGES.EVENT_MANAGEMENT] &&
!!privileges[PRIVILEGES.PLANNING_MANAGEMENT] &&
isPlanAdHoc(planning) &&
// TODO: Add check for config option, if multiple events are allowed or not,
// if not, disallow after there's a primary link
!lockUtils.isItemLocked(planning, locks) &&
!isItemSpiked(planning) &&
getItemWorkflowState(planning) !== WORKFLOW_STATE.KILLED &&
Expand Down Expand Up @@ -425,7 +424,7 @@ export function getPlanningItemActions(
[PLANNING.ITEM_ACTIONS.CANCEL_ALL_COVERAGE.actionName]: () =>
canCancelAllCoverage(plan, event, session, privileges, locks),
[PLANNING.ITEM_ACTIONS.ADD_AS_EVENT.actionName]: () =>
canAddAsEvent(plan, event, session, privileges, locks),
canAddAsEvent(plan, privileges, locks),
[PLANNING.ITEM_ACTIONS.EDIT_PLANNING.actionName]: () =>
canEditPlanning(plan, event, session, privileges, locks),
[PLANNING.ITEM_ACTIONS.EDIT_PLANNING_MODAL.actionName]: () =>
Expand Down

0 comments on commit 7df17ff

Please sign in to comment.