-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
279 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,97 @@ | ||
import React from 'react'; | ||
import React, { cloneElement } from 'react'; | ||
import classnames from 'classnames'; | ||
import Card from '@material-ui/core/Card'; | ||
import { createStyles } from '@material-ui/core/styles'; | ||
import { Title } from 'ra-ui-materialui'; | ||
|
||
import TreeNodeList from './TreeNodeList'; | ||
import TreeListLoading from './TreeListLoading'; | ||
import TreeListActions from './TreeListActions'; | ||
import TreeListToolbar from './TreeListToolbar'; | ||
|
||
const TreeList = ({ children, ...props }) => ( | ||
<TreeNodeList {...props}>{children}</TreeNodeList> | ||
const TreeList = ({ | ||
actions = <TreeListActions />, | ||
aside, | ||
children, | ||
className, | ||
classes, | ||
defaultTitle, | ||
exporter, | ||
filter, | ||
loading, | ||
title, | ||
version, | ||
...props | ||
}) => ( | ||
<div | ||
className={classnames('tree-page', classes.root, className)} | ||
{...sanitizeRestProps(props)} | ||
> | ||
<Title title={title} defaultTitle={defaultTitle} /> | ||
<Card className={classes.card}> | ||
{actions && ( | ||
<TreeListToolbar | ||
{...props} | ||
actions={actions} | ||
exporter={exporter} | ||
permanentFilter={filter} | ||
/> | ||
)} | ||
{loading && props.nodes.length === 0 ? ( | ||
<TreeListLoading /> | ||
) : ( | ||
<div key={version}> | ||
<TreeNodeList {...props}>{children}</TreeNodeList> | ||
</div> | ||
)} | ||
</Card> | ||
{aside && cloneElement(aside, props)} | ||
</div> | ||
); | ||
|
||
export default TreeList; | ||
|
||
export const styles = createStyles({ | ||
root: { | ||
display: 'flex', | ||
flex: 1, | ||
}, | ||
card: { | ||
position: 'relative', | ||
flex: '1 1 auto', | ||
}, | ||
actions: { | ||
zIndex: 2, | ||
display: 'flex', | ||
justifyContent: 'flex-end', | ||
flexWrap: 'wrap', | ||
}, | ||
noResults: { padding: 20 }, | ||
}); | ||
|
||
const sanitizeRestProps = ({ | ||
basePath, | ||
children, | ||
classes, | ||
closeNode, | ||
data, | ||
expandNode, | ||
hasCreate, | ||
hasEdit, | ||
hasList, | ||
hasShow, | ||
history, | ||
loading, | ||
locale, | ||
location, | ||
match, | ||
nodes, | ||
options, | ||
parentSource, | ||
permissions, | ||
positionSource, | ||
resource, | ||
toggleNode, | ||
version, | ||
...rest | ||
}: any) => rest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import onlyUpdateForKeys from 'recompose/onlyUpdateForKeys'; | ||
import { sanitizeListRestProps } from 'ra-core'; | ||
import { CardActions, CreateButton, ExportButton } from 'react-admin'; | ||
|
||
const TreeListActions = ({ | ||
basePath, | ||
className, | ||
closeNode, | ||
currentSort, | ||
expandNode, | ||
exporter, | ||
hasCreate, | ||
hasEdit, | ||
hasList, | ||
hasShow, | ||
parentSource, | ||
permanentFilter, | ||
positionSource, | ||
resource, | ||
toggleNode, | ||
total, | ||
...rest | ||
}) => ( | ||
<CardActions className={className} {...sanitizeListRestProps(rest)}> | ||
{hasCreate && <CreateButton basePath={basePath} />} | ||
{exporter !== false && ( | ||
<ExportButton | ||
disabled={total === 0} | ||
resource={resource} | ||
sort={currentSort} | ||
filter={permanentFilter} | ||
exporter={exporter} | ||
/> | ||
)} | ||
</CardActions> | ||
); | ||
|
||
TreeListActions.propTypes = { | ||
basePath: PropTypes.string, | ||
className: PropTypes.string, | ||
exporter: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]), | ||
hasCreate: PropTypes.bool, | ||
resource: PropTypes.string, | ||
}; | ||
|
||
export default onlyUpdateForKeys(['resource'])(TreeListActions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
import List from '@material-ui/core/List'; | ||
import { createStyles, withStyles } from '@material-ui/core/styles'; | ||
import TreeNode from './TreeNode'; | ||
|
||
const times = (nbChildren, fn) => | ||
Array.from({ length: nbChildren }, (_, key) => fn(key)); | ||
|
||
const DummyRecord = {}; | ||
|
||
const TreeListLoading = ({ nbFakeLines = 5, ...props }) => ( | ||
<List dense disablePadding {...sanitizeRestProps(props)}> | ||
{times(nbFakeLines, key => ( | ||
// @ts-ignore | ||
<TreeNode key={key} record={DummyRecord} {...props}> | ||
<Placeholder /> | ||
</TreeNode> | ||
))} | ||
</List> | ||
); | ||
|
||
export default TreeListLoading; | ||
|
||
const sanitizeRestProps = ({ | ||
basePath, | ||
children, | ||
classes, | ||
closeNode, | ||
data, | ||
expandNode, | ||
hasCreate, | ||
hasEdit, | ||
hasList, | ||
hasShow, | ||
history, | ||
loading, | ||
locale, | ||
location, | ||
match, | ||
nodes, | ||
options, | ||
parentSource, | ||
permissions, | ||
positionSource, | ||
resource, | ||
toggleNode, | ||
version, | ||
...rest | ||
}: any) => rest; | ||
|
||
const RawPlaceholder = ({ classes }) => ( | ||
<div className={classes.root}> </div> | ||
); | ||
|
||
const styles = theme => | ||
createStyles({ | ||
root: { | ||
backgroundColor: theme.palette.grey[300], | ||
width: 256, | ||
}, | ||
}); | ||
|
||
const Placeholder = withStyles(styles)(RawPlaceholder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Toolbar from '@material-ui/core/Toolbar'; | ||
import { withStyles, createStyles } from '@material-ui/core/styles'; | ||
|
||
const styles = createStyles({ | ||
toolbar: { | ||
justifyContent: 'space-between', | ||
}, | ||
}); | ||
|
||
const TreeListToolbar = ({ | ||
classes, | ||
filters, | ||
permanentFilter, // set in the List component by the developer | ||
actions, | ||
exporter, | ||
...rest | ||
}) => ( | ||
<Toolbar className={classes.toolbar}> | ||
<span /> | ||
{actions && | ||
React.cloneElement(actions, { | ||
...rest, | ||
className: classes.actions, | ||
exporter, | ||
permanentFilter, | ||
...actions.props, | ||
})} | ||
</Toolbar> | ||
); | ||
|
||
TreeListToolbar.propTypes = { | ||
classes: PropTypes.object, | ||
permanentFilter: PropTypes.object, | ||
actions: PropTypes.element, | ||
exporter: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]), | ||
}; | ||
|
||
TreeListToolbar.defaultProps = { | ||
classes: {}, | ||
}; | ||
|
||
export default withStyles(styles)(TreeListToolbar); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import Tree from './Tree'; | ||
import TreeNode from './TreeNode'; | ||
import TreeList from './TreeList'; | ||
export { TreeNode, Tree, TreeList }; | ||
import TreeListLoading from './TreeListLoading'; | ||
export { TreeNode, Tree, TreeList, TreeListLoading }; | ||
export * from 'ra-tree-core'; |