Skip to content

Commit

Permalink
Merge pull request #2595 from marmelab/disable-export-no-data
Browse files Browse the repository at this point in the history
[RFR] Disable the Export button when there is nothing to export
  • Loading branch information
fzaninotto authored Dec 5, 2018
2 parents e6e7611 + 3419db6 commit 1618935
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docs/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ const PostActions = ({
onUnselectItems,
resource,
selectedIds,
showFilter
showFilter,
total
}) => (
<CardActions>
{bulkActions && React.cloneElement(bulkActions, {
Expand All @@ -119,6 +120,7 @@ const PostActions = ({
}) }
<CreateButton basePath={basePath} />
<ExportButton
disabled={total === 0}
resource={resource}
sort={currentSort}
filter={filterValues}
Expand Down Expand Up @@ -149,7 +151,9 @@ export const PostList = ({ permissions, ...props }) => (

### Exporter

Among the default list actions, react-admin includes an `<ExportButton>`. By default, clicking this button will:
Among the default list actions, react-admin includes an `<ExportButton>`. This button is disabled when there is no record in the current `<List>`.

By default, clicking this button will:

1. Call the `dataProvider` with the current sort and filter (but without pagination),
2. Transform the result into a CSV string,
Expand Down
3 changes: 3 additions & 0 deletions packages/ra-ui-materialui/src/list/ListActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const Actions = ({
selectedIds,
onUnselectItems,
showFilter,
total,
...rest
}) => (
<CardActions className={className} {...sanitizeListRestProps(rest)}>
Expand All @@ -41,6 +42,7 @@ const Actions = ({
})}
{hasCreate && <CreateButton basePath={basePath} />}
<ExportButton
disabled={total === 0}
resource={resource}
sort={currentSort}
filter={filterValues}
Expand All @@ -63,6 +65,7 @@ Actions.propTypes = {
onUnselectItems: PropTypes.func.isRequired,
selectedIds: PropTypes.arrayOf(PropTypes.any),
showFilter: PropTypes.func,
total: PropTypes.number.isRequired,
};

Actions.defaultProps = {
Expand Down

0 comments on commit 1618935

Please sign in to comment.