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

[WIP] makeStyles and functional components #3461

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fc223ec
makeStyles for functional components
MohammedFaragallah Jul 25, 2019
1faad93
removed createStyles
MohammedFaragallah Jul 25, 2019
f0fe0c7
fixes failing test
MohammedFaragallah Jul 25, 2019
a68ab7c
Merge branch 'next' into useStyles
MohammedFaragallah Jul 25, 2019
f165d35
merge
MohammedFaragallah Jul 26, 2019
0fe39fc
class => functional components / use makeStyles
MohammedFaragallah Jul 26, 2019
4e6c658
fix tests
MohammedFaragallah Jul 26, 2019
1cea7c2
ra-tree-ui-materialui DragLayer
MohammedFaragallah Jul 26, 2019
b2437c6
ra-tree-ui-materialui DragPreview/NodeForm
MohammedFaragallah Jul 26, 2019
1b912c4
ra-tree-ui-materialui RootDropTarget/tree
MohammedFaragallah Jul 26, 2019
651c638
prevent firing ra-tree-ui-materialui/Tree useEffect after every update
MohammedFaragallah Jul 26, 2019
34bb6c3
convert TreeNodeContent/TreeNodeWithChildren
MohammedFaragallah Jul 26, 2019
ad0516a
Merge branch 'next' of https://github.com/marmelab/react-admin into u…
MohammedFaragallah Jul 26, 2019
28ecd0a
makeStyles typescript components
MohammedFaragallah Jul 26, 2019
fd60887
class => functional components
MohammedFaragallah Jul 27, 2019
2b23e4d
FileInputPreview/SingleFieldList
MohammedFaragallah Jul 27, 2019
4e1cca9
SimpleFormIterator
MohammedFaragallah Jul 27, 2019
2d16633
makeStyles TabbedForm
MohammedFaragallah Jul 27, 2019
db7c638
save
MohammedFaragallah Jul 28, 2019
50f69fc
Merge branch 'next' of https://github.com/marmelab/react-admin into u…
MohammedFaragallah Jul 30, 2019
60f87af
Merge branch 'next' of https://github.com/marmelab/react-admin into u…
MohammedFaragallah Jul 31, 2019
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
46 changes: 22 additions & 24 deletions packages/ra-tree-ui-materialui/src/NodeActions.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
import React, { cloneElement, Children, Component } from 'react';
import React, { cloneElement, Children } from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import { makeStyles } from '@material-ui/core/styles';

const styles = theme => ({
const useStyles = makeStyles(theme => ({
root: {
alignItems: 'center',
marginLeft: 'auto',
marginRight: theme.spacing(4),
},
});
}));

export class NodeActions extends Component {
static propTypes = {
classes: PropTypes.object.isRequired,
basePath: PropTypes.string.isRequired,
children: PropTypes.node,
record: PropTypes.object.isRequired,
resource: PropTypes.string.isRequired,
};
const NodeActions = ({ children, ...props }) => {
const classes = useStyles();

render() {
const { children, classes, ...props } = this.props;
return (
<span className={classes.root}>
{Children.map(children, action =>
action ? cloneElement(action, props) : null
)}
</span>
);
}
}
return (
<span className={classes.root}>
{Children.map(children, action =>
action ? cloneElement(action, props) : null
)}
</span>
);
};

export default withStyles(styles)(NodeActions);
NodeActions.propTypes = {
basePath: PropTypes.string.isRequired,
children: PropTypes.node,
record: PropTypes.object.isRequired,
resource: PropTypes.string.isRequired,
};

export default NodeActions;
96 changes: 46 additions & 50 deletions packages/ra-tree-ui-materialui/src/NodeView.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React, { cloneElement, Children, Component } from 'react';
import React, { cloneElement, Children } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { withStyles } from '@material-ui/core/styles';
import { makeStyles } from '@material-ui/core/styles';

const CONTAINER_CLASS = 'treenode-content';

const styles = {
const useStyles = makeStyles({
root: {
alignItems: 'center',
display: 'flex',
flexGrow: 1,
},
};
});

const sanitizeRestProps = ({
cancelDropOnChildren,
Expand All @@ -30,17 +30,17 @@ const sanitizeRestProps = ({
...rest
}) => rest;

export class NodeView extends Component {
static propTypes = {
actions: PropTypes.node,
basePath: PropTypes.string.isRequired,
children: PropTypes.node,
classes: PropTypes.object,
node: PropTypes.object.isRequired,
resource: PropTypes.string.isRequired,
};
const NodeView = ({
actions,
basePath,
children,
node,
resource,
...props
}) => {
const classes = useStyles();

handleClick = event => {
const handleClick = event => {
event.persist();
// This ensure clicking on a button does not collapse/expand a node
// When clicking on the form (empty spaces around buttons) however, it should
Expand All @@ -50,41 +50,37 @@ export class NodeView extends Component {
}
};

render() {
const {
actions,
basePath,
children,
classes,
node,
resource,
...props
} = this.props;
return (
<div
className={classNames(CONTAINER_CLASS, classes.root)}
onClick={handleClick}
{...sanitizeRestProps(props)}
>
{Children.map(children, field =>
field
? cloneElement(field, {
basePath: field.props.basePath || basePath,
record: node.record,
resource,
})
: null
)}
{actions &&
cloneElement(actions, {
basePath,
record: node.record,
resource,
})}
</div>
);
};

return (
<div
className={classNames(CONTAINER_CLASS, classes.root)}
onClick={this.handleClick}
{...sanitizeRestProps(props)}
>
{Children.map(children, field =>
field
? cloneElement(field, {
basePath: field.props.basePath || basePath,
record: node.record,
resource,
})
: null
)}
{actions &&
cloneElement(actions, {
basePath,
record: node.record,
resource,
})}
</div>
);
}
}
NodeView.propTypes = {
actions: PropTypes.node,
basePath: PropTypes.string.isRequired,
children: PropTypes.node,
node: PropTypes.object.isRequired,
resource: PropTypes.string.isRequired,
};

export default withStyles(styles)(NodeView);
export default NodeView;
Loading