Skip to content

Commit 2243515

Browse files
committed
Add filter clear-ing context-dependently
1 parent cae148a commit 2243515

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/app/components/elements/panels/QuestionFinderFilterPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export function QuestionFinderFilterPanel(props: QuestionFinderFilterPanelProps)
229229
{(isAda || !pageContext.stage) && <CollapsibleList
230230
title={listTitles.stage} expanded={listState.stage.state}
231231
toggle={() => listStateDispatch({type: "toggle", id: "stage", focus: below["md"](deviceSize)})}
232-
numberSelected={(isAda && searchStages.includes(STAGE.ALL)) ? searchStages.length - 1 : searchStages.length}
232+
numberSelected={(isAda && searchStages.includes(STAGE.ALL)) ? searchStages.length - 1 : searchStages.filter(s => s !== pageContext.stage).length}
233233
>
234234
{getFilteredStageOptions().map((stage, index) => (
235235
<div className={classNames("w-100 ps-3 py-1", {"bg-white": isAda, "ms-2": isPhy, "bg-grey": isPhy && searchStages.includes(stage.value)})} key={index}>
@@ -261,7 +261,7 @@ export function QuestionFinderFilterPanel(props: QuestionFinderFilterPanelProps)
261261
<CollapsibleList
262262
title={listTitles.topics} expanded={listState.topics.state}
263263
toggle={() => listStateDispatch({type: "toggle", id: "topics", focus: below["md"](deviceSize)})}
264-
numberSelected={siteSpecific(getChoiceTreeLeaves(selections).length, searchTopics.length)}
264+
numberSelected={siteSpecific(getChoiceTreeLeaves(selections).filter(l => l.value !== pageContext.subject).length, searchTopics.length)}
265265
>
266266
{siteSpecific(
267267
<div>

src/app/components/elements/svg/HierarchyFilter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ export function HierarchyFilterHexagonal({tier, index, tiers, choices, selection
6464
}
6565
};
6666

67-
return <div key={choice.value} className={classNames("ps-3 ms-2", {"ms-3": tier===1, "ms-4 search-field": tier===2, "bg-white": tier===0 && isSelected, "bg-light": tier===1 && isSelected})}>
67+
return <div key={choice.value} className={classNames("ps-3 ms-2", {"ms-3": tier===1, "ms-4 search-field": tier===2, "bg-white": tier===0 && isSelected, "bg-grey": tier===1 && isSelected})}>
6868
<StyledCheckbox
6969
color="primary"
7070
checked={isSelected}
7171
onChange={selectValue}
7272
label={<span>{choice.label}</span>}
7373
/>
7474
{tier < 2 && choices[tier+1] && choice.value in choices[tier+1] &&
75-
<HierarchyFilterHexagonal {...{tier: tier+1, index: choice.value, tiers, choices, selections, questionFinderFilter, setTierSelection}} className={classNames({"bg-white": tier===0, "bg-light": tier===1})}/>
75+
<HierarchyFilterHexagonal {...{tier: tier+1, index: choice.value, tiers, choices, selections, questionFinderFilter, setTierSelection}} className={classNames({"bg-white": tier===0})}/>
7676
}
7777
</div>;
7878
}

src/app/components/pages/QuestionFinder.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,10 @@ export const QuestionFinder = withRouter(({location}: RouteComponentProps) => {
385385
setSearchDifficulties([]);
386386
setSearchTopics([]);
387387
setSearchExamBoards([]);
388-
setSearchStages([]);
388+
setSearchStages(pageContext.stage ? [pageContext.stage as STAGE] : []);
389389
setSearchBooks([]);
390390
setExcludeBooks(false);
391-
setSelections([{}, {}, {}]);
391+
setSelections([pageContext.subject ? {"subject": [itemiseTag(tags.getById(pageContext.subject as TAG_ID))]} : {}, {}, {}]);
392392
setSearchStatuses(
393393
{
394394
notAttempted: false,
@@ -429,19 +429,27 @@ export const QuestionFinder = withRouter(({location}: RouteComponentProps) => {
429429

430430
const FilterTag = ({name}: {name: string}) => {
431431
return (
432-
<div className="tag">
432+
<div className="quiz-level-1-tag me-2">
433433
{name}
434434
</div>
435435
);
436436
};
437437

438438
const FilterSummary = () => {
439-
const selectionList: string[] = getChoiceTreeLeaves(selections).map(leaf => leaf.label);
439+
const stageList: string[] = searchStages.filter(stage => stage !== pageContext.stage);
440+
const selectionList: string[] = getChoiceTreeLeaves(selections).filter(leaf => leaf.value !== pageContext.subject).map(leaf => leaf.label);
440441
const statusList: string[] = Object.keys(searchStatuses).filter(status => searchStatuses[status as keyof QuestionStatus]);
441442

442-
const categories = [searchDifficulties, searchTopics, searchStages, searchExamBoards, statusList, searchBooks, selectionList];
443+
const categories = [searchDifficulties, searchTopics, stageList, searchExamBoards, statusList, searchBooks, selectionList].flat();
443444

444-
return <div> {categories.map(c => c.map(c2 => <FilterTag key={c2} name={c2}/>))} </div>;
445+
return <div className="d-flex">
446+
{categories.map(c => <FilterTag key={c} name={c}/>)}
447+
{categories.length > 0 ?
448+
<button className="text-black py-0 btn-link bg-transparent" onClick={(e) => { e.stopPropagation(); clearFilters(); }}>
449+
clear all filters
450+
</button>
451+
: <div/>}
452+
</div>;
445453
};
446454

447455
return <Container id="finder-page" className={classNames("mb-5")} { ...(pageContext?.subject && { "data-bs-theme" : pageContext.subject })}>
@@ -498,7 +506,7 @@ export const QuestionFinder = withRouter(({location}: RouteComponentProps) => {
498506
</Col>
499507
</Row>}
500508

501-
<FilterSummary />
509+
{isPhy && <FilterSummary/>}
502510

503511
<Row className="mt-4 position-relative finder-panel">
504512
<Col lg={siteSpecific(4, 3)} md={12} xs={12} className={classNames("text-wrap my-2", {"d-none": isPhy})} data-testid="question-finder-filters">

0 commit comments

Comments
 (0)