Skip to content

Commit

Permalink
feat(react-scheduler): add ConfirmationDialog plugin (#2393)
Browse files Browse the repository at this point in the history
  • Loading branch information
AryamnovEugeniy committed Oct 24, 2019
1 parent 6bdc739 commit 9041bd5
Show file tree
Hide file tree
Showing 36 changed files with 1,451 additions and 227 deletions.
Expand Up @@ -9,6 +9,7 @@ import {
WeekView,
EditRecurrenceMenu,
AllDayPanel,
ConfirmationDialog,
} from '@devexpress/dx-react-scheduler-material-ui';
import { appointments } from '../../../demo-data/appointments';

Expand Down Expand Up @@ -92,6 +93,7 @@ export default class Demo extends React.PureComponent {
/>
<AllDayPanel />
<EditRecurrenceMenu />
<ConfirmationDialog />
<Appointments />
<AppointmentTooltip
showOpenButton
Expand Down
@@ -0,0 +1,113 @@
/* eslint-disable react/no-unused-state */
import * as React from 'react';
import Paper from '@material-ui/core/Paper';
import { ViewState, EditingState, IntegratedEditing } from '@devexpress/dx-react-scheduler';
import {
Scheduler,
Appointments,
AppointmentTooltip,
WeekView,
DragDropProvider,
} from '@devexpress/dx-react-scheduler-material-ui';
import { appointments } from '../../../demo-data/appointments';

const SHIFT_KEY = 16;

export default class Demo extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
data: appointments,
currentDate: '2018-06-27',
isShiftPressed: false,
};

this.commitChanges = this.commitChanges.bind(this);
this.onKeyDown = this.onKeyDown.bind(this);
this.onKeyUp = this.onKeyUp.bind(this);
}

componentDidMount() {
window.addEventListener('keydown', this.onKeyDown);
window.addEventListener('keyup', this.onKeyUp);
}

componentWillUnmount() {
window.removeEventListener('keydown');
window.removeEventListener('keyup');
}

onKeyDown(event) {
if (event.keyCode === SHIFT_KEY) {
this.setState({ isShiftPressed: true });
}
}

onKeyUp(event) {
if (event.keyCode === SHIFT_KEY) {
this.setState({ isShiftPressed: false });
}
}

commitChanges({ added, changed, deleted }) {
this.setState((state) => {
let { data } = state;
const { isShiftPressed } = this.state;
if (added) {
const startingAddedId = data.length > 0 ? data[data.length - 1].id + 1 : 0;
data = [...data, { id: startingAddedId, ...added }];
}
if (changed) {
if (isShiftPressed) {
const changedAppointment = data.find(appointment => changed[appointment.id]);
const startingAddedId = data.length > 0 ? data[data.length - 1].id + 1 : 0;
data = [
...data,
{ ...changedAppointment, id: startingAddedId, ...changed[changedAppointment.id] },
];
} else {
data = data.map(appointment => (
changed[appointment.id]
? { ...appointment, ...changed[appointment.id] }
: appointment));
}
}
if (deleted !== undefined) {
data = data.filter(appointment => appointment.id !== deleted);
}
return { data };
});
}

render() {
const { currentDate, data } = this.state;

return (
<Paper>
<Scheduler
data={data}
height={660}
>
<ViewState
currentDate={currentDate}
/>
<EditingState
onCommitChanges={this.commitChanges}
/>
<IntegratedEditing />

<WeekView
startDayHour={9}
endDayHour={17}
/>
<Appointments />
<AppointmentTooltip
showOpenButton
showDeleteButton
/>
<DragDropProvider />
</Scheduler>
</Paper>
);
}
}
@@ -1,4 +1,3 @@
/* eslint-disable react/no-unused-state */
import * as React from 'react';
import Paper from '@material-ui/core/Paper';
import { ViewState, EditingState, IntegratedEditing } from '@devexpress/dx-react-scheduler';
Expand All @@ -8,71 +7,19 @@ import {
Appointments,
AppointmentForm,
AppointmentTooltip,
ConfirmationDialog,
} from '@devexpress/dx-react-scheduler-material-ui';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogContentText from '@material-ui/core/DialogContentText';
import DialogTitle from '@material-ui/core/DialogTitle';
import Button from '@material-ui/core/Button';
import { appointments } from '../../../demo-data/appointments';

