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

[RFR] Fix <Confirm> element isn't translatable #2739

Merged
merged 1 commit into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions docs/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ export default connect(undefined, { crudUpdateMany })(ResetViewsButton);

**Tip**: `<Confirm>` leverages material-ui's `<Dialog>` component to implement a confirmation popup. Feel free to use it in your admins!

**Tip**: `<Confirm>` text props such as `title` and `content` are translatable. You can pass them translation keys.

**Tip**: You can customize the text of the two `<Confirm>` component buttons using the `cancel` and `confirm` prop which accepts translation keys too.

**Tip**: React-admin doesn't use the `<Confirm>` component internally, because deletes and updates are applied locally immediately, then dispatched to the server after a few seconds, unless the user chooses to undo the modification. That's what we call optimistic rendering. You can do the same for the `ResetViewsButton` by wrapping the `crudUpdateMany()` action creator inside a `startUndoable()` action creator, as follows:

```jsx
Expand Down
1 change: 1 addition & 0 deletions packages/ra-language-english/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
cancel: 'Cancel',
clear_input_value: 'Clear value',
clone: 'Clone',
confirm: 'Confirm',
create: 'Create',
delete: 'Delete',
edit: 'Edit',
Expand Down
1 change: 1 addition & 0 deletions packages/ra-language-french/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
cancel: 'Annuler',
clear_input_value: 'Vider le champ',
clone: 'Dupliquer',
confirm: 'Confirmer',
create: 'Créer',
delete: 'Supprimer',
edit: 'Éditer',
Expand Down
21 changes: 14 additions & 7 deletions packages/ra-ui-materialui/src/layout/Confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { fade } from '@material-ui/core/styles/colorManipulator';
import ActionCheck from '@material-ui/icons/CheckCircle';
import AlertError from '@material-ui/icons/ErrorOutline';
import classnames from 'classnames';
import compose from 'recompose/compose';
import { translate } from 'ra-core';

const styles = theme => ({
confirmPrimary: {
Expand Down Expand Up @@ -56,20 +58,21 @@ const Confirm = ({
onConfirm,
onClose,
classes,
translate,
}) => (
<Dialog
open={isOpen}
onClose={onClose}
aria-labelledby="alert-dialog-title"
>
<DialogTitle id="alert-dialog-title">{title}</DialogTitle>
<DialogTitle id="alert-dialog-title">{translate(title, { _: title })}</DialogTitle>
<DialogContent>
<DialogContentText>{content}</DialogContentText>
<DialogContentText>{translate(content, { _: content })}</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={onClose}>
<AlertError className={classes.iconPaddingStyle} />
{cancel}
{translate(cancel, { _: cancel })}
</Button>
<Button
onClick={onConfirm}
Expand All @@ -80,7 +83,7 @@ const Confirm = ({
autoFocus
>
<ActionCheck className={classes.iconPaddingStyle} />
{confirm}
{translate(confirm, { _: confirm })}
</Button>
</DialogActions>
</Dialog>
Expand All @@ -96,14 +99,18 @@ Confirm.propTypes = {
onClose: PropTypes.func.isRequired,
onConfirm: PropTypes.func.isRequired,
title: PropTypes.string.isRequired,
translate: PropTypes.func.isRequired,
};

Confirm.defaultProps = {
cancel: 'Cancel',
cancel: 'ra.action.cancel',
classes: {},
confirm: 'Confirm',
confirm: 'ra.action.confirm',
confirmColor: 'primary',
isOpen: false,
};

export default withStyles(styles)(Confirm);
export default compose(
withStyles(styles),
translate
)(Confirm);