From ff5d5dcd77eb4ff7d047540c7989e36980282fc4 Mon Sep 17 00:00:00 2001 From: wiadev Date: Tue, 14 Nov 2017 08:41:54 +0100 Subject: [PATCH 1/3] Add ctrl+a for both of select all / select x items on table #1222 --- .../shortcuts/PaginationContextShortcuts.js | 7 ++- src/components/table/TablePagination.js | 48 +++++++++++++------ src/keymap.js | 3 +- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/components/shortcuts/PaginationContextShortcuts.js b/src/components/shortcuts/PaginationContextShortcuts.js index 4d56b332b..a3dbbfee8 100644 --- a/src/components/shortcuts/PaginationContextShortcuts.js +++ b/src/components/shortcuts/PaginationContextShortcuts.js @@ -8,7 +8,7 @@ class PaginationContextShortcuts extends Component { handleShortcuts = (action, event) => { const { - handleFirstPage, handleLastPage, handlePrevPage, handleNextPage, pages + handleFirstPage, handleLastPage, handlePrevPage, handleNextPage, pages, handleSelectAll } = this.props; switch (action) { @@ -28,6 +28,10 @@ class PaginationContextShortcuts extends Component { if (pages > 1) return handlePrevPage(); return; + case 'SELECT_ALL_ROWS': + event.preventDefault(); + return handleSelectAll(); + } } @@ -40,6 +44,7 @@ class PaginationContextShortcuts extends Component { isolate = { true } preventDefault = { true } stopPropagation = { true } + global /> ) } diff --git a/src/components/table/TablePagination.js b/src/components/table/TablePagination.js index 22245df65..8a281cb5d 100644 --- a/src/components/table/TablePagination.js +++ b/src/components/table/TablePagination.js @@ -20,6 +20,16 @@ class TablePagination extends Component { }) } + _handleSelectAll = () => { + const { + selected, rowLength, handleSelectAll, handleSelectRange + } = this.props; + + const selectedWholePage = selected && (selected.length === rowLength); + + return selectedWholePage? handleSelectRange(['all']) : handleSelectAll(); + } + handleSubmit = (e, value, pages) => { const {handleChangePage, deselect} = this.props; if(e.key === 'Enter'){ @@ -203,7 +213,7 @@ class TablePagination extends Component { renderSelectAll = () => { const { - selected, handleSelectAll, handleSelectRange, size, rowLength + selected, size, rowLength } = this.props; const selectedWholePage = selected && (selected.length === rowLength); @@ -224,8 +234,7 @@ class TablePagination extends Component {
{ - selectedWholePage ? - handleSelectRange(['all']) : handleSelectAll() + this._handleSelectAll(); }} > {selectedWholePage ? @@ -260,6 +269,23 @@ class TablePagination extends Component { ) } + paginationShortcuts = () => { + const { + size, pageLength, disablePaginationShortcuts + } = this.props; + + const pages = size ? Math.ceil(size / pageLength) : 0; + + return !disablePaginationShortcuts && { + handleFirstPage : () => handleChangePage(1), + handleLastPage : () => handleChangePage( + size ? Math.ceil(size / pageLength) : 0), + handleNextPage : () => handleChangePage('up'), + handlePrevPage : () => handleChangePage('down'), + pages : pages + } + } + render() { const { size, pageLength, handleChangePage, page, compressed, @@ -310,18 +336,10 @@ class TablePagination extends Component {
- { - !disablePaginationShortcuts && - handleChangePage(1)} - handleLastPage={() => handleChangePage( - size ? Math.ceil(size / pageLength) : 0) - } - handleNextPage={() => handleChangePage('up')} - handlePrevPage={() => handleChangePage('down')} - pages={pages} - /> - } + this._handleSelectAll()} + {...this.paginationShortcuts()} + /> ); diff --git a/src/keymap.js b/src/keymap.js index 4dac9c74a..29c74e162 100644 --- a/src/keymap.js +++ b/src/keymap.js @@ -46,7 +46,8 @@ export default { NEXT_PAGE: 'pagedown', PREV_PAGE: 'pageup', FIRST_PAGE: 'home', - LAST_PAGE: 'end' + LAST_PAGE: 'end', + SELECT_ALL_ROWS: mod + '+' + 'a' }, QUICK_ACTIONS: { QUICK_ACTION_POS: mod + '+' + 'u', From 4be07f2193d067e42910afbc5c32838eb1aded9e Mon Sep 17 00:00:00 2001 From: wiadev Date: Tue, 14 Nov 2017 11:11:47 +0100 Subject: [PATCH 2/3] hotfix --- src/components/shortcuts/PaginationContextShortcuts.js | 1 - src/components/table/TablePagination.js | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/shortcuts/PaginationContextShortcuts.js b/src/components/shortcuts/PaginationContextShortcuts.js index a3dbbfee8..72545ef52 100644 --- a/src/components/shortcuts/PaginationContextShortcuts.js +++ b/src/components/shortcuts/PaginationContextShortcuts.js @@ -31,7 +31,6 @@ class PaginationContextShortcuts extends Component { case 'SELECT_ALL_ROWS': event.preventDefault(); return handleSelectAll(); - } } diff --git a/src/components/table/TablePagination.js b/src/components/table/TablePagination.js index 8a281cb5d..7c0c42600 100644 --- a/src/components/table/TablePagination.js +++ b/src/components/table/TablePagination.js @@ -27,7 +27,8 @@ class TablePagination extends Component { const selectedWholePage = selected && (selected.length === rowLength); - return selectedWholePage? handleSelectRange(['all']) : handleSelectAll(); + return selectedWholePage? + handleSelectRange(['all']) :handleSelectAll(); } handleSubmit = (e, value, pages) => { @@ -271,7 +272,7 @@ class TablePagination extends Component { paginationShortcuts = () => { const { - size, pageLength, disablePaginationShortcuts + size, pageLength, disablePaginationShortcuts, handleChangePage } = this.props; const pages = size ? Math.ceil(size / pageLength) : 0; From 425202a4c2c8d3e5377ec075754870d0a63b66a9 Mon Sep 17 00:00:00 2001 From: wiadev Date: Tue, 14 Nov 2017 11:37:53 +0100 Subject: [PATCH 3/3] remove unused variables --- src/components/table/TablePagination.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/table/TablePagination.js b/src/components/table/TablePagination.js index 7c0c42600..c94a954db 100644 --- a/src/components/table/TablePagination.js +++ b/src/components/table/TablePagination.js @@ -289,8 +289,7 @@ class TablePagination extends Component { render() { const { - size, pageLength, handleChangePage, page, compressed, - disablePaginationShortcuts + size, pageLength, page, compressed } = this.props; const pages = size ? Math.ceil(size / pageLength) : 0;