diff --git a/client/actions/planning/ui.ts b/client/actions/planning/ui.ts index 113fd23b6..033a995cf 100644 --- a/client/actions/planning/ui.ts +++ b/client/actions/planning/ui.ts @@ -514,22 +514,6 @@ const saveFromAuthoring = (original, updates) => ( } ); -const addScheduledUpdateToWorkflow = (original, coverage, coverageIndex, scheduledUpdate, index) => ( - (dispatch, getState, {notify}) => { - let updates = {coverages: cloneDeep(original.coverages)}; - let coverage = updates.coverages[coverageIndex]; - - coverage.scheduled_updates[index] = planningUtils.addToWorkflow(scheduledUpdate, - selectors.general.newsCoverageStatus(getState())); - - return dispatch(planningApis.save(original, updates)) - .then((savedItem) => { - notify.success(gettext('Scheduled update added to workflow.')); - return dispatch(self.updateItemOnSave(savedItem)); - }); - } -); - /** * Action to update the values of a single Coverage so the Assignment is placed in the workflow * @param {object} original - Original Planning item @@ -597,7 +581,6 @@ const self = { openFeaturedPlanningModal, updateItemOnSave, addNewCoverageToPlanning, - addScheduledUpdateToWorkflow, }; export default self; diff --git a/client/api/planning.ts b/client/api/planning.ts index b371db454..3497b8266 100644 --- a/client/api/planning.ts +++ b/client/api/planning.ts @@ -11,6 +11,7 @@ import { ISearchSpikeState, IPlanningRelatedEventLink, IPlanningNewsCoverageStatus, + ICoverageScheduledUpdate, } from '../interfaces'; import {appConfig} from 'appConfig'; @@ -218,7 +219,7 @@ function bulkAddCoverageToWorkflow(planningItems: Array): Promise const updates = {coverages: cloneDeep(plan.coverages)}; updates.coverages = plan.coverages - .map((coverage) => planningUtils.addToWorkflow(coverage, coverageStatuses)); + .map((coverage) => planningUtils.addCoverageToWorkflow(coverage, coverageStatuses)); return planning.update(plan, updates) .then((updatedPlan) => { @@ -253,13 +254,29 @@ function addCoverageToWorkflow( return coverages.map((coverage) => { if (coverage.coverage_id === coverageToAddToWorkflow.coverage_id) { - return planningUtils.addToWorkflow(coverageToAddToWorkflow, coverageStatuses); + return planningUtils.addCoverageToWorkflow(coverageToAddToWorkflow, coverageStatuses); } else { return coverage; } }); } +function addScheduledUpdateToWorkflow( + updates: Array, + updateToAddToWorkflow: ICoverageScheduledUpdate, +): Array { + const {vocabulary} = superdeskApi.entities; + const coverageStatuses = vocabulary.getAll().get('newscoveragestatus').items as Array; + + return updates.map((update) => { + if (update.scheduled_update_id === updateToAddToWorkflow.scheduled_update_id) { + return planningUtils.addScheduledUpdateToWorkflow(updateToAddToWorkflow, coverageStatuses); + } else { + return update; + } + }); +} + export const planning: IPlanningAPI['planning'] = { search: searchPlanning, searchGetAll: searchPlanningGetAll, @@ -274,6 +291,7 @@ export const planning: IPlanningAPI['planning'] = { coverages: { setDefaultValues: setDefaultValues, addCoverageToWorkflow: addCoverageToWorkflow, + addScheduledUpdateToWorkflow: addScheduledUpdateToWorkflow, bulkAddCoverageToWorkflow: bulkAddCoverageToWorkflow, }, }; diff --git a/client/components/Coverages/CoverageArrayInput.tsx b/client/components/Coverages/CoverageArrayInput.tsx index 747fefa06..874a3cb3f 100644 --- a/client/components/Coverages/CoverageArrayInput.tsx +++ b/client/components/Coverages/CoverageArrayInput.tsx @@ -66,12 +66,6 @@ interface IProps { setCoverageDefaultDesk(coverage: IPlanningCoverageItem): void; setCoverageAddAdvancedMode(enabled: boolean): Promise; createUploadLink(file: IFile): void; - onAddScheduledUpdateToWorkflow( - coverage: IPlanningCoverageItem, - index: number, - scheduledUpdate?: ICoverageScheduledUpdate, - scheduledUpdateIndex?: number - ): void; onRemoveAssignment(assignemnt: IAssignmentItem): Promise; uploadFiles(files: Array>): Promise>; notifyValidationErrors(errors: Array): void; diff --git a/client/components/Coverages/CoverageEditor/CoverageForm.tsx b/client/components/Coverages/CoverageEditor/CoverageForm.tsx index 4e0990d0f..73ec1dac9 100644 --- a/client/components/Coverages/CoverageEditor/CoverageForm.tsx +++ b/client/components/Coverages/CoverageEditor/CoverageForm.tsx @@ -441,6 +441,7 @@ export class CoverageFormComponent extends React.Component { this.props.includeScheduledUpdates && this.props.value.planning?.g2_content_type === 'text' ), + scheduledUpdates: this.props.value.scheduled_updates ?? [], }, priority: {field: 'planning.priority'}, }; diff --git a/client/components/Coverages/ScheduledUpdate/index.tsx b/client/components/Coverages/ScheduledUpdate/index.tsx index 5e5a46c65..c99ae49d2 100644 --- a/client/components/Coverages/ScheduledUpdate/index.tsx +++ b/client/components/Coverages/ScheduledUpdate/index.tsx @@ -23,11 +23,13 @@ import {CoverageFormHeader} from '../CoverageEditor/CoverageFormHeader'; import {CoveragePreviewTopBar} from '../CoveragePreview/CoveragePreviewTopBar'; import {planningUtils, stringUtils, assignmentUtils} from '../../../utils'; -import {PLANNING, COVERAGES} from '../../../constants'; +import {PLANNING} from '../../../constants'; +import {planningApis} from '../../../api'; interface IProps { diff: IPlanningCoverageItem; planning: IPlanningItem; + scheduledUpdates: Array; index: number; field: string; value: ICoverageScheduledUpdate; @@ -64,12 +66,6 @@ interface IProps { onOpen?(coverage: ICoverageScheduledUpdate): void; onClose?(coverage: ICoverageScheduledUpdate): void; onCancelScheduledUpdate?(): void; - onAddScheduledUpdateToWorkflow( - coverage: IPlanningCoverageItem, - coverageIndex: number, - scheduledUpdate: ICoverageScheduledUpdate, - scheduledIndex: number - ): void; } export class ScheduledUpdate extends React.PureComponent { @@ -80,20 +76,10 @@ export class ScheduledUpdate extends React.PureComponent { constructor(props: IProps) { super(props); - this.addScheduledUpdateToWorkflow = this.addScheduledUpdateToWorkflow.bind(this); this.onOpen = this.onOpen.bind(this); this.onClose = this.onClose.bind(this); } - addScheduledUpdateToWorkflow() { - this.props.onAddScheduledUpdateToWorkflow( - this.props.diff, - this.props.coverageIndex, - this.props.value, - this.props.index - ); - } - onOpen() { this.props.onOpen(this.props.value); } @@ -135,7 +121,6 @@ export class ScheduledUpdate extends React.PureComponent { onOpen, onClose, message, - onAddScheduledUpdateToWorkflow, testId, ...props } = this.props; @@ -160,7 +145,15 @@ export class ScheduledUpdate extends React.PureComponent { id: 'addToWorkflow', label: gettext('Add to workflow'), icon: 'icon-assign', - callback: this.addScheduledUpdateToWorkflow, + callback: () => { + this.props.onChange( + 'scheduled_updates', + planningApis.planning.coverages.addScheduledUpdateToWorkflow( + this.props.scheduledUpdates, + this.props.value, + ), + ); + }, }); } diff --git a/client/components/Main/ItemEditor/ItemManager.ts b/client/components/Main/ItemEditor/ItemManager.ts index 01bc185ae..7e02ad71e 100644 --- a/client/components/Main/ItemEditor/ItemManager.ts +++ b/client/components/Main/ItemEditor/ItemManager.ts @@ -58,7 +58,6 @@ export class ItemManager { this.addCoverage = this.addCoverage.bind(this); this.startPartialSave = this.startPartialSave.bind(this); this.openInModal = this.openInModal.bind(this); - this.addScheduledUpdateToWorkflow = this.addScheduledUpdateToWorkflow.bind(this); this.removeAssignment = this.removeAssignment.bind(this); this.setStateForPartialSave = this.setStateForPartialSave.bind(this); @@ -880,12 +879,6 @@ export class ItemManager { ); } - addScheduledUpdateToWorkflow(planning, coverage, covergeIndex, scheduledUpdate, index) { - return this.dispatch(actions.planning.ui.addScheduledUpdateToWorkflow(planning, coverage, covergeIndex, - scheduledUpdate, index)) - .then((updates) => this.finalisePartialSave(this.getCoverageAfterPartialSave(updates, index))); - } - removeAssignment(planning, coverage, index) { return this.dispatch(actions.planning.ui.removeAssignment(planning, coverage, index)) .then((updates) => this.finalisePartialSave(this.getCoverageAfterPartialSave(updates, index))); diff --git a/client/components/Planning/PlanningEditor/index.tsx b/client/components/Planning/PlanningEditor/index.tsx index 34511fa9b..18829d7a4 100644 --- a/client/components/Planning/PlanningEditor/index.tsx +++ b/client/components/Planning/PlanningEditor/index.tsx @@ -118,7 +118,6 @@ class PlanningEditorComponent extends React.Component { this.onCoverageChange = this.onCoverageChange.bind(this); this.onPlanningDateChange = this.onPlanningDateChange.bind(this); this.onTimeToBeConfirmed = this.onTimeToBeConfirmed.bind(this); - this.onAddScheduledUpdateToWorkflow = this.onAddScheduledUpdateToWorkflow.bind(this); this.onRemoveAssignment = this.onRemoveAssignment.bind(this); } @@ -334,21 +333,6 @@ class PlanningEditorComponent extends React.Component { } } - onAddScheduledUpdateToWorkflow( - coverage: IPlanningCoverageItem, - coverageIndex: number, - scheduledUpdate: ICoverageScheduledUpdate, - index: number - ) { - this.onPartialSave( - coverage, - coverageIndex, - COVERAGES.PARTIAL_SAVE.SCHEDULED_UPDATES_ADD_TO_WORKFLOW, - scheduledUpdate, - index - ); - } - onRemoveAssignment( coverage: IPlanningCoverageItem, index: number, @@ -392,8 +376,6 @@ class PlanningEditorComponent extends React.Component { if (action === COVERAGES.PARTIAL_SAVE.REMOVE_ASSIGNMENT) { partialSaveAction = this.props.itemManager.removeAssignment; - } else if (action == COVERAGES.PARTIAL_SAVE.SCHEDULED_UPDATES_ADD_TO_WORKFLOW) { - partialSaveAction = this.props.itemManager.addScheduledUpdateToWorkflow; } partialSaveAction(this.props.item, coverage, index, scheduledUpdate, scheduledUpdateIndex); @@ -482,7 +464,6 @@ class PlanningEditorComponent extends React.Component { preferredCoverageDesks: this.props.preferredCoverageDesks, setCoverageDefaultDesk: this.props.setCoverageDefaultDesk, setCoverageAddAdvancedMode: this.props.setCoverageAddAdvancedMode, - onAddScheduledUpdateToWorkflow: this.onAddScheduledUpdateToWorkflow, onRemoveAssignment: this.onRemoveAssignment, defaultValue: [], files: this.props.files, diff --git a/client/components/fields/editor/coverages.interface.ts b/client/components/fields/editor/coverages.interface.ts index 88b1e8a68..cb56f666d 100644 --- a/client/components/fields/editor/coverages.interface.ts +++ b/client/components/fields/editor/coverages.interface.ts @@ -29,12 +29,6 @@ export interface IPropsEditorFieldCoverages extends IEditorFieldProps { onPopupClose?(): void; setCoverageDefaultDesk(coverage: IPlanningCoverageItem): void; setCoverageAddAdvancedMode(enabled: boolean): Promise; - onAddScheduledUpdateToWorkflow( - coverage: IPlanningCoverageItem, - index: number, - scheduledUpdate?: ICoverageScheduledUpdate, - scheduledUpdateIndex?: number - ): void; onRemoveAssignment( coverage: IPlanningCoverageItem, index: number, diff --git a/client/constants/coverages.ts b/client/constants/coverages.ts index 08c330e88..b44dcb20b 100644 --- a/client/constants/coverages.ts +++ b/client/constants/coverages.ts @@ -3,9 +3,7 @@ import {superdeskApi} from '../superdeskApi'; export const COVERAGES = { WORKFLOW_STATE: {ACTIVE: 'active'}, PARTIAL_SAVE: { - ADD_TO_WORKFLOW: 'ADD_TO_WORKFLOW', REMOVE_ASSIGNMENT: 'REMOVE_ASSIGNMENT', - SCHEDULED_UPDATES_ADD_TO_WORKFLOW: 'SCHEDULED_UPDATES_ADD_TO_WORKFLOW', SCHEDULED_UPDATES_REMOVE_ASSIGNMENT: 'SCHEDULED_UPDATES_REMOVE_ASSIGNMENT', }, HISTORY_OPERATIONS: { diff --git a/client/interfaces.ts b/client/interfaces.ts index 3931bd5f0..aa41b0ca0 100644 --- a/client/interfaces.ts +++ b/client/interfaces.ts @@ -1343,13 +1343,6 @@ export interface IFormItemManager { coverage: IPlanningCoverageItem, index: number ): Promise; - addScheduledUpdateToWorkflow( - planning: IPlanningItem, - coverage: IPlanningCoverageItem, - coverageIndex: number, - scheduledUpdate: ICoverageScheduledUpdate, - index: number - ): Promise; finalisePartialSave(diff: DeepPartial, updateDirtyFlag: boolean): Promise; setState(newState: Partial): Promise; getState(): IEditorState; @@ -2221,6 +2214,10 @@ export interface IPlanningAPI { coverages: Array, coverageToAddToWorkflow: IPlanningCoverageItem, ): Array; + addScheduledUpdateToWorkflow( + updates: Array, + updateToAddToWorkflow: ICoverageScheduledUpdate, + ): Array; bulkAddCoverageToWorkflow(planingItems: Array): Promise>; } create(updates: Partial): Promise; diff --git a/client/planning-extension/src/authoring-react-fields/coverages/editor.tsx b/client/planning-extension/src/authoring-react-fields/coverages/editor.tsx index 816be4946..2c07426c7 100644 --- a/client/planning-extension/src/authoring-react-fields/coverages/editor.tsx +++ b/client/planning-extension/src/authoring-react-fields/coverages/editor.tsx @@ -34,7 +34,6 @@ export class Editor extends React.PureComponent { setCoverageAddAdvancedMode={() => Promise.resolve()} preferredCoverageDesks={{}} uploadFiles={() => Promise.resolve([])} - onAddScheduledUpdateToWorkflow={noop} message={{}} notifyValidationErrors={noop} onChange={(fieldPath: any, value: any) => { diff --git a/client/utils/planning.tsx b/client/utils/planning.tsx index 985ef4479..dd3b3528a 100644 --- a/client/utils/planning.tsx +++ b/client/utils/planning.tsx @@ -1764,30 +1764,47 @@ function canAddScheduledUpdateToWorkflow( ); } -function setCoverageActiveValues( - coverage: IPlanningCoverageItem | ICoverageScheduledUpdate, +function addToWorkflowCommon( + item: T, newsCoverageStatus: Array -): void { - set(coverage, 'news_coverage_status', newsCoverageStatus.find((s) => s.qcode === 'ncostat:int')); - set(coverage, 'workflow_status', COVERAGES.WORKFLOW_STATE.ACTIVE); - set(coverage, 'assigned_to.state', ASSIGNMENTS.WORKFLOW_STATE.ASSIGNED); +): T { + const next: T = cloneDeep(item); + + next.news_coverage_status = newsCoverageStatus.find((s) => s.qcode === 'ncostat:int'); + next.workflow_status = COVERAGES.WORKFLOW_STATE.ACTIVE; + + if (next.assigned_to != null) { + next.assigned_to.state = ASSIGNMENTS.WORKFLOW_STATE.ASSIGNED; + } + + return next; } -function addToWorkflow( - updatedCoverage: IPlanningCoverageItem, +function addCoverageToWorkflow( + coverage: IPlanningCoverageItem, newsCoverageStatus: Array ): IPlanningCoverageItem { - const coverage = cloneDeep(updatedCoverage); + const coverageNext = addToWorkflowCommon(coverage, newsCoverageStatus); - setCoverageActiveValues(coverage, newsCoverageStatus); - (get(coverage, 'scheduled_updates') || []).forEach((s) => { - // Add the scheduled_update to workflow if they have an assignment - if (get(s, 'assigned_to')) { - setCoverageActiveValues(s, newsCoverageStatus); - } - }); + if (coverageNext.scheduled_updates != null) { + coverageNext.scheduled_updates = coverageNext.scheduled_updates.map((update) => { + // Add the scheduled_update to workflow if they have an assignment + if (update.assigned_to != null) { + return addToWorkflowCommon(update, newsCoverageStatus); + } else { + return update; + } + }); + } - return coverage; + return coverageNext; +} + +function addScheduledUpdateToWorkflow( + update: ICoverageScheduledUpdate, + newsCoverageStatus: Array +): ICoverageScheduledUpdate { + return addToWorkflowCommon(update, newsCoverageStatus); } function getPlanningFiles(planning: IPlanningItem): IPlanningItem['files'] { @@ -1950,7 +1967,8 @@ const self = { getDateStringForPlanning, setDefaultAssignment, getCoverageDateText, - addToWorkflow: addToWorkflow, + addCoverageToWorkflow, + addScheduledUpdateToWorkflow, canAddScheduledUpdateToWorkflow, getDefaultCoverageStatus, getPlanningFiles,