-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Gildas Garcia
committed
Mar 10, 2019
1 parent
f2bfcd6
commit 264a878
Showing
9 changed files
with
366 additions
and
268 deletions.
There are no files selected for viewing
104 changes: 0 additions & 104 deletions
104
packages/ra-ui-materialui/src/button/BulkDeleteButton.js
This file was deleted.
Oops, something went wrong.
133 changes: 133 additions & 0 deletions
133
packages/ra-ui-materialui/src/button/BulkDeleteButton.tsx
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,133 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import compose from 'recompose/compose'; | ||
import ActionDelete from '@material-ui/icons/Delete'; | ||
import { | ||
withStyles, | ||
createStyles, | ||
Theme, | ||
WithStyles, | ||
} from '@material-ui/core/styles'; | ||
import { fade } from '@material-ui/core/styles/colorManipulator'; | ||
import { | ||
crudDeleteMany, | ||
startUndoable as startUndoableAction, | ||
Dispatch, | ||
Identifier, | ||
} from 'ra-core'; | ||
|
||
import Button from './Button'; | ||
import { ButtonWithIconProps } from './types'; | ||
|
||
interface Props extends ButtonWithIconProps { | ||
undoable: boolean; | ||
onClick?: () => void; | ||
} | ||
|
||
// Props injected by react-admin | ||
interface InjectedProps { | ||
basePath: string; | ||
resource: string; | ||
selectedIds: Identifier[]; | ||
} | ||
|
||
// Props injected by the HOCs | ||
interface EnhancedProps extends WithStyles<typeof styles> { | ||
dispatchCrudDeleteMany: Dispatch<typeof crudDeleteMany>; | ||
startUndoable: Dispatch<typeof startUndoableAction>; | ||
} | ||
|
||
const styles = (theme: Theme) => | ||
createStyles({ | ||
deleteButton: { | ||
color: theme.palette.error.main, | ||
'&:hover': { | ||
backgroundColor: fade(theme.palette.error.main, 0.12), | ||
// Reset on mouse devices | ||
'@media (hover: none)': { | ||
backgroundColor: 'transparent', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
class BulkDeleteButton extends Component< | ||
Props & InjectedProps & EnhancedProps | ||
> { | ||
handleClick = () => { | ||
const { | ||
basePath, | ||
dispatchCrudDeleteMany, | ||
resource, | ||
selectedIds, | ||
startUndoable, | ||
undoable, | ||
onClick, | ||
} = this.props; | ||
if (undoable) { | ||
startUndoable(crudDeleteMany(resource, selectedIds, basePath)); | ||
} else { | ||
dispatchCrudDeleteMany(resource, selectedIds, basePath); | ||
} | ||
|
||
if (typeof onClick === 'function') { | ||
onClick(); | ||
} | ||
}; | ||
|
||
render() { | ||
const { | ||
basePath, | ||
classes, | ||
dispatchCrudDeleteMany, | ||
label, | ||
icon, | ||
onClick, | ||
resource, | ||
selectedIds, | ||
startUndoable, | ||
theme, | ||
undoable, | ||
...rest | ||
} = this.props; | ||
return ( | ||
<Button | ||
onClick={this.handleClick} | ||
label={label} | ||
className={classes.deleteButton} | ||
{...rest} | ||
> | ||
{icon} | ||
</Button> | ||
); | ||
} | ||
} | ||
|
||
const EnhancedBulkDeleteButton = compose< | ||
Props & InjectedProps & EnhancedProps, | ||
Props | ||
>( | ||
connect( | ||
undefined, | ||
{ | ||
startUndoable: startUndoableAction, | ||
dispatchCrudDeleteMany: crudDeleteMany, | ||
} | ||
), | ||
withStyles(styles) | ||
)(BulkDeleteButton); | ||
|
||
EnhancedBulkDeleteButton.propTypes = { | ||
label: PropTypes.string, | ||
undoable: PropTypes.bool, | ||
icon: PropTypes.element, | ||
}; | ||
|
||
EnhancedBulkDeleteButton.defaultProps = { | ||
label: 'ra.action.delete', | ||
undoable: true, | ||
icon: <ActionDelete />, | ||
}; | ||
|
||
export default EnhancedBulkDeleteButton; |
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
Oops, something went wrong.