@@ -3,7 +3,7 @@ import {Link, RouteComponentProps, withRouter} from "react-router-dom";
3
3
import { selectors , useAppSelector } from "../../state" ;
4
4
import { Badge , Card , CardBody , CardHeader , Container } from "reactstrap" ;
5
5
import queryString from "query-string" ;
6
- import { isAda , isPhy , isRelevantToPageContext , matchesAllWordsInAnyOrder , pushConceptsToHistory , searchResultIsPublic , shortcuts , TAG_ID , tags } from "../../services" ;
6
+ import { getFilteredStageOptions , isAda , isPhy , isRelevantToPageContext , matchesAllWordsInAnyOrder , pushConceptsToHistory , searchResultIsPublic , shortcuts , STAGE , STAGE_TO_LEARNING_STAGE , TAG_ID , tags } from "../../services" ;
7
7
import { generateSubjectLandingPageCrumbFromContext , TitleAndBreadcrumb } from "../elements/TitleAndBreadcrumb" ;
8
8
import { ShortcutResponse , Tag } from "../../../IsaacAppTypes" ;
9
9
import { IsaacSpinner } from "../handlers/IsaacSpinner" ;
@@ -49,6 +49,7 @@ export const Concepts = withRouter((props: RouteComponentProps) => {
49
49
const [ conceptFilters , setConceptFilters ] = useState < Tag [ ] > (
50
50
applicableTags . filter ( f => filters . includes ( f . id ) )
51
51
) ;
52
+ const [ searchStages , setSearchStages ] = useState < STAGE [ ] > ( [ ] ) ;
52
53
const [ shortcutResponse , setShortcutResponse ] = useState < ShortcutResponse [ ] > ( ) ;
53
54
54
55
const listConceptsQuery = useListConceptsQuery ( pageContext
@@ -58,8 +59,8 @@ export const Concepts = withRouter((props: RouteComponentProps) => {
58
59
59
60
const shortcutAndFilter = ( concepts ?: ContentSummaryDTO [ ] , excludeTopicFiltering ?: boolean ) => {
60
61
const searchResults = concepts ?. filter ( c =>
61
- matchesAllWordsInAnyOrder ( c . title , searchText || "" ) ||
62
- matchesAllWordsInAnyOrder ( c . summary , searchText || "" )
62
+ ( matchesAllWordsInAnyOrder ( c . title , searchText || "" ) || matchesAllWordsInAnyOrder ( c . summary , searchText || "" ) )
63
+ && ( searchStages . length === 0 || searchStages . some ( s => c . audience ?. some ( a => a . stage ?. includes ( s ) ) ) )
63
64
) ;
64
65
65
66
const filteredSearchResults = searchResults
@@ -81,6 +82,11 @@ export const Concepts = withRouter((props: RouteComponentProps) => {
81
82
[ t . id ] : shortcutAndFilter ( listConceptsQuery ?. data ?. results , true ) ?. filter ( c => c . tags ?. includes ( t . id ) ) . length || 0
82
83
} ) , { } ) ;
83
84
85
+ const stageCounts = getFilteredStageOptions ( ) . reduce ( ( acc , s ) => ( {
86
+ ...acc ,
87
+ [ s . value ] : shortcutAndFilter ( listConceptsQuery ?. data ?. results , true ) ?. filter ( c => c . audience ?. some ( a => a . stage ?. includes ( s . value ) ) ) . length || 0
88
+ } ) , { } ) ;
89
+
84
90
function doSearch ( e ?: FormEvent < HTMLFormElement > ) {
85
91
if ( e ) {
86
92
e . preventDefault ( ) ;
@@ -119,7 +125,7 @@ export const Concepts = withRouter((props: RouteComponentProps) => {
119
125
< SidebarLayout >
120
126
{ pageContext ?. subject
121
127
? < SubjectSpecificConceptListSidebar { ...sidebarProps } />
122
- : < GenericConceptsSidebar { ...sidebarProps } />
128
+ : < GenericConceptsSidebar { ...sidebarProps } searchStages = { searchStages } setSearchStages = { setSearchStages } stageCounts = { stageCounts } />
123
129
}
124
130
< MainContent >
125
131
{ pageContext ?. subject && < div className = "d-flex align-items-baseline flex-wrap flex-md-nowrap" >
0 commit comments