Skip to content

Commit 061c559

Browse files
committed
OpenConceptLab/ocl_issues#2190 | on enter search and pagination
1 parent 0c048d6 commit 061c559

3 files changed

Lines changed: 29 additions & 12 deletions

File tree

src/components/map-projects/MapProject.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const MapProject = () => {
108108
const [matchedConcepts, setMatchedConcepts] = React.useState([]);
109109
const [otherMatchedConcepts, setOtherMatchedConcepts] = React.useState([]);
110110
const [searchedConcepts, setSearchedConcepts] = React.useState({});
111+
const [searchResponse, setSearchResponse] = React.useState({});
111112
const [algo, setAlgo] = React.useState('llm')
112113
const [notes, setNotes] = React.useState({})
113114
const [mapTypes, setMapTypes] = React.useState({})
@@ -303,6 +304,7 @@ const MapProject = () => {
303304
setMatchedConcepts([])
304305
setOtherMatchedConcepts([])
305306
setSearchedConcepts({})
307+
setSearchResponse({})
306308
setNotes({})
307309
setMapTypes({})
308310
setProposed({})
@@ -918,19 +920,22 @@ const MapProject = () => {
918920
}
919921
}
920922

921-
const searchCandidates = () => {
923+
const searchCandidates = (event, page, pageSize) => {
924+
console.log(params)
922925
setIsLoadingInDecisionView(true)
923926
APIService.new().overrideURL(repoVersion.version_url).appendToUrl('concepts/').get(null, null, {
924927
includeSearchMeta: true,
925928
includeMappings: true,
926929
mappingBrief: true,
927930
mapTypes: 'SAME-AS,SAME AS,SAME_AS',
928931
verbose: true,
929-
limit: 5,
930-
q: searchStr
932+
limit: pageSize || 5,
933+
q: searchStr,
934+
page: page || 1,
931935
}).then(response => {
932936
let items = response.data
933937
setSearchedConcepts({...searchedConcepts, [row.__index]: items})
938+
setSearchResponse(response)
934939
setIsLoadingInDecisionView(false)
935940
if(items.length > 0)
936941
setTimeout(() => highlightTexts(items, null, false), 100)
@@ -1418,12 +1423,14 @@ const MapProject = () => {
14181423
repo={repo}
14191424
repoVersion={repoVersion}
14201425
concepts={searchedConcepts[rowIndex]}
1426+
response={searchResponse}
14211427
setShowItem={setShowItem}
14221428
showItem={showItem}
14231429
isSelectedForMap={isSelectedForMap}
14241430
onMap={onMap}
14251431
searchStr={searchStr}
14261432
setSearchStr={setSearchStr}
1433+
onSearch={searchCandidates}
14271434
/>
14281435
}
14291436
</div>

src/components/map-projects/SearchCandidates.jsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,37 @@ import React from 'react'
22
import TextField from '@mui/material/TextField'
33
import Button from '@mui/material/Button';
44

5-
import orderBy from 'lodash/orderBy'
5+
import max from 'lodash/max'
66

77
import { highlightTexts } from '../../common/utils';
88
import SearchResults from '../search/SearchResults';
99
import Mappings from './Mappings'
1010
import Concept from './Concept'
1111

12-
const SearchCandidates = ({searchStr, setSearchStr, candidates, repo, repoVersion, rowIndex, concepts, setShowItem, showItem, isSelectedForMap, onMap}) => {
12+
const SearchCandidates = ({searchStr, setSearchStr, candidates, repo, repoVersion, rowIndex, concepts, setShowItem, showItem, isSelectedForMap, onMap, response, onSearch}) => {
13+
let total = parseInt(response?.headers?.num_found) || concepts?.length || 0
14+
const results = {total: total, pageSize: max([parseInt(response?.headers?.num_returned), 5]), page: parseInt(response?.headers?.page_number), pages: parseInt(response?.headers?.pages), results: response?.data || []}
15+
16+
const onKeyPress = event => {
17+
if(event.key === 'Enter') {
18+
if(searchStr)
19+
candidates(event)
20+
}
21+
}
22+
1323
return (
1424
<div className='col-xs-12 padding-0'>
1525
<div className='col-xs-12 padding-0' style={{display: 'flex', alignItems: 'center', margin: '16px 0'}}>
1626
<TextField
27+
autoFocus
1728
label='Search'
1829
sx={{width: 'calc(100% - 90px)'}}
1930
required
2031
id="search"
2132
value={searchStr}
2233
onChange={event => setSearchStr(event.target.value || '')}
2334
size='small'
35+
onKeyDown={onKeyPress}
2436
/>
2537
<Button
2638
color='primary'
@@ -52,22 +64,20 @@ const SearchCandidates = ({searchStr, setSearchStr, candidates, repo, repoVersio
5264
renderer={props => <Concept {...props} onMap={onMap} isSelectedForMap={isSelectedForMap} noScore />}
5365
display='card'
5466
nested
55-
results={{
56-
results: orderBy(concepts || [], 'search_meta.search_score', 'desc'),
57-
total: concepts?.length
58-
}}
67+
results={results}
5968
resource='concepts'
60-
noPagination
6169
noSorting
6270
noToolbar
63-
resultContainerStyle={{height: 'calc(100vh - 560px)'}}
71+
rowsPerPageOptions={-1}
72+
resultContainerStyle={{height: 'calc(100vh - 582px)'}}
6473
onShowItemSelect={item => {
6574
setShowItem(item)
6675
setTimeout(() => {
6776
highlightTexts([item], null, false)
6877
}, 100)
6978
}}
7079
selectedToShow={showItem}
80+
onPageChange={(page, pageSize) => onSearch(null, page, pageSize)}
7181
extraColumns={[
7282
{
7383
sortable: false,

src/components/search/SearchResults.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ const SearchResults = props => {
242242
{
243243
!props.noPagination &&
244244
<TablePagination
245-
rowsPerPageOptions={[10, 25, 50, 100]}
245+
rowsPerPageOptions={props.rowsPerPageOptions || [10, 25, 50, 100]}
246246
component="div"
247247
count={props.results?.total || 0}
248248
rowsPerPage={rowsPerPage || 25}

0 commit comments

Comments
 (0)