Skip to content

Commit

Permalink
fix(react-scheduler): make it possible to create an appointment after…
Browse files Browse the repository at this point in the history
… cancelled drag-drop (#2307)
  • Loading branch information
AryamnovEugeniy authored Sep 11, 2019
1 parent d3d1df7 commit b666250
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const Layout = React.memo(({
);

const onCommitButtonClick = () => {
handleClose();
commit(currentValue);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe('EditRecurrenceMenu', () => {
action: {
commitChangedAppointment: jest.fn(),
commitDeletedAppointment: jest.fn(),
cancelChangedAppointment: jest.fn(),
stopEditAppointment: jest.fn(),
},
};
const defaultProps = {
Expand Down Expand Up @@ -159,4 +161,21 @@ describe('EditRecurrenceMenu', () => {
expect(defaultDeps.action.commitDeletedAppointment)
.toBeCalled();
});
it('should cancel appointment editing', () => {
const tree = mount((
<PluginHost>
{pluginDepsToComponents(defaultDeps, { getter: {} })}
<EditRecurrenceMenu
{...defaultProps}
/>
</PluginHost>
));

tree.find(defaultProps.layoutComponent).prop('handleClose')();

expect(defaultDeps.action.cancelChangedAppointment)
.toBeCalled();
expect(defaultDeps.action.stopEditAppointment)
.toBeCalled();
});
});
24 changes: 19 additions & 5 deletions packages/dx-react-scheduler/src/plugins/edit-recurrence-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,25 @@ class EditRecurrenceMenuBase extends React.PureComponent<
}
}

commit = memoize((editAction, deleteAction, payload) => {
commit = memoize((editAction, deleteAction, payload) => (type) => {
if (payload) {
return type => deleteAction({ deletedAppointmentData: payload, type });
deleteAction({ deletedAppointmentData: payload, type });
} else {
editAction(type);
}
return type => editAction(type);
this.closeMenu();
});

closeMenu = () => {
this.setState({ isOpen: false, deletedAppointmentData: null });
}

cancelEditing = memoize((cancelAction, stopEditAction) => () => {
stopEditAction();
cancelAction();
this.closeMenu();
});

availableOperations = memoize((getMessage, menuAvailableOperations) =>
menuAvailableOperations.map(({ value }) => ({
value,
Expand Down Expand Up @@ -120,10 +128,16 @@ class EditRecurrenceMenuBase extends React.PureComponent<

<Template name="overlay">
<TemplateConnector>
{(getters, { commitChangedAppointment, commitDeletedAppointment }) => {
{(getters, {
commitChangedAppointment, commitDeletedAppointment,
cancelChangedAppointment, stopEditAppointment,
}) => {
const commit = this.commit(
commitChangedAppointment, commitDeletedAppointment, deletedAppointmentData,
);
const cancelEditing = this.cancelEditing(
cancelChangedAppointment, stopEditAppointment,
);

return (
<Overlay
Expand All @@ -134,7 +148,7 @@ class EditRecurrenceMenuBase extends React.PureComponent<
<Layout
isDeleting={!!deletedAppointmentData}
buttonComponent={buttonComponent}
handleClose={this.closeMenu}
handleClose={cancelEditing}
commit={commit}
availableOperations={availableOperations}
getMessage={getMessage}
Expand Down

0 comments on commit b666250

Please sign in to comment.