Skip to content

Commit

Permalink
Merge branch 'authoring-react-planning' into subject-field
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc committed Dec 17, 2024
2 parents e9761ca + eb6b394 commit 9a267f8
Show file tree
Hide file tree
Showing 27 changed files with 114 additions and 368 deletions.
10 changes: 0 additions & 10 deletions client/actions/assignments/tests/api_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,6 @@ describe('actions.assignments.api', () => {
});
});

it('removeAssignment', (done) => (
store.test(done, assignmentsApi.removeAssignment(data.assignments[0]))
.then(() => {
expect(services.api('assignments').remove.callCount).toBe(1);
expect(services.api('assignments').remove.args[0]).toEqual([data.assignments[0]]);

done();
})
).catch(done.fail));

describe('receivedAssignments', () => {
beforeEach(() => {
restoreSinonStub(assignmentsApi.receivedAssignments);
Expand Down
80 changes: 0 additions & 80 deletions client/actions/assignments/tests/ui_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,86 +297,6 @@ describe('actions.assignments.ui', () => {
});
});

describe('showRemoveAssignmentModal', () => {
it('locks only Assignment and displays the confirmation dialog', (done) => (
store.test(done, assignmentsUi.showRemoveAssignmentModal(data.assignments[0]))
.then((item) => {
expect(item).toEqual(data.assignments[0]);

expect(planningApi.locks.lockItem.callCount).toBe(1);
expect(planningApi.locks.lockItem.args[0]).toEqual([
data.assignments[0],
'remove_assignment'
]);

expect(store.dispatch.callCount).toBe(1);
expect(store.dispatch.args[0]).toEqual([{
type: 'SHOW_MODAL',
modalType: 'CONFIRMATION',
modalProps: jasmine.objectContaining(
{body: 'This will also remove other linked assignments (if any, for story updates). '
+ 'Are you sure?'}
),
}]);

done();
})
).catch(done.fail));

it('returns Promise.reject on locking error', (done) => {
restoreSinonStub(planningApi.locks.lockItem);
sinon.stub(planningApi.locks, 'lockItem').returns(Promise.reject(errorMessage));

return store.test(done, assignmentsUi.showRemoveAssignmentModal(data.assignments[0]))
.then(() => { /* no-op */ }, (error) => {
expect(error).toEqual(errorMessage);
done();
})
.catch(done.fail);
});
});

describe('_removeAssignment', () => {
beforeEach(() => {
sinon.stub(assignmentsApi, 'removeAssignment').callsFake(
(item) => Promise.resolve(item)
);
});

afterEach(() => {
restoreSinonStub(assignmentsApi.removeAssignment);
});

it('Executes api.removeAssignment and notifies user of success', (done) => (
store.test(done, assignmentsUi.removeAssignment(data.assignments[0]))
.then(() => {
expect(assignmentsApi.removeAssignment.callCount).toBe(1);
expect(assignmentsApi.removeAssignment.args[0]).toEqual([data.assignments[0]]);

expect(services.notify.success.callCount).toBe(1);
expect(services.notify.success.args[0]).toEqual(['Assignment removed']);

done();
})
).catch(done.fail));

it('Notifies user if removeAssignment fails', (done) => {
restoreSinonStub(assignmentsApi.removeAssignment);
sinon.stub(assignmentsApi, 'removeAssignment').returns(Promise.reject(errorMessage));

return store.test(done, assignmentsUi.removeAssignment(data.assignments[0]))
.then(() => { /* no-op */ }, (error) => {
expect(error).toEqual(errorMessage);

expect(services.notify.error.callCount).toBe(1);
expect(services.notify.error.args[0]).toEqual(['Failed!']);

done();
})
.catch(done.fail);
});
});

describe('openArchivePreview', () => {
beforeEach(() => {
sinon.stub(assignmentsUi, 'closePreview');
Expand Down
3 changes: 0 additions & 3 deletions client/actions/assignments/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,6 @@ const loadDefaultListSort = () => (
* @param {string} priorityPrefix - The prefix for the priority field
* @param {boolean} disableDeskSelection - If true, disables the Desk input field
* @param {boolean} disableUserSelection - If true, disables the User input field
* @param {Function} setCoverageDefaultDesk - Callback function to set default desk for coverages
*/
const showEditCoverageAssignmentModal = ({
field,
Expand All @@ -867,7 +866,6 @@ const showEditCoverageAssignmentModal = ({
priorityPrefix,
disableDeskSelection,
disableUserSelection,
setCoverageDefaultDesk,
}) => (
(dispatch) => {
dispatch(showModal({
Expand All @@ -879,7 +877,6 @@ const showEditCoverageAssignmentModal = ({
priorityPrefix,
disableDeskSelection,
disableUserSelection,
setCoverageDefaultDesk,
},
}));
}
Expand Down
22 changes: 0 additions & 22 deletions client/actions/planning/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,27 +514,6 @@ const saveFromAuthoring = (original, updates) => (
}
);

/**
* Action to update the values of a single Coverage so the Assignment is placed in the workflow
* @param {object} original - Original Planning item
* @param {object} updatedCoverage - Coverage to update (along with any coverage fields to update as well)
* @param {number} index - index of the Coverage in the coverages[] array
*/
const removeAssignment = (original, updatedCoverage, index) => (
(dispatch, getState, {notify}) => {
const updates = {coverages: cloneDeep(original.coverages)};
const coverage = cloneDeep(updatedCoverage);

updates.coverages[index] = coverage;

return dispatch(planningApis.save(original, updates))
.then((savedItem) => {
notify.success(gettext('Removed assignment from coverage.'));
return dispatch(self.updateItemOnSave(savedItem));
});
}
);

const updateItemOnSave = (savedItem) => (
(dispatch) => {
const modifiedItem = planningUtils.modifyForClient(savedItem);
Expand Down Expand Up @@ -575,7 +554,6 @@ const self = {
saveFromAuthoring,
scheduleRefetch,
assignToAgenda,
removeAssignment,
_modifyPlanningFeatured,
modifyPlanningFeatured,
openFeaturedPlanningModal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ describe('assignments', () => {
revertAssignment,
editAssignmentPriority,
startWorking,
removeAssignment,
onDoubleClick,
completeAssignment,
] = Array(7).fill(() => true);
Expand All @@ -58,7 +57,6 @@ describe('assignments', () => {
editAssignmentPriority={editAssignmentPriority}
completeAssignment={completeAssignment}
startWorking={startWorking}
removeAssignment={removeAssignment}
revertAssignment={revertAssignment}
privileges={privileges}
session={session}
Expand Down Expand Up @@ -92,7 +90,6 @@ describe('assignments', () => {
editAssignmentPriority = sinon.spy();
completeAssignment = sinon.spy();
startWorking = sinon.spy();
removeAssignment = sinon.spy();
onDoubleClick = sinon.spy();
revertAssignment = sinon.spy();
});
Expand Down Expand Up @@ -142,64 +139,6 @@ describe('assignments', () => {
'Priority: {{ name }}'
);
});

it('ActionMenu executes prop functions', () => {
const executeItemAction = (actionLabel) => {
const wrapper = getMountedWrapper();
const menu = new helpers.actionMenu(wrapper, true);

menu.invokeAction(actionLabel);
};

lockedItems = null;

expect(reassign.callCount).toBe(0);
executeItemAction('Reassign');
expect(reassign.callCount).toBe(1);
expect(reassign.args[0][0]).toEqual(assignment);

expect(editAssignmentPriority.callCount).toBe(0);
executeItemAction('Edit Priority');
expect(editAssignmentPriority.callCount).toBe(1);
expect(editAssignmentPriority.args[0][0]).toEqual(assignment);

expect(removeAssignment.callCount).toBe(0);
executeItemAction('Remove Assignment');
expect(removeAssignment.callCount).toBe(1);
expect(removeAssignment.args[0][0]).toEqual(assignment);

assignment.assigned_to.state = 'in_progress';
expect(completeAssignment.callCount).toBe(0);
executeItemAction('Complete Assignment');
expect(completeAssignment.callCount).toBe(1);
expect(completeAssignment.args[0][0]).toEqual(assignment);

assignment.assigned_to = {
user: 'ident1',
state: 'assigned',
};
assignment.planning.g2_content_type = 'text';
expect(startWorking.callCount).toBe(0);
executeItemAction('Start Working');
expect(startWorking.callCount).toBe(1);
expect(startWorking.args[0][0]).toEqual(assignment);

assignment.item_ids = ['item1'];
expect(onDoubleClick.callCount).toBe(0);
executeItemAction('Open Coverage');
expect(onDoubleClick.callCount).toBe(1);
expect(onDoubleClick.args[0]).toEqual([assignment]);

assignment.assigned_to = {
user: 'ident1',
state: 'completed',
};
assignment.planning.g2_content_type = 'live_video';
expect(revertAssignment.callCount).toBe(0);
executeItemAction('Revert Availability');
expect(revertAssignment.callCount).toBe(1);
expect(revertAssignment.args[0][0]).toEqual(assignment);
});
});
});
});
7 changes: 5 additions & 2 deletions client/components/Assignments/AssignmentPopup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {gettext} from '../../../utils';
import {ButtonList} from '../../UI';
import {Popup, Header, Footer, Content} from '../../UI/Popup';
import {AssignmentEditor} from '../AssignmentEditor';
import * as actions from '../../../actions';
import {planningApi} from '../../../superdeskApi';

import './style.scss';

Expand Down Expand Up @@ -35,7 +37,9 @@ export class AssignmentPopup extends React.Component {

onSubmit() {
this.props.onChange(this.props.field, this.state.diff);
this.props.setCoverageDefaultDesk(this.state.diff);

planningApi.redux.store.dispatch(actions.users.setCoverageDefaultDesk(this.state.diff));

this.props.onClose();
}

Expand Down Expand Up @@ -131,7 +135,6 @@ AssignmentPopup.propTypes = {
popupContainer: PropTypes.func,
onPopupOpen: PropTypes.func,
onPopupClose: PropTypes.func,
setCoverageDefaultDesk: PropTypes.func,
};

AssignmentPopup.defaultProps = {priorityPrefix: ''};
7 changes: 5 additions & 2 deletions client/components/Assignments/EditCoverageAssignmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import * as selectors from '../../selectors';
import {Modal} from '../';
import {Button} from '../UI';
import {AssignmentEditor} from './AssignmentEditor';
import {planningApi} from '../../superdeskApi';
import * as actions from '../../actions';

export class EditCoverageAssignmentModalComponent extends React.Component {
constructor(props) {
Expand All @@ -36,7 +38,9 @@ export class EditCoverageAssignmentModalComponent extends React.Component {
onSubmit() {
this.setState({submitting: true}, () => {
this.props.modalProps.onChange(this.props.modalProps.field, this.state.diff);
this.props.modalProps.setCoverageDefaultDesk(this.state.diff);

planningApi.redux.store.dispatch(actions.users.setCoverageDefaultDesk(this.state.diff));

this.props.handleHide();
});
}
Expand Down Expand Up @@ -125,7 +129,6 @@ EditCoverageAssignmentModalComponent.propTypes = {
priorityPrefix: PropTypes.string,
disableDeskSelection: PropTypes.bool,
disableUserSelection: PropTypes.bool,
setCoverageDefaultDesk: PropTypes.func,
}),
users: PropTypes.array,
desks: PropTypes.array,
Expand Down
24 changes: 21 additions & 3 deletions client/components/Coverages/CoverageAddAdvancedModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import {connect} from 'react-redux';
import {get} from 'lodash';

import {IG2ContentType, IPlanningCoverageItem, IPlanningNewsCoverageStatus} from '../../interfaces';
Expand All @@ -11,10 +12,17 @@ import {getVocabularyItemFieldTranslated} from '../../utils/vocabularies';
import Modal from '../Modal';
import {SelectInput} from '../UI/Form';
import {superdeskApi} from '../../superdeskApi';
import * as actions from '../../actions';

const isInvalid = (coverage) => coverage.user && !coverage.desk;

interface IProps {
interface IReduxDispatchProps {
setCoverageAddAdvancedMode(enable: boolean): void;
}

type IReduxStateProps = {};

interface IOwnProps {
field: string;
value: Array<DeepPartial<IPlanningCoverageItem>>;
coverageAddAdvancedMode: boolean;
Expand All @@ -25,10 +33,11 @@ interface IProps {

onChange(field: string, value: Array<DeepPartial<IPlanningCoverageItem>>): void;
createCoverage(qcode: IG2ContentType['qcode']): DeepPartial<IPlanningCoverageItem>;
setCoverageAddAdvancedMode(enable: boolean): void;
close(event?: React.MouseEvent): void;
}

type IProps = IOwnProps & IReduxStateProps & IReduxDispatchProps;

interface ICoverageSelector {
id: number;
enabled: boolean;
Expand All @@ -50,7 +59,7 @@ interface IState {
isDirty: boolean;
}

export class CoverageAddAdvancedModal extends React.Component<IProps, IState> {
class CoverageAddAdvancedModalComponent extends React.Component<IProps, IState> {
id: number;

constructor(props) {
Expand Down Expand Up @@ -366,3 +375,12 @@ export class CoverageAddAdvancedModal extends React.Component<IProps, IState> {
);
}
}

const mapDispatchToProps = (dispatch): IReduxDispatchProps => ({
setCoverageAddAdvancedMode: (value) => dispatch(actions.users.setCoverageAddAdvancedMode(value)),
});

export const CoverageAddAdvancedModal = connect<IReduxStateProps, IReduxDispatchProps, IOwnProps>(
null,
mapDispatchToProps
)(CoverageAddAdvancedModalComponent);
Loading

0 comments on commit 9a267f8

Please sign in to comment.