Skip to content

Commit

Permalink
Merge pull request #363 from creative-commoners/pulls/master/delete-d…
Browse files Browse the repository at this point in the history
…elete-and-archive-instead

NEW Rename delete button to archive button. Update all references.
  • Loading branch information
robbieaverill committed Aug 30, 2018
2 parents 4e6946a + 9b40dc0 commit f076ee3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 34 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

45 changes: 26 additions & 19 deletions client/src/components/ElementEditor/Header.js
Expand Up @@ -4,7 +4,7 @@ import React, { Component, PropTypes } from 'react';
import { Tooltip } from 'reactstrap';
import { compose } from 'redux';
import { inject } from 'lib/Injector';
import deleteBlockMutation from 'state/editor/deleteBlockMutation';
import archiveBlockMutation from 'state/editor/archiveBlockMutation';
import publishBlockMutation from 'state/editor/publishBlockMutation';
import i18n from 'i18n';
import classNames from 'classnames';
Expand All @@ -13,11 +13,11 @@ class Header extends Component {
constructor(props) {
super(props);

this.toggle = this.toggle.bind(this);
this.handleDelete = this.handleDelete.bind(this);
this.handlePublish = this.handlePublish.bind(this);
this.handleArchive = this.handleArchive.bind(this);
this.handleCaretClick = this.handleCaretClick.bind(this);
this.handlePublish = this.handlePublish.bind(this);
this.renderActionsMenu = this.renderActionsMenu.bind(this);
this.toggle = this.toggle.bind(this);

this.state = {
tooltipOpen: false,
Expand All @@ -27,19 +27,26 @@ class Header extends Component {
/**
* Handle the deletion of a block, passing the block ID in
*/
handleDelete(event) {
handleArchive(event) {
event.stopPropagation();

const { id, actions: { handleDeleteBlock } } = this.props;
const { id, isPublished, actions: { handleArchiveBlock } } = this.props;

const deleteMessage = i18n._t(
let archiveMessage = i18n._t(
'ElementHeader.CONFIRM_DELETE',
'Are you sure you want to delete this block?'
'Are you sure you want to send this block to the archive?'
);

if (isPublished) {
archiveMessage = i18n._t(
'ElementHeader.CONFIRM_DELETE_AND_UNPUBLISH',
'Warning: This block will be unpublished before being sent to the archive. Are you sure you want to proceed?'
);
}

// eslint-disable-next-line no-alert
if (handleDeleteBlock && confirm(deleteMessage)) {
handleDeleteBlock(id);
if (handleArchiveBlock && confirm(archiveMessage)) {
handleArchiveBlock(id);
}
}

Expand Down Expand Up @@ -117,7 +124,7 @@ class Header extends Component {
return null;
}

const deleteTitle = i18n._t('ElementHeader.DELETE', 'Delete');
const archiveTitle = i18n._t('ElementHeader.ARCHIVE', 'Archive');

return (
<ActionMenuComponent
Expand All @@ -127,12 +134,12 @@ class Header extends Component {
toggleCallback={(event) => event.stopPropagation()}
>
<button
onClick={this.handleDelete}
title={deleteTitle}
onClick={this.handleArchive}
title={archiveTitle}
type="button"
className={classNames('element-editor__actions-delete', 'dropdown-item')}
className={classNames('element-editor__actions-archive', 'dropdown-item')}
>
{deleteTitle}
{archiveTitle}
</button>

{this.renderPublishButton()}
Expand Down Expand Up @@ -202,8 +209,8 @@ Header.propTypes = {
elementType: PropTypes.string,
fontIcon: PropTypes.string,
actions: PropTypes.shape({
handleDeleteBlock: PropTypes.func.isRequired,
handlePublishBlock: PropTypes.func
handlePublishBlock: PropTypes.func,
handleArchiveBlock: PropTypes.func.isRequired,
}),
ActionMenuComponent: React.PropTypes.oneOfType([React.PropTypes.node, React.PropTypes.func]),
expandable: PropTypes.bool,
Expand All @@ -225,6 +232,6 @@ export default compose(
}),
() => 'ElementEditor.ElementList.Element'
),
deleteBlockMutation,
publishBlockMutation
publishBlockMutation,
archiveBlockMutation
)(Header);
Expand Up @@ -3,7 +3,7 @@ import gql from 'graphql-tag';

// GraphQL query for deleting a specific block
const mutation = gql`
mutation DeleteBlock($blockId: ID!) {
mutation ArchiveBlock($blockId: ID!) {
deleteBlock(IDs: [$blockId]) {
ID
}
Expand All @@ -12,14 +12,14 @@ mutation DeleteBlock($blockId: ID!) {

const config = {
props: ({ mutate, ownProps: { actions } }) => {
const handleDeleteBlock = (blockId) => mutate({
const handleArchiveBlock = (blockId) => mutate({
variables: { blockId },
});

return {
actions: {
...actions,
handleDeleteBlock,
handleArchiveBlock,
},
};
},
Expand Down
14 changes: 7 additions & 7 deletions tests/Behat/Context/FeatureContext.php
Expand Up @@ -56,13 +56,13 @@ public function iShouldSeeAsTheSummaryForBlock($text, $position)
}

/**
* @Then I should see the delete button for block :position
* @Then I should see the archive button for block :position
*
* @param int $position
*/
public function iShouldSeeDeleteButtonForBlock($position)
public function iShouldSeeArchiveButtonForBlock($position)
{
$this->getDeleteButton($position);
$this->getArchiveButton($position);
}

/**
Expand Down Expand Up @@ -124,18 +124,18 @@ protected function getSpecificBlock($position)
}

/**
* Returns the delete button for a specific block
* Returns the archive button for a specific block
*
* @param $position
* @return NodeElement
*/
protected function getDeleteButton($position)
protected function getArchiveButton($position)
{
$block = $this->getSpecificBlock($position);
assertNotNull($block, 'Block ' . $position . ' was not found in the page.');

$button = $block->find('css', '.element-editor__actions-delete');
assertNotNull($button, 'Delete button not found');
$button = $block->find('css', '.element-editor__actions-archive');
assertNotNull($button, 'Archive button not found');

return $button;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Behat/features/element-editor.feature
Expand Up @@ -58,7 +58,7 @@ Feature: View types of elements in a report
Then I should see "Imagine some fancy form builder here!"

@modal
Scenario: I can delete a block
Scenario: I can archive a block
Given I wait until I see the ".element-editor__element" element
When I select "Content" from "elemental-editor_add-new-block-control_select-dropdown"
And I click "Add" in the ".elemental-editor__add-new-block-control" element
Expand All @@ -72,9 +72,9 @@ Feature: View types of elements in a report
And I should see "Second Sample Block"
And I should see block 1
And I press the "View actions" button
Then I should see the delete button for block 1
When I press the "Delete" button
And I see the text "Are you sure you want to delete this block?" in the alert
Then I should see the archive button for block 1
When I press the "Archive" button
And I see the text "Are you sure you want to send this block to the archive?" in the alert
And I confirm the dialog
And I wait until I see the ".element-editor__element" element
Then I should see "Second Sample Block"
Expand Down

0 comments on commit f076ee3

Please sign in to comment.