Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react-scheduler): do not show AppointmentForm's Delete Button if a new appointment is being edited #2462

Merged
merged 6 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const LayoutBase = ({
fullSize,
readOnly,
disableSaveButton,
hideDeleteButton,
...restProps
}) => (
<Grid
Expand All @@ -86,12 +87,16 @@ const LayoutBase = ({
/>
{!readOnly && (
<>
<CommandButton
onExecute={onDeleteButtonClick}
getMessage={getMessage}
id={DELETE_BUTTON}
/>
<div className={classes.line} />
{!hideDeleteButton && (
<>
<CommandButton
onExecute={onDeleteButtonClick}
getMessage={getMessage}
id={DELETE_BUTTON}
/>
<div className={classes.line} />
</>
)}
<CommandButton
getMessage={getMessage}
disabled={disableSaveButton}
Expand All @@ -116,6 +121,7 @@ LayoutBase.propTypes = {
readOnly: PropTypes.bool,
children: PropTypes.node,
disableSaveButton: PropTypes.bool,
hideDeleteButton: PropTypes.bool,
};

LayoutBase.defaultProps = {
Expand All @@ -124,6 +130,7 @@ LayoutBase.defaultProps = {
fullSize: false,
readOnly: false,
disableSaveButton: false,
hideDeleteButton: false,
};

export const Layout = withStyles(styles)(LayoutBase, { name: 'Layout' });
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ describe('AppointmentForm command', () => {
.toEqual(CANCEL_BUTTON);
});

it('shouldn\'t render Delete Button if hideDeleteButton prop is true', () => {
const tree = shallow((
<Layout {...defaultProps} hideDeleteButton />
));

const buttons = tree.find(defaultProps.commandButtonComponent);
expect(buttons).toHaveLength(2);
expect(buttons.at(0).prop('id'))
.toEqual(CANCEL_BUTTON);
expect(buttons.at(1).prop('id'))
.toEqual(SAVE_BUTTON);
});

it('should call onCommitButtonClick', () => {
const tree = shallow((
<Layout {...defaultProps} />
Expand Down
1 change: 1 addition & 0 deletions packages/dx-react-scheduler/api/dx-react-scheduler.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export namespace AppointmentForm {
disableSaveButton?: boolean;
fullSize: boolean;
getMessage: (messageKey: string) => string;
hideDeleteButton?: boolean;
onCancelButtonClick: () => void;
onCommitButtonClick: () => void;
onDeleteButtonClick: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Field | Type | Description
readOnly? | boolean | Specifies whether the appointment form is read-only.
fullSize | boolean | Specifies whether the command layout is full-size.
disableSaveButton? | boolean | Specifies whether to disable the Save button.
hideDeleteButton? | boolean | Specifies whether to hide the Delete button.
onCommitButtonClick | () => void | An event raised when the Commit button is clicked. The event handler should commit appointment changes.
onCancelButtonClick | () => void | An event raised when the Cancel button is clicked. The event handler should close the appointment form.
onDeleteButtonClick | () => void | An event raised when the Delete button is clicked. The event handler should delete an appointment.
Expand Down
35 changes: 35 additions & 0 deletions packages/dx-react-scheduler/src/plugins/appointment-form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ describe('AppointmentForm', () => {
onDeleteButtonClick: expect.any(Function),
readOnly: false,
disableSaveButton: false,
hideDeleteButton: false,
});
});

Expand All @@ -203,6 +204,40 @@ describe('AppointmentForm', () => {
expect(tree.find(defaultProps.commandLayoutComponent).prop('fullSize'))
.toBeTruthy();
});

it('should hide delete button if a new appointment is being edited', () => {
const tree = mount((
<PluginHost>
{pluginDepsToComponents({
...defaultDeps,
getter: { ...defaultDeps.getter, editingAppointment: undefined },
})}
<AppointmentForm
{...defaultProps}
/>
</PluginHost>
));

const templatePlaceholder = tree
.find(Template)
.filterWhere(node => node.props().name === 'commandLayout');

const commandLayoutComponent = tree.find(defaultProps.commandLayoutComponent);
expect(commandLayoutComponent.exists())
.toBeTruthy();
expect(commandLayoutComponent.props())
.toMatchObject({
commandButtonComponent: defaultProps.commandButtonComponent,
fullSize: false,
getMessage: expect.any(Function),
onCancelButtonClick: expect.any(Function),
onCommitButtonClick: expect.any(Function),
onDeleteButtonClick: expect.any(Function),
readOnly: false,
disableSaveButton: false,
hideDeleteButton: true,
});
});
});

it('should render BasicLayout', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class AppointmentFormBase extends React.PureComponent<AppointmentFormProps, Appo
readOnly={readOnly}
fullSize={isRecurrence}
disableSaveButton={!isFormEdited}
hideDeleteButton={isNew}
/>
);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ export namespace AppointmentForm {
readOnly?: boolean;
/** Specifies whether the command layout is full-size. */
fullSize: boolean;
/** Specifies whether to disable the SaveButton. */
/** Specifies whether to disable the Save button. */
disableSaveButton?: boolean;
/** Specifies whether to hide the Delete button. */
hideDeleteButton?: boolean;
/** An event raised when the Commit button is clicked. The event handler should commit an appointment changes. */
onCommitButtonClick: () => void;
/** An event raised when the Cancel button is clicked. The event handler should close the appointment form. */
Expand Down