From 9b463f042910c55842e387a0603ce860136e14df Mon Sep 17 00:00:00 2001 From: Shohan Date: Tue, 13 Jul 2021 18:19:23 +0530 Subject: [PATCH] [refactor] Remove repeated logic in bulk-actions.js --- client/src/entrypoints/admin/bulk-actions.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/client/src/entrypoints/admin/bulk-actions.js b/client/src/entrypoints/admin/bulk-actions.js index 4f53ae9d9a..da56f145bc 100644 --- a/client/src/entrypoints/admin/bulk-actions.js +++ b/client/src/entrypoints/admin/bulk-actions.js @@ -61,23 +61,17 @@ function SelectBulkActionsCheckboxes(e) { if (checkedState.checkedPages.size > 0) { /* Update text on number of pages */ let numPagesSelected = ''; - if (checkedState.checkedPages.size === checkedState.numPages) { - document.querySelector(`.${BULK_ACTION_NUM_PAGES_IN_LISTING}`).classList.remove('u-hidden'); - if (checkedState.numPages === 1) { - numPagesSelected = wagtailConfig.STRINGS.NUM_PAGES_SELECTED_SINGULAR; - } else { - numPagesSelected = wagtailConfig.STRINGS.NUM_PAGES_SELECTED_ALL.replace('{0}', checkedState.checkedPages.size); - } + const numCheckPages = checkedState.checkedPages.size; + if (numCheckPages === 1) { + numPagesSelected = wagtailConfig.STRINGS.NUM_PAGES_SELECTED_SINGULAR; } else { - document.querySelector(`.${BULK_ACTION_NUM_PAGES_IN_LISTING}`).classList.add('u-hidden'); - if (checkedState.checkedPages.size === 1) { - numPagesSelected = wagtailConfig.STRINGS.NUM_PAGES_SELECTED_SINGULAR; + if (numCheckPages === checkedState.numPages) { + numPagesSelected = wagtailConfig.STRINGS.NUM_PAGES_SELECTED_ALL.replace('{0}', numCheckPages); } else { - numPagesSelected = wagtailConfig.STRINGS.NUM_PAGES_SELECTED_PLURAL.replace( - '{0}', checkedState.checkedPages.size - ); + numPagesSelected = wagtailConfig.STRINGS.NUM_PAGES_SELECTED_PLURAL.replace('{0}', numCheckPages); } } + document.querySelector(`.${BULK_ACTION_NUM_PAGES_IN_LISTING}`).classList.add('u-hidden'); document.querySelector(`.${BULK_ACTION_NUM_PAGES_SPAN}`).textContent = numPagesSelected; } }