Skip to content

Commit

Permalink
NEW Select all and clear all functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Nov 7, 2023
1 parent 7f57263 commit a43a2ae
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 17 deletions.
4 changes: 2 additions & 2 deletions client/dist/js/TinyMCE_sslink-file.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/dist/js/TinyMCE_ssmedia.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions client/lang/src/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"AssetAdmin.BULK_ACTIONS_ARCHIVE_ITEMS_CONFIRM": "You're about to archive %s file(s) which may be used in your site's content. Carefully check the file usage on the files before archiving the file(s).",
"AssetAdmin.BULK_ACTIONS_ARCHIVE_SUCCESS_02": "%s folders/files were successfully archived.",
"AssetAdmin.BULK_ACTIONS_ARCHIVE_WARNING": "Ensure files are removed from content areas prior to archiving them, otherwise they will appear as broken links.",
"AssetAdmin.BULK_ACTIONS_CLEAR_SELECTION": "Clear selection",
"AssetAdmin.BULK_ACTIONS_CONFIRM": "Are you sure you want to %s these files?",
"AssetAdmin.BULK_ACTIONS_DELETE": "Delete",
"AssetAdmin.BULK_ACTIONS_DELETE_CONFIRM": "Are you sure you want to delete these files?",
Expand All @@ -26,6 +27,8 @@
"AssetAdmin.BULK_ACTIONS_DELETE_SUCCESS_02": "%s folders/files were successfully deleted.",
"AssetAdmin.BULK_ACTIONS_DELETE_WARNING": "Ensure files are removed from content areas prior to deleting them, otherwise they will appear as broken links.",
"AssetAdmin.BULK_ACTIONS_PLACEHOLDER": "Select an action...",
"AssetAdmin.BULK_ACTIONS_SELECTED": "%s selected",
"AssetAdmin.BULK_ACTIONS_SELECT_ALL": "Select all",
"AssetAdmin.CANCEL": "Cancel",
"AssetAdmin.CONFIRMDELETE": "Are you sure you want to delete this record?",
"AssetAdmin.CONFIRM_FILE_ARCHIVE": "Confirm archive",
Expand Down
26 changes: 22 additions & 4 deletions client/src/components/BulkActions/BulkActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import PropTypes from 'prop-types';
class BulkActions extends Component {
constructor(props) {
super(props);

this.handleChangeValue = this.handleChangeValue.bind(this);
this.renderChild = this.renderChild.bind(this);
}
Expand Down Expand Up @@ -106,13 +105,30 @@ class BulkActions extends Component {
}

const { ActionMenu, showCount } = this.props;

const count = this.props.items.length;
const selectAll = i18n._t('AssetAdmin.BULK_ACTIONS_SELECT_ALL', 'Select all');
const selected = i18n.sprintf(
i18n._t('AssetAdmin.BULK_ACTIONS_SELECTED', '%s selected'),
this.props.items.length
);
const title = i18n._t('AssetAdmin.BULK_ACTIONS_CLEAR_SELECTION', 'Clear selection');

return (
<div className="bulk-actions fieldholder-small">
{showCount &&
<div className="bulk-actions-counter">{count}</div>
<>
<Button
className="bulk-actions-counter font-icon-cross-mark"
onClick={this.props.onClearSelection}
title={title}
>
{selected}
</Button>
<div className="bulk-actions-select-all">
<Button onClick={this.props.onSelectAll}>
{selectAll}
</Button>
</div>
</>
}
{children.slice(0, 2)}
{children.length > 2 && ActionMenu
Expand Down Expand Up @@ -144,6 +160,8 @@ BulkActions.propTypes = {
})),
ActionMenu: PropTypes.elementType,
showCount: PropTypes.bool,
onClearSelection: PropTypes.func.isRequired,
onSelectAll: PropTypes.func.isRequired,
};

BulkActions.defaultProps = {
Expand Down
17 changes: 15 additions & 2 deletions client/src/components/BulkActions/BulkActions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,28 @@ $bulk-actions-width: 300px;

.bulk-actions-counter {
vertical-align: middle;
min-width: 28px;
padding: 6px;
padding: 5px 12px 5px 8px;
margin-right: 8px;
line-height: $line-height-base;
color: $white;
text-align: center;
background-color: $component-active-bg;
border-radius: $btn-border-radius;
font-weight: bold;
transition: none;

&.btn-secondary:hover,
&.btn-secondary:focus,
&.btn-secondary:focus-visible {
background-color: $brand-secondary;
border-color: $brand-secondary;
color: $white;
}
}

.bulk-actions-select-all button {
color: $component-active-bg;
font-weight: bold;
}

.bulk-actions__action.ss-ui-button {
Expand Down
22 changes: 17 additions & 5 deletions client/src/containers/Gallery/Gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const ACTION_TYPES = {
UNPUBLISH: 'unpublish',
INSERT: 'insert',
ADMIN: 'admin',
SELECT: 'select'
SELECT: 'select',
CLEAR: 'clear',
};

class Gallery extends Component {
Expand Down Expand Up @@ -68,6 +69,7 @@ class Gallery extends Component {
this.handleBeginSelection = this.handleBeginSelection.bind(this);
this.handleGroupSelect = this.handleGroupSelect.bind(this);
this.handleClearSelection = this.handleClearSelection.bind(this);
this.handleSelectAll = this.handleSelectAll.bind(this);
this.toggleSelectConcat = this.toggleSelectConcat.bind(this);
this.getSelectableFiles = this.getSelectableFiles.bind(this);
}
Expand Down Expand Up @@ -491,16 +493,16 @@ class Gallery extends Component {
/**
* Handles the lasso selection of items from <SelectionGroup />
*
* @param items
* @param ids
* @param event Event
*/
handleGroupSelect(items, event) {
handleGroupSelect(ids, event) {
const { setSelectedFiles, selectFiles } = this.props.actions.gallery;
const selectableFiles = this.getSelectableFiles();

const selectItems = items
const selectItems = ids
.filter((id, index) => {
if (items.indexOf(id) !== index) {
if (ids.indexOf(id) !== index) {
return false;
}
return selectableFiles.find(file => file.id === id);
Expand Down Expand Up @@ -539,6 +541,14 @@ class Gallery extends Component {
this.props.actions.gallery.deselectFiles();
}

/**
* Selects all visible files
*/
handleSelectAll() {
const ids = this.props.files.map(file => file.id);
this.handleGroupSelect(ids, new Event('na'));
}

/**
* Pick if the selection started from inside the pagination. If it started from inside the
* pagination, cancel it to prevent inteference with the normal pagination.
Expand Down Expand Up @@ -756,6 +766,8 @@ class Gallery extends Component {
key={selected.length > 0}
container={this.gallery}
showCount={maxFilesSelect !== 1}
onClearSelection={this.handleClearSelection}
onSelectAll={this.handleSelectAll}
/>
);
}
Expand Down

0 comments on commit a43a2ae

Please sign in to comment.