@@ -30,31 +30,32 @@ const TeamMembers = ({ team }) => {
3030
3131 const filteredMembers = useMemo (
3232 ( ) =>
33- resources . filter ( ( member ) => {
34- const filterLowerCase = filter . toLowerCase ( ) ;
35- const lookupFields = _ . compact ( [
36- member . handle ,
37- member . firstName ,
38- member . lastName ,
39- member . role ,
40- ..._ . map ( member . skills , "name" ) ,
41- ] ) . map ( ( field ) => field . toLowerCase ( ) ) ;
33+ resources
34+ // populate resources with job data first
35+ . map ( ( member ) => ( {
36+ ...member ,
37+ job : _ . find ( jobs , { id : member . jobId } ) || { } ,
38+ } ) )
39+ // now we can filter resources
40+ . filter ( ( member ) => {
41+ const filterLowerCase = filter . toLowerCase ( ) . trim ( ) ;
42+ const lookupFields = _ . compact ( [
43+ member . handle ,
44+ member . firstName ,
45+ member . lastName ,
46+ `${ member . firstName } ${ member . lastName } ` , // full name
47+ member . job . description ,
48+ ..._ . map ( member . skills , "name" ) ,
49+ ] ) . map ( ( field ) => field . toLowerCase ( ) ) ;
4250
43- return _ . some (
44- lookupFields ,
45- ( field ) => field . indexOf ( filterLowerCase ) > - 1
46- ) ;
47- } ) ,
48- [ resources , filter ]
51+ return _ . some (
52+ lookupFields ,
53+ ( field ) => field . indexOf ( filterLowerCase ) > - 1
54+ ) ;
55+ } ) ,
56+ [ resources , filter , jobs ]
4957 ) ;
5058
51- const filteredMembersWithJobs = useMemo ( ( ) => {
52- return filteredMembers . map ( ( member ) => ( {
53- ...member ,
54- job : _ . find ( jobs , { id : member . jobId } ) || { } ,
55- } ) ) ;
56- } , [ filteredMembers , jobs ] ) ;
57-
5859 const onFilterChange = useCallback (
5960 ( event ) => {
6061 setFilter ( event . target . value ) ;
@@ -76,8 +77,8 @@ const TeamMembers = ({ team }) => {
7677 const pagesTotal = Math . ceil ( filteredMembers . length / perPage ) ;
7778
7879 const pageMembers = useMemo (
79- ( ) => filteredMembersWithJobs . slice ( ( page - 1 ) * perPage , page * perPage ) ,
80- [ filteredMembersWithJobs , page , perPage ]
80+ ( ) => filteredMembers . slice ( ( page - 1 ) * perPage , page * perPage ) ,
81+ [ filteredMembers , page , perPage ]
8182 ) ;
8283
8384 const onPageClick = useCallback (
@@ -101,10 +102,10 @@ const TeamMembers = ({ team }) => {
101102 }
102103 />
103104 { resources . length === 0 && < div styleName = "no-members" > No members</ div > }
104- { resources . length > 0 && filteredMembersWithJobs . length === 0 && (
105+ { resources . length > 0 && filteredMembers . length === 0 && (
105106 < div styleName = "no-members" > No members matching filter</ div >
106107 ) }
107- { filteredMembersWithJobs . length > 0 && (
108+ { filteredMembers . length > 0 && (
108109 < div styleName = "table" >
109110 { pageMembers . map ( ( member ) => (
110111 < div styleName = "table-row" key = { member . id } >
@@ -181,15 +182,15 @@ const TeamMembers = ({ team }) => {
181182 type = "secondary"
182183 onClick = { showMore }
183184 disabled = {
184- filteredMembersWithJobs . length === 0 || // if no members to show
185+ filteredMembers . length === 0 || // if no members to show
185186 page === pagesTotal // if we are already on the last page
186187 }
187188 >
188189 Show More
189190 </ Button >
190- { filteredMembersWithJobs . length > 0 && (
191+ { filteredMembers . length > 0 && (
191192 < Pagination
192- total = { filteredMembersWithJobs . length }
193+ total = { filteredMembers . length }
193194 currentPage = { page }
194195 perPage = { perPage }
195196 onPageClick = { onPageClick }
0 commit comments