Skip to content

Commit af99f43

Browse files
committed
Reselect subject when fields deselected
On the generic concept finder: if a subject and fields are selected, and the fields are then deselected, reselect the subject. This now matches the behaviour of the question finder.
1 parent 0ccce16 commit af99f43

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/app/components/elements/layout/SidebarLayout.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,13 @@ const FilterCheckbox = (props : FilterCheckboxProps) => {
335335
}, [conceptFilters, tag]);
336336

337337
const handleCheckboxChange = (checked: boolean) => {
338+
// Reselect parent if all children are deselected
339+
const siblingTags = tag.type === "field" && incompatibleTags ? tags.getDirectDescendents(incompatibleTags[0].id).filter(t => t !== tag) : [];
340+
const reselectParent = siblingTags.length && !siblingTags.some(t => conceptFilters.includes(t));
341+
338342
const newConceptFilters = checked
339343
? [...conceptFilters.filter(c => !incompatibleTags?.includes(c)), ...(!partiallySelected ? [tag] : [])]
340-
: conceptFilters.filter(c => ![tag, ...(dependentTags ?? [])].includes(c));
344+
: [...conceptFilters.filter(c => ![tag, ...(dependentTags ?? [])].includes(c)), ...(reselectParent ? [incompatibleTags![0]] : [])];
341345
setConceptFilters(newConceptFilters.length > 0 ? newConceptFilters : (baseTag ? [baseTag] : []));
342346
};
343347

0 commit comments

Comments
 (0)