const DeleteConfirmationDialog = ({
visible, onCancel, onCommit,
}) => (
<Dialog
open={visible}
>
<DialogTitle>
Delete Appointment
</DialogTitle>
<DialogContent>
<DialogContentText>
Are you sure you want to delete this appointment?
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={onCancel} color="primary">
Cancel
</Button>
<Button onClick={onCommit} color="secondary">
Delete
</Button>
</DialogActions>
</Dialog>
);

export default class Demo extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
data: appointments,
currentDate: '2018-06-27',
deletedAppointmentId: null,
confirmationVisibility: false,
};

this.commitChanges = this.commitChanges.bind(this);
this.toggleConfirmationVisibility = this.toggleConfirmationVisibility.bind(this);
this.commitDeletedAppointment = this.commitDeletedAppointment.bind(this);
}

setDeletedAppointmentId(deletedAppointmentId) {
this.setState({ deletedAppointmentId });
}

toggleConfirmationVisibility() {
const { confirmationVisibility } = this.state;
this.setState({ confirmationVisibility: !confirmationVisibility });
}

commitDeletedAppointment() {
this.setState((state) => {
const { data, deletedAppointmentId } = state;
const nextData = data.filter(appointment => appointment.id !== deletedAppointmentId);
this.toggleConfirmationVisibility();
return { data: nextData, deletedAppointmentId: null };
});
}

commitChanges({ added, changed, deleted }) {
Expand All @@ -87,15 +34,14 @@ export default class Demo extends React.PureComponent {
changed[appointment.id] ? { ...appointment, ...changed[appointment.id] } : appointment));
}
if (deleted !== undefined) {
this.setDeletedAppointmentId(deleted);
this.toggleConfirmationVisibility();
data = data.filter(appointment => appointment.id !== deleted);
}
return { data };
});
}

