Skip to content

Commit

Permalink
Merge branch 'release/2.7' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkLark86 committed Mar 6, 2024
2 parents 4abd907 + ed5e386 commit 067d78d
Show file tree
Hide file tree
Showing 11 changed files with 552 additions and 103 deletions.
12 changes: 8 additions & 4 deletions client/api/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ISearchParams,
ISearchSpikeState,
IPlanningConfig,
IEventUpdateMethod,
} from '../interfaces';
import {appConfig as config} from 'appConfig';
import {IRestApiResponse} from 'superdesk-api';
Expand Down Expand Up @@ -122,14 +123,16 @@ function getEventSearchProfile() {
}

function create(updates: Partial<IEventItem>): Promise<Array<IEventItem>> {
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<IEventItem | IRestApiResponse<IEventItem>>(url, {
return superdeskApi.dataApi.create<IEventItem | IRestApiResponse<IEventItem>>('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,
Expand All @@ -142,6 +145,7 @@ function create(updates: Partial<IEventItem>): Promise<Array<IEventItem>> {
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
Expand Down
12 changes: 6 additions & 6 deletions client/api/planning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,8 @@ function getPlanningSearchProfile() {
return planningSearchProfile(planningApi.redux.store.getState());
}

function create(updates: Partial<IPlanningItem>, addToSeries?: boolean): Promise<IPlanningItem> {
return superdeskApi.dataApi.create<IPlanningItem>(
addToSeries === true ? 'planning?add_to_series=true' : 'planning',
updates
);
function create(updates: Partial<IPlanningItem>): Promise<IPlanningItem> {
return superdeskApi.dataApi.create<IPlanningItem>('planning', updates);
}

function update(original: IPlanningItem, updates: Partial<IPlanningItem>): Promise<IPlanningItem> {
Expand All @@ -161,6 +158,10 @@ function update(original: IPlanningItem, updates: Partial<IPlanningItem>): Promi
}

function createFromEvent(event: IEventItem, updates: Partial<IPlanningItem>): Promise<IPlanningItem> {
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,
Expand All @@ -176,7 +177,6 @@ function createFromEvent(event: IEventItem, updates: Partial<IPlanningItem>): Pr
...updates,
event_item: event._id,
}),
appConfig.planning.default_create_planning_series_with_event_series === true,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface IState {
diff: Partial<IEventItem>;
eventModified: boolean;
recurringPlanningItemsToUpdate: Array<IPlanningItem['_id']>;
recurringPlanningItemsToCreate: Array<IPlanningItem['_id']>;
planningUpdateMethods: {[planningId: string]: IEventUpdateMethod};
}

Expand Down Expand Up @@ -109,6 +110,12 @@ function getRecurringPlanningToUpdate(
.map((planningItem) => planningItem._id);
}

function getRecurringPlanningToCreate(updates: Partial<IEventItem>): Array<IPlanningItem['_id']> {
return (updates.associated_plannings ?? [])
.filter((planningItem) => (planningItem._id.startsWith(TEMP_ID_PREFIX)))
.map((planningItem) => planningItem._id);
}

export class UpdateRecurringEventsComponent extends React.Component<IProps, IState> {
constructor(props: IProps) {
super(props);
Expand Down Expand Up @@ -143,6 +150,7 @@ export class UpdateRecurringEventsComponent extends React.Component<IProps, ISta
this.props.updates,
this.props.originalPlanningItems
),
recurringPlanningItemsToCreate: getRecurringPlanningToCreate(this.props.updates),
planningUpdateMethods: {},
};

Expand Down Expand Up @@ -183,16 +191,49 @@ export class UpdateRecurringEventsComponent extends React.Component<IProps, ISta
return this.props.onSubmit(this.props.original, updates);
}

renderPlanningCreateForm() {
if (this.state.recurringPlanningItemsToCreate.length > 0) {
return this.props.updates.associated_plannings
.filter((planningItem) => (
this.state.recurringPlanningItemsToCreate.includes(planningItem._id)
))
.map((planningItem) => (
<div key={planningItem._id}>
<Select
label={gettext('Create planning for all events or just this one?')}
value={this.state.planningUpdateMethods[planningItem._id] ?? EVENTS.UPDATE_METHODS[0].value}
onChange={(updateMethod) => {
this.onPlanningUpdateMethodChange(planningItem._id, updateMethod as IEventUpdateMethod);
}}
>
<Option value={EVENTS.UPDATE_METHODS[0].value}>
{gettext('This event only')}
</Option>
<Option value={EVENTS.UPDATE_METHODS[1].value}>
{gettext('This and all future events')}
</Option>
<Option value={EVENTS.UPDATE_METHODS[2].value}>
{gettext('All Events')}
</Option>
</Select>
<PlanningMetaData plan={planningItem} />
</div>
));
}

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)
))
.map((planningItem) => (
<div key={planningItem._id}>
<Select
label="Update all recurring planning or just this one?"
label={gettext('Update all recurring planning or just this one?')}
value={this.state.planningUpdateMethods[planningItem._id] ?? EVENTS.UPDATE_METHODS[0].value}
onChange={(updateMethod) => {
this.onPlanningUpdateMethodChange(planningItem._id, updateMethod as IEventUpdateMethod);
Expand Down Expand Up @@ -277,6 +318,7 @@ export class UpdateRecurringEventsComponent extends React.Component<IProps, ISta
/>
</div>
)}
{this.renderPlanningCreateForm()}
{this.renderPlanningUpdateForm()}
</React.Fragment>
);
Expand Down
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "superdesk",
"license": "GPL-3.0",
"dependencies": {
"superdesk-core": "github:superdesk/superdesk-client-core#develop",
"superdesk-core": "github:superdesk/superdesk-client-core#release/2.7",
"superdesk-planning": "file:../"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 067d78d

Please sign in to comment.