Skip to content

Commit 1ba02ff

Browse files
committed
1 parent cf1f0a7 commit 1ba02ff

10 files changed

Lines changed: 147 additions & 37 deletions

File tree

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@
253253
"intensional",
254254
"nullable",
255255
"versioning",
256-
"unversioned"
256+
"unversioned",
257+
"reranker"
257258
],
258259
"skipIfMatch": [
259260
"http://[^s]*",

src/common/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export const canSwitchServer = () => {
445445
);
446446
}
447447

448-
const hasAuthGroup = (user, groupName) => Boolean(find(user?.auth_groups, group => group.includes(groupName)))
448+
export const hasAuthGroup = (user, groupName) => Boolean(find(user?.auth_groups, group => group.includes(groupName)))
449449

450450
export const canViewOperationsPanel = () => {
451451
const user = getCurrentUser()

src/components/app/LayoutContext.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const LayoutContext = ({ subPages }) => {
1111
const [parentItem, setParentItem] = React.useState(null);
1212
const [toggles, setToggles] = React.useState({});
1313
const [alert, setAlert] = React.useState(false);
14+
const [contextRepo, setContextRepo] = React.useState(false)
1415
return (
1516
<OperationsProvider
1617
value={{
@@ -27,7 +28,9 @@ const LayoutContext = ({ subPages }) => {
2728
setToggles: setToggles,
2829
toggles: toggles,
2930
alert: alert,
30-
setAlert: setAlert
31+
setAlert: setAlert,
32+
contextRepo: contextRepo,
33+
setContextRepo: setContextRepo
3134
}}>
3235
{subPages}
3336
</OperationsProvider>

src/components/repos/RepoHome.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ const RepoHome = () => {
5555
const versionFromURL = (TAB_KEYS.includes(params?.repoVersion) ? '' : params.repoVersion) || ''
5656

5757
const [tab, setTab] = React.useState(findTab)
58-
const { setAlert } = React.useContext(OperationsContext);
58+
const { setAlert, setContextRepo } = React.useContext(OperationsContext);
5959

6060
const getURL = () => ((toParentURI(location.pathname) + '/').replace('//', '/') + versionFromURL + '/').replace('//', '/')
61+
6162
const fetchRepo = () => {
6263
setLoading(true)
6364
setStatus(false)
@@ -67,6 +68,8 @@ const RepoHome = () => {
6768
setLoading(false)
6869
const _repo = response?.data || response?.response?.data || {}
6970
setRepo(_repo)
71+
if(!isCollection)
72+
setContextRepo(_repo)
7073
fetchOwner()
7174
fetchRepoSummary()
7275
if(isCollection)
@@ -117,6 +120,14 @@ const RepoHome = () => {
117120
fetchVersions()
118121
}, [location.pathname])
119122

123+
React.useEffect(() => {
124+
return () => {
125+
// runs on unmount
126+
setContextRepo(false);
127+
};
128+
}, []);
129+
130+
120131
const onVersionChange = (version, reload=true) => {
121132
if(reload)
122133
setLoading(true)

src/components/search/Search.jsx

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const FILTERS_WIDTH = 250
2323
const FILTERABLE_RESOURCES = ['concepts', 'mappings', 'repos', 'sources', 'collections', 'references']
2424

2525
const Search = props => {
26-
const { setAlert } = React.useContext(OperationsContext);
26+
const { setAlert, contextRepo } = React.useContext(OperationsContext);
2727
const { t } = useTranslation()
2828
const history = useHistory();
2929
const location = useLocation();
@@ -40,6 +40,8 @@ const Search = props => {
4040
const [showItem, setShowItem] = React.useState(false)
4141
const [order, setOrder] = React.useState('desc');
4242
const [orderBy, setOrderBy] = React.useState('score');
43+
const [isMatchOp, setIsMatchOp] = React.useState(false)
44+
4345
const didMount = React.useRef(false);
4446
const isFilterable = _resource => FILTERABLE_RESOURCES.includes(_resource)
4547

@@ -69,6 +71,8 @@ const Search = props => {
6971
const getCurrentLayoutURL = (params, _resource) => {
7072
/*eslint no-unused-vars: 0*/
7173
const { q, page, limit, includeSearchMeta, sortAsc, sortDesc, ...filters} = params
74+
const isMatch = params['$match']
75+
delete filters['$match']
7276
_resource = _resource || resource || 'concepts'
7377
if(_resource === 'organizations')
7478
_resource = 'orgs'
@@ -81,6 +85,8 @@ const Search = props => {
8185
url += `&limit=${limit}`
8286
if(page && page > 1)
8387
url += `&page=${page}`
88+
if(isMatch)
89+
url += '&$match=true'
8490
if(!isEmpty(filters)){
8591
if(_resource === 'references')
8692
url += Object.entries(filters)
@@ -129,6 +135,7 @@ const Search = props => {
129135
const setQueryParamsInState = (mustFetch, includeRepoDefaultFilters) => {
130136
const queryParams = new URLSearchParams(window.location.hash.split('?')[1])
131137
const value = queryParams.get('q') || ''
138+
const isMatch = queryParams.get('$match') === 'true'
132139
const isDiffFromPrevInput = value !== input
133140
const _page = parseInt(queryParams.get('page') || 1)
134141
const _pageSize = parseInt(queryParams.get('limit') || 25)
@@ -156,6 +163,11 @@ const Search = props => {
156163
if(includeRepoDefaultFilters && !_filters && props.repoDefaultFilters) {
157164
_filters = getAppliedFacetFromQueryParam(props.repoDefaultFilters)
158165
}
166+
if(!isEqual(isMatch, isMatchOp)) {
167+
setIsMatchOp(isMatch)
168+
_fetch = true
169+
_fetchFacets = false
170+
}
159171
if(!isEqual(filters, _filters)) {
160172
setFilters(_filters)
161173
_fetchFacets = true
@@ -184,8 +196,12 @@ const Search = props => {
184196
_fetch = true
185197
}
186198

187-
if(_fetch)
188-
fetchResults(getQueryParams(value, _page, _pageSize, _filters, _orderBy, _order), _fetchFacets, _resource)
199+
if(_fetch) {
200+
if(isMatch)
201+
fetchMatchResults(getQueryParams(value, _page, _pageSize, _filters, _orderBy, _order))
202+
else
203+
fetchResults(getQueryParams(value, _page, _pageSize, _filters, _orderBy, _order), _fetchFacets, _resource)
204+
}
189205
}
190206

191207
const getAppliedFacetFromQueryParam = filters => {
@@ -227,6 +243,8 @@ const Search = props => {
227243
} else if(!_input) {
228244
params.sortAsc = 'id'
229245
}
246+
if(isMatchOp)
247+
params['$match'] = true
230248
return params
231249
}
232250

@@ -274,6 +292,31 @@ const Search = props => {
274292
})
275293
}
276294

295+
296+
const fetchMatchResults = (params) => {
297+
let __resource = 'concepts'
298+
setLoading(true)
299+
setResult(prev => {
300+
return {...prev, [__resource]: {...result[__resource], results: []}}
301+
})
302+
let _filters = omit(params, ['q', 'page', 'page_number', 'page_size', 'limit', 'offset', 'includeSearchMeta', 'verbose', 'order', 'orderBy', 'sortAsc', 'sortDesc', 'display', 'type'])
303+
const payload = {rows: [{name: params.q}], target_repo_url: contextRepo?.version_url, filter: _filters || {}}
304+
APIService.new().overrideURL('/concepts/$match/').post(payload, null, null, {verbose: true, includeSearchMeta: true, semantic: true, reranker: true, ...params}).then(response => {
305+
if(response?.detail) {
306+
setAlert({message: response.detail, severity: 'error', duration: 5000})
307+
setLoading(false)
308+
return
309+
}
310+
let __results = get(response, 'data.0.results') || []
311+
let total = __results.length + 10
312+
const resourceResult = {total: total, pageSize: params?.limit || 10, page: params?.page || params?.page_number || 1, pages: 2, results: __results || [], facets: result[__resource]?.facets || {}}
313+
setResult(prev => {
314+
return {...result, [__resource]: resourceResult}
315+
})
316+
setLoading(false)
317+
})
318+
}
319+
277320
const fetchFacets = (params, otherResults, _resource=undefined) => {
278321
setLoadingFacets(true)
279322
const __resource = _resource || resource
@@ -451,6 +494,7 @@ const Search = props => {
451494
excludedColumns={props.excludedColumns}
452495
properties={props.properties}
453496
propertyFilters={props.propertyFilters}
497+
isMatch={isMatchOp}
454498
/>
455499
</div>
456500
</div>

src/components/search/SearchInput.jsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ const SearchInput = props => {
2828
return false
2929
}
3030

31-
const initiateSearch = (event, global) => {
32-
performSearch(event, input, global)
33-
setOpen(false)
34-
setTimeout(blurInput, 1000)
31+
const initiateSearch = (event, global, isMatch) => {
32+
performSearch(event, input, global, isMatch)
33+
setOpen(false)
34+
setTimeout(blurInput, 1000)
3535
}
3636

37-
const performSearch = (event, value, global) => {
37+
const performSearch = (event, value, global, isMatch) => {
3838
event.preventDefault()
3939
event.stopPropagation()
4040

41-
props.onSearch ? props.onSearch(value) : moveToSearchPage(value, global)
41+
props.onSearch ? props.onSearch(value) : moveToSearchPage(value, global, isMatch)
4242
}
4343

4444
const blurInput = () => {
@@ -64,13 +64,17 @@ const SearchInput = props => {
6464
return URL
6565
}
6666

67-
const moveToSearchPage = (value, global) => {
67+
const moveToSearchPage = (value, global, isMatch) => {
6868
if(!props.nested || global) {
6969
let _input = value || '';
7070
const queryParams = new URLSearchParams(location.search)
7171
const resourceType = queryParams.get('type') || 'concepts'
7272
const isGlobal = (location.pathname === '/' || global)
7373
let URL = applyURLRules(isGlobal ? '/search/' : location.pathname)
74+
if(isMatch)
75+
queryParams.set('$match', true)
76+
else
77+
queryParams.delete('$match')
7478
if(_input) {
7579
queryParams.set('q', _input)
7680
if(isGlobal)
@@ -79,6 +83,7 @@ const SearchInput = props => {
7983
} else if(isGlobal || queryParams.get('type')) {
8084
URL += `?type=${resourceType}`
8185
}
86+
8287
history.push(URL.replace('?&', '?'));
8388
}
8489
}
@@ -107,11 +112,15 @@ const SearchInput = props => {
107112
setTimeout(blurInput, 50)
108113
}
109114

115+
const checkIsMatchOp = () => new URLSearchParams(location.search).get('$match') === 'true'
116+
const isMatchOp = checkIsMatchOp()
117+
110118
return (
111119
<React.Fragment>
112120
<SearchInputText
113121
id='search-input'
114122
onClick={() => setOpen(true)}
123+
isMatchOp={isMatchOp}
115124
{...inputProps}
116125
/>
117126
<SearchInputDrawer
@@ -120,6 +129,7 @@ const SearchInput = props => {
120129
input={input || ''}
121130
initiateSearch={initiateSearch}
122131
inputProps={inputProps}
132+
isMatchOp={isMatchOp}
123133
/>
124134
</React.Fragment>
125135
)

0 commit comments

Comments
 (0)