@@ -33,7 +33,7 @@ import { toastr } from "react-redux-toastr";
3333const createSortCandidatesMethod = ( sortBy ) => ( candidate1 , candidate2 ) => {
3434 switch ( sortBy ) {
3535 case CANDIDATES_SORT_BY . SKILL_MATCHED :
36- return candidate2 . skillMatched - candidate1 . skillMatched ;
36+ return candidate2 . skillsMatched - candidate1 . skillsMatched ;
3737 case CANDIDATES_SORT_BY . HANDLE :
3838 return new Intl . Collator ( ) . compare (
3939 candidate1 . handle . toLowerCase ( ) ,
@@ -42,18 +42,31 @@ const createSortCandidatesMethod = (sortBy) => (candidate1, candidate2) => {
4242 }
4343} ;
4444
45- const PositionCandidates = ( {
46- candidates,
47- candidateStatus,
48- updateCandidate,
49- } ) => {
45+ /**
46+ * Populates candidate objects with `skillsMatched` property
47+ * which define the number of candidate skills that match position skills
48+ *
49+ * @param {object } position position
50+ * @param {object } candidate candidate for position
51+ */
52+ const populateSkillsMatched = ( position , candidate ) => ( {
53+ ...candidate ,
54+ skillsMatched : _ . intersectionBy ( position . skills , candidate . skills , "id" ) ,
55+ } ) ;
56+
57+ const PositionCandidates = ( { position, candidateStatus, updateCandidate } ) => {
58+ const { candidates } = position ;
5059 const [ sortBy , setSortBy ] = useState ( CANDIDATES_SORT_BY . SKILL_MATCHED ) ;
5160 const filteredCandidates = useMemo (
5261 ( ) =>
53- _ . filter ( candidates , { status : candidateStatus } ) . sort (
54- createSortCandidatesMethod ( sortBy )
55- ) ,
56- [ candidates , candidateStatus , sortBy ]
62+ _ . chain ( candidates )
63+ . map ( ( candidate ) => populateSkillsMatched ( position , candidate ) )
64+ . filter ( {
65+ status : candidateStatus ,
66+ } )
67+ . value ( )
68+ . sort ( createSortCandidatesMethod ( sortBy ) ) ,
69+ [ candidates , candidateStatus , sortBy , position ]
5770 ) ;
5871
5972 const onSortByChange = useCallback (
@@ -158,7 +171,7 @@ const PositionCandidates = ({
158171 < div styleName = "table-cell cell-skills" >
159172 < SkillsSummary
160173 skills = { candidate . skills }
161- skillMatched = { candidate . skillMatched }
174+ requiredSkills = { position . skills }
162175 limit = { 7 }
163176 />
164177 { candidate . resumeLink && (
@@ -221,7 +234,7 @@ const PositionCandidates = ({
221234} ;
222235
223236PositionCandidates . propType = {
224- candidates : PT . array ,
237+ position : PT . object ,
225238 candidateStatus : PT . oneOf ( Object . values ( CANDIDATE_STATUS ) ) ,
226239} ;
227240
0 commit comments