render() {
const { currentDate, data, confirmationVisibility } = this.state;
const { currentDate, data } = this.state;

return (
<Paper>
Expand All @@ -116,18 +62,15 @@ export default class Demo extends React.PureComponent {
endDayHour={17}
/>
<Appointments />
<ConfirmationDialog
ignoreCancel
/>
<AppointmentTooltip
showOpenButton
showDeleteButton
/>
<AppointmentForm />
</Scheduler>

<DeleteConfirmationDialog
visible={confirmationVisibility}
onCancel={this.toggleConfirmationVisibility}
onCommit={this.commitDeletedAppointment}
/>
</Paper>
);
}
Expand Down
Expand Up @@ -7,6 +7,7 @@ import {
Appointments,
AppointmentForm,
AppointmentTooltip,
ConfirmationDialog,
} from '@devexpress/dx-react-scheduler-material-ui';

import { appointments } from '../../../demo-data/appointments';
Expand Down Expand Up @@ -99,6 +100,7 @@ export default class Demo extends React.PureComponent {
showOpenButton
showDeleteButton
/>
<ConfirmationDialog />
<AppointmentForm
basicLayoutComponent={BasicLayout}
textEditorComponent={TextEditor}
Expand Down
Expand Up @@ -7,6 +7,7 @@ import {
Appointments,
AppointmentForm,
AppointmentTooltip,
ConfirmationDialog,
} from '@devexpress/dx-react-scheduler-material-ui';

import { appointments } from '../../../demo-data/appointments';
Expand Down Expand Up @@ -60,6 +61,7 @@ export default class Demo extends React.PureComponent {
startDayHour={9}
endDayHour={19}
/>
<ConfirmationDialog />
<Appointments />
<AppointmentTooltip
showOpenButton
Expand Down
Expand Up @@ -10,6 +10,7 @@ import { AppointmentMeta } from '@devexpress/dx-react-scheduler';
import { AppointmentModel } from '@devexpress/dx-react-scheduler';
import { Appointments as Appointments_2 } from '@devexpress/dx-react-scheduler';
import { AppointmentTooltip as AppointmentTooltip_2 } from '@devexpress/dx-react-scheduler';
import { ConfirmationDialog as ConfirmationDialog_2 } from '@devexpress/dx-react-scheduler';
import { DateNavigator as DateNavigator_2 } from '@devexpress/dx-react-scheduler';
import { DayView as DayView_2 } from '@devexpress/dx-react-scheduler';
import { DragDropProvider as DragDropProvider_2 } from '@devexpress/dx-react-scheduler';
Expand Down Expand Up @@ -262,6 +263,38 @@ export interface AppointmentTooltipProps {
visible?: boolean;
}

// @public (undocumented)
export namespace ConfirmationDialog {
export type LayoutProps = ConfirmationDialog_2.LayoutProps;
}

// @public (undocumented)
export namespace ConfirmationDialog {
export type OverlayProps = ConfirmationDialog_2.OverlayProps;
}

// @public (undocumented)
export namespace ConfirmationDialog {
export type ButtonProps = ConfirmationDialog_2.ButtonProps;
}

// @public
export const ConfirmationDialog: React.ComponentType<ConfirmationDialogProps> & {
Layout: React.ComponentType<ConfirmationDialog_2.LayoutProps & { className?: string; style?: React.CSSProperties; [x: string]: any }>;
Overlay: React.ComponentType<ConfirmationDialog_2.OverlayProps & { className?: string; style?: React.CSSProperties; [x: string]: any }>;
Button: React.ComponentType<ConfirmationDialog_2.ButtonProps & { className?: string; style?: React.CSSProperties; [x: string]: any }>;
};

// @public (undocumented)
export interface ConfirmationDialogProps {
buttonComponent?: React.ComponentType<ConfirmationDialog_2.ButtonProps>;
ignoreCancel?: boolean;
ignoreDelete?: boolean;
layoutComponent?: React.ComponentType<ConfirmationDialog_2.LayoutProps>;
messages?: React.ComponentType<ConfirmationDialog_2.LocalizationMessages>;
overlayComponent?: React.ComponentType<ConfirmationDialog_2.OverlayProps>;
}

// @public (undocumented)
export namespace DateNavigator {
export type RootProps = DateNavigator_2.RootProps;
Expand Down Expand Up @@ -452,7 +485,7 @@ export const EditRecurrenceMenu: React.ComponentType<EditRecurrenceMenuProps> &
export interface EditRecurrenceMenuProps {
buttonComponent?: React.ComponentType<EditRecurrenceMenu_2.ButtonProps>;
layoutComponent?: React.ComponentType<EditRecurrenceMenu_2.LayoutProps>;
messages?: React.ComponentType<EditRecurrenceMenu_2.LocalizationMessages>;
messages?: EditRecurrenceMenu_2.LocalizationMessages;
overlayComponent?: React.ComponentType<EditRecurrenceMenu_2.OverlayProps>;
}

Expand Down
1 change: 1 addition & 0 deletions packages/dx-react-scheduler-material-ui/src/index.js
Expand Up @@ -12,3 +12,4 @@ export * from './plugins/appointment-form';
export * from './plugins/drag-drop-provider';
export * from './plugins/today-button';
export * from './plugins/edit-recurrence-menu';
export * from './plugins/confirmation-dialog';
Expand Up @@ -13,7 +13,7 @@ import { Select } from '../templates/common/select/select';
import { Layout as RecurrenceLayout } from '../templates/appointment-form/recurrence/layout';
import { RadioGroup } from '../templates/appointment-form/recurrence/radio-group/radio-group';
import { WeeklyRecurrenceSelector } from '../templates/appointment-form/recurrence/weekly-recurrence-selector';
import { Container } from '../templates/appointment-form/container';
import { OverlayContainer as Container } from '../templates/common/overlay-container';

export const AppointmentForm = withComponents({
Overlay,
Expand Down
@@ -0,0 +1,10 @@
import { withComponents } from '@devexpress/dx-react-core';
import { ConfirmationDialog as ConfirmationDialogBase } from '@devexpress/dx-react-scheduler';
import { Overlay } from '../templates/common/dialog/overlay';
import { Layout } from '../templates/confirmation-dialog/layout';
import { OverlayContainer as Container } from '../templates/common/overlay-container';
import { Button } from '../templates/common/dialog/button';

export const ConfirmationDialog = withComponents({
Overlay, Layout, Container, Button,
})(ConfirmationDialogBase);
@@ -1,9 +1,9 @@
import { withComponents } from '@devexpress/dx-react-core';
import { EditRecurrenceMenu as EditRecurrenceMenuBase } from '@devexpress/dx-react-scheduler';
import { Overlay } from '../templates/edit-recurrence-menu/overlay';
import { Overlay } from '../templates/common/dialog/overlay';
import { Layout } from '../templates/edit-recurrence-menu/layout';
import { Button } from '../templates/edit-recurrence-menu/button';
import { Container } from '../templates/edit-recurrence-menu/container';
import { Button } from '../templates/common/dialog/button';
import { OverlayContainer as Container } from '../templates/common/overlay-container';

export const EditRecurrenceMenu = withComponents({
Layout, Overlay, Button, Container,
Expand Down

0 comments on commit 9041bd5

Please sign in to comment.