Skip to content

Commit bf40379

Browse files
committed
UISAUTCOMP-95 Use first page Browse query for facet requests. (#130)
* UISAUTCOMP-95 Use first page Browse query for facet requests. * UISAUTCOMP-95 Use existing query prop in AuthoritiesSearchPane * UISAUTCOMP-95 Include current facets in firstPageQuery * UISAUTCOMP-95 Added readme for useAuthoritiesBrowse hook
1 parent 8e9bbf2 commit bf40379

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change history for stripes-authoriy-components
22

3+
## [3.0.2] IN PROGRESS
4+
5+
- [UISAUTCOMP-95](https://issues.folio.org/browse/UISAUTCOMP-95) Use first page Browse query for facet requests.
6+
37
## [3.0.1] (https://github.com/folio-org/stripes-authority-components/tree/v3.0.1) (2023-10-27)
48

59
- [UISAUTCOMP-87](https://issues.folio.org/browse/UISAUTCOMP-87) Highlight the Browse search list row after editing the 1xx field.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# useAuthoritiesBrowse
2+
This hook contains logic of Authority browsing functionality.
3+
4+
### Usage
5+
6+
`useAuthoritiesBrowse` returns an object with following properties:
7+
8+
Name | type | description
9+
--- | --- | --- |
10+
`authorities` | array | Array of found Authority records
11+
`isLoading` | bool | Is a request pending
12+
`isLoaded` | bool | Has a request finished
13+
`hasNextPage` | bool | Can browse a next page
14+
`hasPrevPage` | bool | Can browse a previous page
15+
`handleLoadMore` | function | Function to fetch more data. Same API as `MCL`'s `onNeedMoreData`
16+
`query` | string | Formatted query string that is used for fetching results for currently browsed page
17+
`firstPageQuery` | string | Formatted query string that was used for fetching results for first browsed page (page with anchor)
18+
`totalRecords` | number | Number of total records found
19+
20+
21+
### Props
22+
Name | type | description | default | required
23+
--- | --- | --- | --- | ---
24+
`searchQuery` | string | Seqrch query provided by user | `` | true
25+
`searchIndex` | string | Search index provided by user | `` | true
26+
`filters` | object | Selected search filters. Structure: `{ filterName: ['filterValue1', 'filterValue2'] }`| undefined | true
27+
`pageSize` | number | Number of results per page | undefined | true
28+
`precedingRecordsCount` | number | Number of records before anchor item in results list | undefined | true
29+
`browsePageQuery` | string | Query that will be searched when viewing Next or Previous page | undefined | false
30+
`setBrowsePageQuery` | function | Setter function for `browsePageQuery` | undefined | true
31+
`browsePage` | number | Numerical order of the current viewed Browse page | undefined | false
32+
`setBrowsePage` | function | Setter function for `browsePage` | undefined | true
33+
`navigationSegmentValue` | string | Current segment of MARC authority search and browse view | undefined | false.
34+
`tenantId` | string | Tenant id in a multi-tenant environment | undefined | false

lib/queries/useAuthoritiesBrowse/useAuthoritiesBrowse.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,8 @@ import { useTenantKy } from '../../temp/hooks/useTenantKy';
2121

2222
const AUTHORITIES_BROWSE_API = 'browse/authorities';
2323

24-
const useBrowseRequest = ({
25-
filters,
26-
searchQuery,
27-
searchIndex,
28-
startingSearch,
29-
pageSize,
30-
precedingRecordsCount,
31-
tenantId,
32-
}) => {
33-
const ky = useTenantKy({ tenantId });
34-
const [namespace] = useNamespace({ key: QUERY_KEY_AUTHORITIES });
35-
36-
const cqlSearch = startingSearch ? [startingSearch] : [];
24+
const buildQuery = (searchString, searchIndex, filters) => {
25+
const cqlSearch = searchString ? [searchString] : [];
3726

3827
cqlSearch.push(`isTitleHeadingRef==${searchIndex === searchableIndexesValues.NAME_TITLE}`);
3928

@@ -49,6 +38,23 @@ const useBrowseRequest = ({
4938

5039
const query = [...cqlSearch, ...cqlFilters, headingTypeQuery].filter(Boolean).join(' and ');
5140

41+
return query;
42+
};
43+
44+
const useBrowseRequest = ({
45+
filters,
46+
searchQuery,
47+
searchIndex,
48+
startingSearch,
49+
pageSize,
50+
precedingRecordsCount,
51+
tenantId,
52+
}) => {
53+
const ky = useTenantKy({ tenantId });
54+
const [namespace] = useNamespace({ key: QUERY_KEY_AUTHORITIES });
55+
56+
const query = buildQuery(startingSearch, searchIndex, filters);
57+
5258
const searchParams = {
5359
query,
5460
limit: pageSize,
@@ -227,6 +233,7 @@ const useAuthoritiesBrowse = ({
227233
isLoaded: isFetched,
228234
handleLoadMore,
229235
query,
236+
firstPageQuery: buildQuery(buildPageQuery(searchQuery, 0), searchIndex, filters),
230237
});
231238
};
232239

0 commit comments

Comments
 (0)