Skip to content

Commit

Permalink
Merge pull request #1171 from MarkLark86/SDESK-4131
Browse files Browse the repository at this point in the history
[SDESK-4131] Show 'Ignore/Cancel/Save' dialog for 'UpdateRepetitions' action
  • Loading branch information
Mayur Dhamanwala committed Apr 8, 2019
2 parents 9b3d0b9 + fe12751 commit c0e0903
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 34 deletions.
38 changes: 20 additions & 18 deletions client/actions/events/tests/ui_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,16 @@ describe('actions.events.ui', () => {
}]);
});

it('openRepetitionsModal calls `_openActionModal`', (done) => (
store.test(done, eventsUi.openRepetitionsModal(data.events[1]))
.then(() => {
expect(eventsUi._openActionModal.callCount).toBe(1);
expect(eventsUi._openActionModal.args[0]).toEqual([
data.events[1],
{},
'Update Repetitions',
'update_repetitions',
]);
it('openRepetitionsModal calls `_openActionModalFromEditor`', () => {
eventsUi.openRepetitionsModal(data.events[1]);

done();
})
).catch(done.fail));
expect(eventsUi._openActionModalFromEditor.callCount).toBe(1);
expect(eventsUi._openActionModalFromEditor.args[0]).toEqual([{
event: data.events[1],
action: EVENTS.ITEM_ACTIONS.UPDATE_REPETITIONS,
title: 'Save changes before updating Event Repetitions?',
}]);
});

describe('openActionModal', () => {
beforeEach(() => {
Expand Down Expand Up @@ -448,13 +444,14 @@ describe('actions.events.ui', () => {
const daysBetween = moment().diff(data.events[0].dates.start, 'days');
const newStartDate = data.events[0].dates.start.add(daysBetween, 'days');
const newEndDate = data.events[0].dates.end.add(daysBetween, 'days');
const args = main.createNew.args[0];

expect(main.createNew.callCount).toBe(1);
expect(main.createNew.args[0]).toEqual([ITEM_TYPE.EVENT, {
expect(args).toEqual([ITEM_TYPE.EVENT, {
...omit(data.events[0], ['_id', '_etag', 'planning_ids']),
dates: {
start: newStartDate,
end: newEndDate,
start: jasmine.any(moment),
end: jasmine.any(moment),
tz: 'Australia/Sydney',
},
duplicate_from: 'e1',
Expand All @@ -466,9 +463,14 @@ describe('actions.events.ui', () => {
},
files: ['file1_id'],
links: ['http://www.google.com'],
_startTime: newStartDate,
_endTime: newEndDate,
_startTime: jasmine.any(moment),
_endTime: jasmine.any(moment),
}]);

expect(args[1].dates.start.format()).toEqual(newStartDate.format());
expect(args[1].dates.end.format()).toEqual(newEndDate.format());
expect(args[1]._startTime.format()).toEqual(newStartDate.format());
expect(args[1]._endTime.format()).toEqual(newEndDate.format());
});
});

Expand Down
24 changes: 16 additions & 8 deletions client/actions/events/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,22 @@ const convertToRecurringEvent = (event, post) => (
))
);

const openRepetitionsModal = (event) => (
(dispatch) => dispatch(self._openActionModal(
event,
{},
EVENTS.ITEM_ACTIONS.UPDATE_REPETITIONS.label,
EVENTS.ITEM_ACTIONS.UPDATE_REPETITIONS.lock_action
))
);
const openRepetitionsModal = (event, fromEditor = true) => {
if (fromEditor) {
return self._openActionModalFromEditor({
event: event,
action: EVENTS.ITEM_ACTIONS.UPDATE_REPETITIONS,
title: gettext('Save changes before updating Event Repetitions?'),
});
} else {
return self._openActionModal(
event,
{},
EVENTS.ITEM_ACTIONS.UPDATE_REPETITIONS.label,
EVENTS.ITEM_ACTIONS.UPDATE_REPETITIONS.lock_action
);
}
};

const rescheduleEvent = (original, updates) => (
(dispatch, getState, {notify}) => (
Expand Down
9 changes: 7 additions & 2 deletions client/actions/planning/featuredPlanning.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,13 @@ const fetchToList = (params = {}, append = false) => (
return dispatch(planningApi.query(
params,
false,
getTimeZoneOffset(momentTz.tz(moment(), selectors.config.defaultTimeZone(getState()))))
)
getTimeZoneOffset(
momentTz.tz(
get(params, 'advancedSearch.dates.start') || moment(),
selectors.config.defaultTimeZone(getState())
)
)
))
.then((data) => {
dispatch(self.total(data.total));
dispatch(self.receivePlannings(data._items, append));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export class UpdateEventRepetitionsComponent extends React.Component {
submit() {
return this.props.onSubmit(
this.props.original,
this.state.diff
this.state.diff,
get(this.props, 'modalProps') || {}
);
}

Expand Down Expand Up @@ -133,6 +134,8 @@ UpdateEventRepetitionsComponent.propTypes = {
onValidate: PropTypes.func,
formProfiles: PropTypes.object,
submitting: PropTypes.bool,
onHide: PropTypes.func,
modalProps: PropTypes.object,
};

const mapStateToProps = (state) => ({
Expand All @@ -141,7 +144,7 @@ const mapStateToProps = (state) => ({
});

const mapDispatchToProps = (dispatch) => ({
onSubmit: (original, updates) => {
onSubmit: (original, updates, modalProps) => {
let newUpdates = cloneDeep(updates);

if (get(event, 'dates.recurring_rule.until')) {
Expand All @@ -152,14 +155,26 @@ const mapDispatchToProps = (dispatch) => ({
).endOf('day');
}

return dispatch(
const promise = dispatch(
actions.events.ui.updateRepetitions(original, newUpdates)
);

if (get(modalProps, 'onCloseModal')) {
promise.then((updatedEvent) => modalProps.onCloseModal(updatedEvent));
}

return promise;
},
onHide: (event) => {
if (event.lock_action === EVENTS.ITEM_ACTIONS.UPDATE_REPETITIONS.lock_action) {
dispatch(actions.events.api.unlock(event));
onHide: (event, modalProps) => {
const promise = event.lock_action === EVENTS.ITEM_ACTIONS.UPDATE_REPETITIONS.lock_action ?
dispatch(actions.events.api.unlock(event)) :
Promise.resolve(event);

if (get(modalProps, 'onCloseModal')) {
promise.then((updatedEvent) => modalProps.onCloseModal(updatedEvent));
}

return promise;
},
onValidate: (item, profile, errors, errorMessages) => dispatch(validateItem({
profileName: ITEM_TYPE.EVENT,
Expand Down
7 changes: 7 additions & 0 deletions client/components/Main/ItemEditor/EditorItemActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ export const EditorItemActions = ({
),
[EVENTS.ITEM_ACTIONS.CONVERT_TO_RECURRING.actionName]:
itemActions[EVENTS.ITEM_ACTIONS.CONVERT_TO_RECURRING.actionName].bind(null, item),
[EVENTS.ITEM_ACTIONS.UPDATE_REPETITIONS.actionName]:
() => (
autoSave.flushAutosave()
.then(() => (
itemActions[EVENTS.ITEM_ACTIONS.UPDATE_REPETITIONS.actionName](item)
))
),
};
actions = eventUtils.getEventActions({
item,
Expand Down

0 comments on commit c0e0903

Please sign in to comment.