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

fix(react-scheduler): open the AppointmentForm from AllDayPanel #2583

Merged
merged 3 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 36 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 @@ -348,6 +348,42 @@ describe('AppointmentForm', () => {
.toBeTruthy();
});

it('should render cell template', () => {
const tree = mount((
<PluginHost>
{pluginDepsToComponents(defaultDeps)}
<AppointmentForm
{...defaultProps}
/>
</PluginHost>
));

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

expect(templatePlaceholder.exists())
.toBeTruthy();
});

it('should render allDayCell template', () => {
const tree = mount((
<PluginHost>
{pluginDepsToComponents(defaultDeps)}
<AppointmentForm
{...defaultProps}
/>
</PluginHost>
));

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

expect(templatePlaceholder.exists())
.toBeTruthy();
});

it('should provide toggleAppointmentFormVisibility action', () => {
const tree = mount((
<PluginHost>
Expand Down
54 changes: 34 additions & 20 deletions packages/dx-react-scheduler/src/plugins/appointment-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ import {
AppointmentFormProps, AppointmentFormState, AppointmentTooltip, Appointments,
} from '../types';

const addDoubleClickToCell = (
title, startDate, endDate, allDay, openFormHandler, addAppointment, params,
) => {
const newAppointmentData = { title, startDate, endDate, allDay };
return (
<TemplatePlaceholder
params={{
...params,
onDoubleClick: () => {
openFormHandler(newAppointmentData);
callActionIfExists(addAppointment,
{ appointmentData: newAppointmentData });
},
}}
/>
);
};

const defaultMessages = {
allDayLabel: 'All Day',
titleLabel: 'Title',
Expand Down Expand Up @@ -506,26 +524,22 @@ class AppointmentFormBase extends React.PureComponent<AppointmentFormProps, Appo
<Template name="cell">
{(params: any) => (
<TemplateConnector>
{(getters, { addAppointment }) => {
const newAppointmentData = {
title: undefined,
startDate: params.startDate,
endDate: params.endDate,
allDay: isAllDayCell(params.startDate, params.endDate),
};
return (
<TemplatePlaceholder
params={{
...params,
onDoubleClick: () => {
this.openFormHandler(newAppointmentData);
callActionIfExists(addAppointment,
{ appointmentData: newAppointmentData });
},
}}
/>
);
}}
{(getters, { addAppointment }) => addDoubleClickToCell(
undefined, params.startDate, params.endDate,
isAllDayCell(params.startDate, params.endDate),
this.openFormHandler, addAppointment, params,
)}
</TemplateConnector>
)}
</Template>

<Template name="allDayPanelCell">
{(params: any) => (
<TemplateConnector>
{(getters, { addAppointment }) => addDoubleClickToCell(
undefined, params.startDate, params.endDate,
true, this.openFormHandler, addAppointment, params,
)}
</TemplateConnector>
)}
</Template>
Expand Down