Skip to content

Commit

Permalink
Media: Update/scarier media delete message (Automattic#11629)
Browse files Browse the repository at this point in the history
* update wording

* allow button element instead of text

* media-modal: update tests
  • Loading branch information
rralian authored Mar 8, 2017
1 parent 79b43b2 commit 3adf639
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
6 changes: 3 additions & 3 deletions client/lib/accept/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Accept is a stylized substitute to the browser `confirm` dialog.

## Arguments

* `message` - A string that gets displayed to the user in the cofirm dialog.
* `message` - A string that gets displayed to the user in the cofirm dialog.
* `callback` - A callback that gets called after confirms or cancels the dialog.
* `confirmButtonText` - Optional confirm button text, defaults to 'OK'.
* `cancelButtonText` - Optional cancel button text, defaults to 'Cancel'.
* `confirmButtonText` - Optional confirm button text (defaults to 'OK') OR Button element.
* `cancelButtonText` - Optional cancel button text (defaults to 'Cancel') OR Button element.

## Usage

Expand Down
22 changes: 12 additions & 10 deletions client/lib/accept/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const AcceptDialog = React.createClass( {
message: PropTypes.node,
onClose: PropTypes.func.isRequired,
confirmButtonText: PropTypes.node,
cancelButtonText: PropTypes.node
cancelButtonText: PropTypes.node,
},

getInitialState: function() {
Expand All @@ -31,16 +31,18 @@ const AcceptDialog = React.createClass( {
},

getActionButtons: function() {
const cancelButton = React.isValidElement( this.props.cancelButtonText ) ? this.props.cancelButtonText : {
action: 'cancel',
label: this.props.cancelButtonText ? this.props.cancelButtonText : this.props.translate( 'Cancel' ),
};
const confirmButton = React.isValidElement( this.props.confirmButtonText ) ? this.props.confirmButtonText : {
action: 'accept',
label: this.props.confirmButtonText ? this.props.confirmButtonText : this.props.translate( 'OK' ),
isPrimary: true,
};
return [
{
action: 'cancel',
label: this.props.cancelButtonText ? this.props.cancelButtonText : this.props.translate( 'Cancel' ),
},
{
action: 'accept',
label: this.props.confirmButtonText ? this.props.confirmButtonText : this.props.translate( 'OK' ),
isPrimary: true
}
cancelButton,
confirmButton,
];
},

Expand Down
11 changes: 8 additions & 3 deletions client/post-editor/media-modal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import MediaModalGallery from './gallery';
import MediaActions from 'lib/media/actions';
import MediaUtils from 'lib/media/utils';
import Dialog from 'components/dialog';
import Button from 'components/button';
import accept from 'lib/accept';

import { getMediaModalView } from 'state/ui/media-modal/selectors';
Expand Down Expand Up @@ -174,12 +175,16 @@ export class EditorMediaModal extends Component {
}

const confirmMessage = this.props.translate(
'Are you sure you want to permanently delete this item?',
'Are you sure you want to permanently delete these items?',
'Are you sure you want to permanently delete this item? It will be ' +
'permanently removed from all other locations where it currently appears.',
'Are you sure you want to permanently delete these items? They will be ' +
'permanently removed from all other locations where they appear.',
{ count: selectedCount }
);

accept( confirmMessage, this.confirmDeleteMedia );
const deleteButton = <Button primary scary>{ this.props.translate( 'Delete' ) }</Button>;

accept( confirmMessage, this.confirmDeleteMedia, deleteButton );
};

onAddMedia = () => {
Expand Down
20 changes: 16 additions & 4 deletions client/post-editor/media-modal/test/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ describe( 'EditorMediaModal', function() {
).instance();
tree.deleteMedia();

expect( accept ).to.have.been.calledWith( 'Are you sure you want to permanently delete this item?' );
expect( accept ).to.have.been.calledWith(
'Are you sure you want to permanently delete this item? It will be ' +
'permanently removed from all other locations where it currently appears.'
);
process.nextTick( function() {
expect( deleteMedia ).to.have.been.calledWith( DUMMY_SITE.ID, media );
done();
Expand All @@ -86,7 +89,10 @@ describe( 'EditorMediaModal', function() {
).instance();
tree.deleteMedia();

expect( accept ).to.have.been.calledWith( 'Are you sure you want to permanently delete these items?' );
expect( accept ).to.have.been.calledWith(
'Are you sure you want to permanently delete these items? They will be ' +
'permanently removed from all other locations where they appear.',
);
process.nextTick( function() {
expect( deleteMedia ).to.have.been.calledWith( DUMMY_SITE.ID, DUMMY_MEDIA );
done();
Expand All @@ -102,7 +108,10 @@ describe( 'EditorMediaModal', function() {
).instance();
tree.deleteMedia();

expect( accept ).to.have.been.calledWith( 'Are you sure you want to permanently delete this item?' );
expect( accept ).to.have.been.calledWith(
'Are you sure you want to permanently delete this item? It will be ' +
'permanently removed from all other locations where it currently appears.'
);
process.nextTick( function() {
expect( deleteMedia ).to.have.been.calledWith( DUMMY_SITE.ID, media );
done();
Expand All @@ -115,7 +124,10 @@ describe( 'EditorMediaModal', function() {
).instance();
tree.deleteMedia();

expect( accept ).to.have.been.calledWith( 'Are you sure you want to permanently delete this item?' );
expect( accept ).to.have.been.calledWith(
'Are you sure you want to permanently delete this item? It will be ' +
'permanently removed from all other locations where it currently appears.'
);
process.nextTick( function() {
expect( deleteMedia ).to.have.been.calledWith( DUMMY_SITE.ID, DUMMY_MEDIA[ 0 ] );
done();
Expand Down

0 comments on commit 3adf639

Please sign in to comment.