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

Improve drawer animation of review edition in Posters Galore demo #2945

Merged
merged 2 commits into from
Apr 2, 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
97 changes: 62 additions & 35 deletions examples/demo/src/reviews/ReviewList.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { Fragment, Component } from 'react';
import compose from 'recompose/compose';
import classnames from 'classnames';
import { BulkDeleteButton, List, Responsive } from 'react-admin';
import { connect } from 'react-redux';
import { push } from 'react-router-redux';
import { Route } from 'react-router';
import Drawer from '@material-ui/core/Drawer';

import { createStyles, withStyles } from '@material-ui/core/styles';
import BulkAcceptButton from './BulkAcceptButton';
import BulkRejectButton from './BulkRejectButton';
import ReviewListMobile from './ReviewListMobile';
Expand All @@ -20,49 +22,74 @@ const ReviewsBulkActionButtons = props => (
</Fragment>
);

const styles = theme => createStyles({
root: {
display: 'flex',
},
list: {
flexGrow: 1,
transition: theme.transitions.create(['all'], {
duration: theme.transitions.duration.enteringScreen,
}),
marginRight: 0,
},
listWithDrawer: {
marginRight: 400,
},
});

class ReviewList extends Component {
render() {
const props = this.props;
const { classes, ...props } = this.props;
return (
<Fragment>
<List
{...props}
bulkActionButtons={<ReviewsBulkActionButtons />}
filters={<ReviewFilter />}
perPage={25}
sort={{ field: 'date', order: 'DESC' }}
>
<Responsive
xsmall={<ReviewListMobile />}
medium={<ReviewListDesktop />}
/>
</List>
<div className={classes.root}>
<Route path="/reviews/:id">
{({ match }) => {
const isMatch =
match &&
!!(match &&
match.params &&
match.params.id !== 'create';
match.params.id !== 'create');

return (
<Drawer
variant="persistent"
open={isMatch}
anchor="right"
onClose={this.handleClose}
>
{/* To avoid any errors if the route does not match, we don't render at all the component in this case */}
{isMatch ? (
<ReviewEdit
id={match.params.id}
onCancel={this.handleClose}
{...props}
<Fragment>
<List
{...props}
className={classnames(classes.list, {
[classes.listWithDrawer]: isMatch
})}
bulkActionButtons={<ReviewsBulkActionButtons />}
filters={<ReviewFilter />}
perPage={25}
sort={{ field: 'date', order: 'DESC' }}
>
<Responsive
xsmall={<ReviewListMobile />}
medium={<ReviewListDesktop />}
/>
) : null}
</Drawer>
</List>
<Drawer
variant="persistent"
open={isMatch}
anchor="right"
onClose={this.handleClose}
classes={{
paper: classes.drawerPaper
}}
>
{/* To avoid any errors if the route does not match, we don't render at all the component in this case */}
{isMatch ? (
<ReviewEdit
id={match.params.id}
onCancel={this.handleClose}
{...props}
/>
) : null}
</Drawer>
</Fragment>
);
}}
</Route>
</Fragment>
</div>
);
}

Expand All @@ -71,7 +98,7 @@ class ReviewList extends Component {
};
}

export default connect(
undefined,
{ push }
export default compose(
connect(undefined, { push }),
withStyles(styles)
)(ReviewList);
2 changes: 2 additions & 0 deletions packages/ra-core/src/controller/ListController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ interface Props {
path?: string;
query: ListParams;
resource: string;
[key: string]: any;
}
interface EnhancedProps {
changeListParams: Dispatch<typeof changeListParamsAction>;
Expand Down Expand Up @@ -229,6 +230,7 @@ export class UnconnectedListController extends Component<

shouldComponentUpdate(nextProps: Props & EnhancedProps, nextState) {
if (
nextProps.className === this.props.className &&
nextProps.translate === this.props.translate &&
nextProps.isLoading === this.props.isLoading &&
nextProps.version === this.props.version &&
Expand Down