diff --git a/client/api/events.ts b/client/api/events.ts index 6f0968ef9..fb029428c 100644 --- a/client/api/events.ts +++ b/client/api/events.ts @@ -6,6 +6,7 @@ import { ISearchParams, ISearchSpikeState, IPlanningConfig, + IEventUpdateMethod, } from '../interfaces'; import {appConfig as config} from 'appConfig'; import {IRestApiResponse} from 'superdesk-api'; @@ -122,14 +123,16 @@ function getEventSearchProfile() { } function create(updates: Partial): Promise> { - const url = appConfig.planning.default_create_planning_series_with_event_series === true ? - 'events?add_to_series=true' : - 'events'; + const {default_create_planning_series_with_event_series} = appConfig.planning; + const planningDefaultCreateMethod: IEventUpdateMethod = default_create_planning_series_with_event_series === true ? + 'all' : + 'single'; - return superdeskApi.dataApi.create>(url, { + return superdeskApi.dataApi.create>('events', { ...updates, associated_plannings: undefined, embedded_planning: updates.associated_plannings.map((planning) => ({ + update_method: planning.update_method ?? planningDefaultCreateMethod, coverages: planning.coverages.map((coverage) => ({ coverage_id: coverage.coverage_id, g2_content_type: coverage.planning.g2_content_type, @@ -142,6 +145,7 @@ function create(updates: Partial): Promise> { slugline: coverage.planning.slugline, ednote: coverage.planning.ednote, internal_note: coverage.planning.internal_note, + headline: coverage.planning.headline, })), })), update_method: updates.update_method?.value ?? updates.update_method diff --git a/client/api/planning.ts b/client/api/planning.ts index 1a6dfffa8..477352ea8 100644 --- a/client/api/planning.ts +++ b/client/api/planning.ts @@ -145,11 +145,8 @@ function getPlanningSearchProfile() { return planningSearchProfile(planningApi.redux.store.getState()); } -function create(updates: Partial, addToSeries?: boolean): Promise { - return superdeskApi.dataApi.create( - addToSeries === true ? 'planning?add_to_series=true' : 'planning', - updates - ); +function create(updates: Partial): Promise { + return superdeskApi.dataApi.create('planning', updates); } function update(original: IPlanningItem, updates: Partial): Promise { @@ -161,6 +158,10 @@ function update(original: IPlanningItem, updates: Partial): Promi } function createFromEvent(event: IEventItem, updates: Partial): Promise { + if (updates.update_method == null && appConfig.planning.default_create_planning_series_with_event_series === true) { + updates.update_method = 'all'; + } + return create( planningUtils.modifyForServer({ slugline: event.slugline, @@ -176,7 +177,6 @@ function createFromEvent(event: IEventItem, updates: Partial): Pr ...updates, event_item: event._id, }), - appConfig.planning.default_create_planning_series_with_event_series === true, ); } diff --git a/client/components/ItemActionConfirmation/forms/updateRecurringEventsForm.tsx b/client/components/ItemActionConfirmation/forms/updateRecurringEventsForm.tsx index c7decc026..f167e47f1 100644 --- a/client/components/ItemActionConfirmation/forms/updateRecurringEventsForm.tsx +++ b/client/components/ItemActionConfirmation/forms/updateRecurringEventsForm.tsx @@ -52,6 +52,7 @@ interface IState { diff: Partial; eventModified: boolean; recurringPlanningItemsToUpdate: Array; + recurringPlanningItemsToCreate: Array; planningUpdateMethods: {[planningId: string]: IEventUpdateMethod}; } @@ -109,6 +110,12 @@ function getRecurringPlanningToUpdate( .map((planningItem) => planningItem._id); } +function getRecurringPlanningToCreate(updates: Partial): Array { + return (updates.associated_plannings ?? []) + .filter((planningItem) => (planningItem._id.startsWith(TEMP_ID_PREFIX))) + .map((planningItem) => planningItem._id); +} + export class UpdateRecurringEventsComponent extends React.Component { constructor(props: IProps) { super(props); @@ -143,6 +150,7 @@ export class UpdateRecurringEventsComponent extends React.Component 0) { + return this.props.updates.associated_plannings + .filter((planningItem) => ( + this.state.recurringPlanningItemsToCreate.includes(planningItem._id) + )) + .map((planningItem) => ( +
+ + +
+ )); + } + + return null; + } + renderPlanningUpdateForm() { - if (Object.keys(this.state.recurringPlanningItemsToUpdate).length > 0) { + if (this.state.recurringPlanningItemsToUpdate.length > 0) { return this.props.updates.associated_plannings .filter((planningItem) => ( this.state.recurringPlanningItemsToUpdate.includes(planningItem._id) @@ -192,7 +233,7 @@ export class UpdateRecurringEventsComponent extends React.Component (