@@ -135,6 +135,7 @@ const MapProject = () => {
135135 const [ matchTypes , setMatchTypes ] = React . useState ( { very_high : 0 , high : 0 , medium : 0 , low : 0 , no_match : 0 } )
136136 const [ matchedConcepts , setMatchedConcepts ] = React . useState ( [ ] ) ;
137137 const [ otherMatchedConcepts , setOtherMatchedConcepts ] = React . useState ( [ ] ) ;
138+ const [ candidatesToSave , setCandidatesToSave ] = React . useState ( [ ] ) ;
138139 const [ searchedConcepts , setSearchedConcepts ] = React . useState ( { } ) ;
139140 const [ facets , setFacets ] = React . useState ( { } ) ;
140141 const [ appliedFacets , setAppliedFacets ] = React . useState ( { } ) ;
@@ -294,6 +295,7 @@ const MapProject = () => {
294295 setLoadingProject ( false )
295296 }
296297 setOtherMatchedConcepts ( response ?. data ?. candidates || [ ] )
298+ setCandidatesToSave ( response ?. data ?. candidates || [ ] )
297299 setName ( response . data ?. name || '' )
298300 setDescription ( response . data ?. description || '' )
299301 setOwner ( response . data ?. owner_url )
@@ -583,7 +585,7 @@ const MapProject = () => {
583585 }
584586 } )
585587 const candidates = [ ]
586- forEach ( otherMatchedConcepts , _candidates => {
588+ forEach ( candidatesToSave , _candidates => {
587589 if ( _candidates ?. results ?. length ) {
588590 candidates . push ( { ..._candidates , results : _candidates . results . splice ( 0 , 10 ) } )
589591 }
@@ -702,7 +704,7 @@ const MapProject = () => {
702704 return includeDefaultFilter ? allFilters : omit ( allFilters , Object . keys ( defaultFilters ) )
703705 }
704706
705- const getPayloadForMatching = ( rows , _repo ) => {
707+ const getPayloadForMatching = ( rows , _repo , _filters ) => {
706708 return {
707709 rows : map ( rows , row => prepareRow ( row ) ) ,
708710 target_repo_url : repoVersion ?. version_url || _repo . version_url || _repo . url ,
@@ -713,7 +715,7 @@ const MapProject = () => {
713715 'source' : _repo . short_code || _repo . id
714716 } ,
715717 map_config : getMapConfigs ( ) ,
716- filter : getFilters ( )
718+ filter : rows . length > 1 ? getFilters ( ) : getFacetQueryParam ( isEmpty ( _filters ) ? appliedFacets [ rows [ 0 ] . __index ] : _filters )
717719 }
718720 }
719721
@@ -818,6 +820,9 @@ const MapProject = () => {
818820 setOtherMatchedConcepts ( prev => {
819821 return [ ...reject ( prev , c => c . row . __index === concept . row . __index ) , concept ]
820822 } )
823+ setCandidatesToSave ( prev => {
824+ return [ ...reject ( prev , c => c . row . __index === concept . row . __index ) , concept ]
825+ } )
821826 } )
822827 setMatchedConcepts ( prev => [ ...prev , ...data ] ) ;
823828 activeRequests . delete ( promise ) ; // Remove from active set after completion
@@ -1264,17 +1269,17 @@ const MapProject = () => {
12641269 log ( { action : newValue || 'decision_changed' , description : 'Desicion Changed to None' , extras : newValue ? { } : { decision : 'None' } } )
12651270 }
12661271
1267- const fetchOtherCandidates = ( _row , offset = 0 , _retired , scrollToBottom ) => {
1272+ const fetchOtherCandidates = ( _row , offset = 0 , _retired , scrollToBottom , _filters , forceReload = false ) => {
12681273 setAlert ( false )
12691274 if ( isAnyValidColumn ( ) ) {
12701275 let __row = isEmpty ( _row ) ? row : _row
12711276 const existingCandidates = find ( otherMatchedConcepts , c => c . row . __index === __row . __index ) ?. results
1272- if ( offset === 0 && ! _retired && existingCandidates ?. length > 0 ) {
1277+ if ( ! forceReload && offset === 0 && ! _retired && existingCandidates ?. length > 0 ) {
12731278 setTimeout ( ( ) => highlightTexts ( existingCandidates , null , false ) , 100 )
12741279 return
12751280 }
12761281 setIsLoadingInDecisionView ( true )
1277- const payload = getPayloadForMatching ( [ __row ] , repo )
1282+ const payload = getPayloadForMatching ( [ __row ] , repo , _filters )
12781283 const service = getMatchAPIService ( )
12791284 service . post (
12801285 payload ,
@@ -2031,10 +2036,11 @@ const MapProject = () => {
20312036 columns = { getValidColumns ( ) }
20322037 facets = { facets [ rowIndex ] }
20332038 appliedFacets = { appliedFacets [ rowIndex ] }
2039+ defaultFilters = { getAppliedFacetFromQueryParam ( getFilters ( ) ) }
20342040 filters = { getFilters ( rowIndex ) }
20352041 setAppliedFacets = { ( filters ) => {
2036- setAppliedFacets ( { ...appliedFacets , [ rowIndex ] : filters } )
2037- search ( null , null , null , null , filters )
2042+ setAppliedFacets ( ( ) => ( { ...appliedFacets , [ rowIndex ] : filters } ) )
2043+ fetchOtherCandidates ( null , 0 , false , false , filters , true )
20382044 } }
20392045 />
20402046 }
@@ -2057,6 +2063,7 @@ const MapProject = () => {
20572063 columns = { getValidColumns ( ) }
20582064 facets = { facets [ rowIndex ] }
20592065 appliedFacets = { appliedFacets [ rowIndex ] }
2066+ defaultFilters = { getAppliedFacetFromQueryParam ( getFilters ( ) ) }
20602067 filters = { getFilters ( ) }
20612068 setAppliedFacets = { ( filters ) => {
20622069 setAppliedFacets ( { ...appliedFacets , [ rowIndex ] : filters } )
0 commit comments