From af8ca71c5120fb9a9f7c7de4e74b09d331b09ea8 Mon Sep 17 00:00:00 2001 From: Gildas Garcia Date: Mon, 10 Dec 2018 09:41:33 +0100 Subject: [PATCH] [RFR] Allow to extend the buttons onClick handlers --- .../src/button/BulkDeleteButton.js | 7 +++++- .../src/button/DeleteButton.js | 23 ++++++++++++++++++- .../src/button/ExportButton.js | 5 ++++ .../src/button/RefreshButton.js | 7 +++++- .../src/button/RefreshIconButton.js | 7 +++++- .../ra-ui-materialui/src/button/SaveButton.js | 6 +++++ 6 files changed, 51 insertions(+), 4 deletions(-) diff --git a/packages/ra-ui-materialui/src/button/BulkDeleteButton.js b/packages/ra-ui-materialui/src/button/BulkDeleteButton.js index b29309bf04f..64243eab030 100644 --- a/packages/ra-ui-materialui/src/button/BulkDeleteButton.js +++ b/packages/ra-ui-materialui/src/button/BulkDeleteButton.js @@ -62,16 +62,21 @@ class BulkDeleteButton extends Component { 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 { classes, label, icon, ...rest } = this.props; + const { classes, label, icon, onClick, ...rest } = this.props; return ( diff --git a/packages/ra-ui-materialui/src/button/ExportButton.js b/packages/ra-ui-materialui/src/button/ExportButton.js index bb2f1b325b1..dfe0520ff08 100644 --- a/packages/ra-ui-materialui/src/button/ExportButton.js +++ b/packages/ra-ui-materialui/src/button/ExportButton.js @@ -118,6 +118,7 @@ class ExportButton extends Component { maxResults, sort, resource, + onClick, } = this.props; dispatch( crudGetAll( @@ -135,6 +136,10 @@ class ExportButton extends Component { : downloadCSV(convertToCSV(data), resource) ) ); + + if (typeof onClick === 'function') { + onClick(); + } }; render() { diff --git a/packages/ra-ui-materialui/src/button/RefreshButton.js b/packages/ra-ui-materialui/src/button/RefreshButton.js index 35bd98e8b99..f3cd62f5d26 100644 --- a/packages/ra-ui-materialui/src/button/RefreshButton.js +++ b/packages/ra-ui-materialui/src/button/RefreshButton.js @@ -19,8 +19,13 @@ class RefreshButton extends Component { }; handleClick = event => { + const { refreshView, onClick } = this.props; event.preventDefault(); - this.props.refreshView(); + refreshView(); + + if (typeof onClick === 'function') { + onClick(); + } }; render() { diff --git a/packages/ra-ui-materialui/src/button/RefreshIconButton.js b/packages/ra-ui-materialui/src/button/RefreshIconButton.js index 8c7e54ca959..542008e5626 100644 --- a/packages/ra-ui-materialui/src/button/RefreshIconButton.js +++ b/packages/ra-ui-materialui/src/button/RefreshIconButton.js @@ -22,8 +22,13 @@ class RefreshButton extends Component { }; handleClick = event => { + const { refreshView, onClick } = this.props; event.preventDefault(); - this.props.refreshView(); + refreshView(); + + if (typeof onClick === 'function') { + onClick(); + } }; render() { diff --git a/packages/ra-ui-materialui/src/button/SaveButton.js b/packages/ra-ui-materialui/src/button/SaveButton.js index 638063f0099..8f03113100b 100644 --- a/packages/ra-ui-materialui/src/button/SaveButton.js +++ b/packages/ra-ui-materialui/src/button/SaveButton.js @@ -69,6 +69,7 @@ export class SaveButton extends Component { redirect, saving, showNotification, + onClick, } = this.props; if (saving) { @@ -84,6 +85,10 @@ export class SaveButton extends Component { } handleSubmitWithRedirect(redirect)(); } + + if (typeof onClick === 'function') { + onClick(); + } }; render() { @@ -99,6 +104,7 @@ export class SaveButton extends Component { translate, variant = 'raised', icon, + onClick, ...rest } = this.props;