From f639ae1319ab0362d0c75a9b7b54e7d0d7d1c283 Mon Sep 17 00:00:00 2001 From: jue-henry Date: Wed, 14 Aug 2024 14:46:23 -0700 Subject: [PATCH] Update label filter to reduce use of none selected --- src/features/filters/BulkSelectCheckbox.jsx | 15 +++------------ src/features/filters/filtersSlice.js | 6 +++--- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/features/filters/BulkSelectCheckbox.jsx b/src/features/filters/BulkSelectCheckbox.jsx index 084bbca4..12b848ea 100644 --- a/src/features/filters/BulkSelectCheckbox.jsx +++ b/src/features/filters/BulkSelectCheckbox.jsx @@ -24,11 +24,11 @@ const StyledBulkSelectCheckbox = styled('div', { const BulkSelectCheckbox = ({ filterCat, managedIds, isHeader }) => { const activeFilters = useSelector(selectActiveFilters); - const [checkboxState, setCheckboxState] = useState('someSelected'); + const [checkboxState, setCheckboxState] = useState('allSelected'); const dispatch = useDispatch(); const stateMap = { - noneSelected: { + notAllSelected: { checked: false, active: false, indeterminate: false, @@ -40,25 +40,16 @@ const BulkSelectCheckbox = ({ filterCat, managedIds, isHeader }) => { indeterminate: false, label: 'unselect all', }, - someSelected: { - checked: false, - active: true, - indeterminate: true, - label: 'clear selection', - }, }; useEffect(() => { const allSelected = (idsToCheck, activeIds) => (activeIds && idsToCheck.every((id) => activeIds.includes(id))) || activeIds === null; - const noneSelected = (idsToCheck, activeIds) => activeIds && idsToCheck.every((id) => !activeIds.includes(id)); if (allSelected(managedIds, activeFilters[filterCat])) { setCheckboxState('allSelected'); - } else if (noneSelected(managedIds, activeFilters[filterCat])) { - setCheckboxState('noneSelected'); } else { - setCheckboxState('someSelected'); + setCheckboxState('notAllSelected'); } }, [activeFilters, filterCat, managedIds]); diff --git a/src/features/filters/filtersSlice.js b/src/features/filters/filtersSlice.js index fe2dd529..d41ddda1 100644 --- a/src/features/filters/filtersSlice.js +++ b/src/features/filters/filtersSlice.js @@ -82,12 +82,12 @@ export const filtersSlice = createSlice({ const availIds = state.availFilters[filterCat].options.map(({ _id }) => _id); let newActiveIds; - if (currState === 'noneSelected') { - // none are currently selected, so add all managedIds to activeFilters + if (currState !== 'allSelected') { + // not all labels are currently selected, so add all managedIds to activeFilters const idsToAdd = managedIds.filter((id) => !activeIds.includes(id)); newActiveIds = activeIds.concat(idsToAdd); } else { - // some or all managed ids are selected, so unselect all: + // all managed ids are selected, so unselect all: // i.e, return all available Ids, minus the managed ids newActiveIds = activeIds === null