Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update label filter to reduce use of none selected #231

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions src/features/filters/BulkSelectCheckbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]);

Expand Down
6 changes: 3 additions & 3 deletions src/features/filters/filtersSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading