From 9c15969124a6690dd13ea9cb28659b74d26f39d3 Mon Sep 17 00:00:00 2001 From: Nick dos Remedios Date: Fri, 23 Dec 2022 20:12:58 +1100 Subject: [PATCH] #31 WIP got working version for grid tab Using `use-query-params` npm package --- packages/react/package-lock.json | 81 +++++++++++----- packages/react/package.json | 3 +- packages/react/src/components/AppContainer.js | 12 ++- packages/react/src/components/FacetsBar.js | 77 +++++++++------- packages/react/src/components/GridView.js | 36 +++++--- packages/react/src/components/Search.js | 92 +++++++++++-------- packages/react/src/components/config.js | 8 ++ packages/react/src/hooks/UrlParams.js | 59 ++++++++++++ packages/react/src/types/solrTypes.ts | 8 ++ 9 files changed, 260 insertions(+), 116 deletions(-) create mode 100644 packages/react/src/hooks/UrlParams.js create mode 100644 packages/react/src/types/solrTypes.ts diff --git a/packages/react/package-lock.json b/packages/react/package-lock.json index a573285..a48129b 100644 --- a/packages/react/package-lock.json +++ b/packages/react/package-lock.json @@ -26,11 +26,12 @@ "react-leaflet-draw": "^0.20.4", "react-markdown": "^8.0.3", "react-oidc-context": "^2.2.0", - "react-router-dom": "^6.4.1", + "react-router-dom": "^6.6.0", "react-scripts": "5.0.1", "react-use-cart": "^1.13.0", "save-dev": "^0.0.1-security", "string-hash": "^1.1.3", + "use-query-params": "^2.1.2", "web-vitals": "^3.0.2" }, "devDependencies": { @@ -3546,9 +3547,9 @@ } }, "node_modules/@remix-run/router": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.0.1.tgz", - "integrity": "sha512-eBV5rvW4dRFOU1eajN7FmYxjAIVz/mRHgUE9En9mBn6m3mulK3WTR5C3iQhL9MZ14rWAq+xOlEaCkDiW0/heOg==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.2.0.tgz", + "integrity": "sha512-GO82KYYTWPRCgdNtnheaZG3LcViUlxRFlHM7ykh7N+ufoXi6PVIHoP+9RUG/vuzl2hr9i/h6EA1Eq+2HpqJ0gQ==", "engines": { "node": ">=14" } @@ -15673,11 +15674,11 @@ } }, "node_modules/react-router": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.4.1.tgz", - "integrity": "sha512-OJASKp5AykDWFewgWUim1vlLr7yfD4vO/h+bSgcP/ix8Md+LMHuAjovA74MQfsfhQJGGN1nHRhwS5qQQbbBt3A==", + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.6.0.tgz", + "integrity": "sha512-+VPfCIaFbkW7BAiB/2oeprxKAt1KLbl+zXZ10CXOYezKWgBmTKyh8XjI53eLqY5kd7uY+V4rh3UW44FclwUU+Q==", "dependencies": { - "@remix-run/router": "1.0.1" + "@remix-run/router": "1.2.0" }, "engines": { "node": ">=14" @@ -15687,12 +15688,12 @@ } }, "node_modules/react-router-dom": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.4.1.tgz", - "integrity": "sha512-MY7NJCrGNVJtGp8ODMOBHu20UaIkmwD2V3YsAOUQoCXFk7Ppdwf55RdcGyrSj+ycSL9Uiwrb3gTLYSnzcRoXww==", + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.6.0.tgz", + "integrity": "sha512-qC4jnvpfCPKVle1mKLD75IvZLcbVJyFMlSn16WY9ZiOed3dgSmqhslCf/u3tmSccWOujkdsT/OwGq12bELmvjg==", "dependencies": { - "@remix-run/router": "1.0.1", - "react-router": "6.4.1" + "@remix-run/router": "1.2.0", + "react-router": "6.6.0" }, "engines": { "node": ">=14" @@ -16498,6 +16499,11 @@ "randombytes": "^2.1.0" } }, + "node_modules/serialize-query-params": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/serialize-query-params/-/serialize-query-params-2.0.2.tgz", + "integrity": "sha512-1chMo1dST4pFA9RDXAtF0Rbjaut4is7bzFbI1Z26IuMub68pNCILku85aYmeFhvnY//BXUPUhoRMjYcsT93J/Q==" + }, "node_modules/serve-index": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/serve-index/-/serve-index-1.9.1.tgz", @@ -17793,6 +17799,18 @@ "punycode": "^2.1.0" } }, + "node_modules/use-query-params": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/use-query-params/-/use-query-params-2.1.2.tgz", + "integrity": "sha512-evg64srKaILvKyRQ1zpXvekTC7rktAT7OAekU7x6naHrOMqLHtq0MHR/PtKIQAP4d7HrkYNVOS8exHhiWy7m3A==", + "dependencies": { + "serialize-query-params": "^2.0.2" + }, + "peerDependencies": { + "react": ">=16.8.0", + "react-dom": ">=16.8.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -21162,9 +21180,9 @@ "requires": {} }, "@remix-run/router": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.0.1.tgz", - "integrity": "sha512-eBV5rvW4dRFOU1eajN7FmYxjAIVz/mRHgUE9En9mBn6m3mulK3WTR5C3iQhL9MZ14rWAq+xOlEaCkDiW0/heOg==" + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.2.0.tgz", + "integrity": "sha512-GO82KYYTWPRCgdNtnheaZG3LcViUlxRFlHM7ykh7N+ufoXi6PVIHoP+9RUG/vuzl2hr9i/h6EA1Eq+2HpqJ0gQ==" }, "@rollup/plugin-babel": { "version": "5.3.1", @@ -29712,20 +29730,20 @@ "integrity": "sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A==" }, "react-router": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.4.1.tgz", - "integrity": "sha512-OJASKp5AykDWFewgWUim1vlLr7yfD4vO/h+bSgcP/ix8Md+LMHuAjovA74MQfsfhQJGGN1nHRhwS5qQQbbBt3A==", + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.6.0.tgz", + "integrity": "sha512-+VPfCIaFbkW7BAiB/2oeprxKAt1KLbl+zXZ10CXOYezKWgBmTKyh8XjI53eLqY5kd7uY+V4rh3UW44FclwUU+Q==", "requires": { - "@remix-run/router": "1.0.1" + "@remix-run/router": "1.2.0" } }, "react-router-dom": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.4.1.tgz", - "integrity": "sha512-MY7NJCrGNVJtGp8ODMOBHu20UaIkmwD2V3YsAOUQoCXFk7Ppdwf55RdcGyrSj+ycSL9Uiwrb3gTLYSnzcRoXww==", + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.6.0.tgz", + "integrity": "sha512-qC4jnvpfCPKVle1mKLD75IvZLcbVJyFMlSn16WY9ZiOed3dgSmqhslCf/u3tmSccWOujkdsT/OwGq12bELmvjg==", "requires": { - "@remix-run/router": "1.0.1", - "react-router": "6.4.1" + "@remix-run/router": "1.2.0", + "react-router": "6.6.0" } }, "react-scripts": { @@ -30306,6 +30324,11 @@ "randombytes": "^2.1.0" } }, + "serialize-query-params": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/serialize-query-params/-/serialize-query-params-2.0.2.tgz", + "integrity": "sha512-1chMo1dST4pFA9RDXAtF0Rbjaut4is7bzFbI1Z26IuMub68pNCILku85aYmeFhvnY//BXUPUhoRMjYcsT93J/Q==" + }, "serve-index": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/serve-index/-/serve-index-1.9.1.tgz", @@ -31259,6 +31282,14 @@ "punycode": "^2.1.0" } }, + "use-query-params": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/use-query-params/-/use-query-params-2.1.2.tgz", + "integrity": "sha512-evg64srKaILvKyRQ1zpXvekTC7rktAT7OAekU7x6naHrOMqLHtq0MHR/PtKIQAP4d7HrkYNVOS8exHhiWy7m3A==", + "requires": { + "serialize-query-params": "^2.0.2" + } + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/packages/react/package.json b/packages/react/package.json index 31621e2..a29c1d7 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -22,11 +22,12 @@ "react-leaflet-draw": "^0.20.4", "react-markdown": "^8.0.3", "react-oidc-context": "^2.2.0", - "react-router-dom": "^6.4.1", + "react-router-dom": "^6.6.0", "react-scripts": "5.0.1", "react-use-cart": "^1.13.0", "save-dev": "^0.0.1-security", "string-hash": "^1.1.3", + "use-query-params": "^2.1.2", "web-vitals": "^3.0.2" }, "scripts": { diff --git a/packages/react/src/components/AppContainer.js b/packages/react/src/components/AppContainer.js index 5cbb6fb..a6603e1 100644 --- a/packages/react/src/components/AppContainer.js +++ b/packages/react/src/components/AppContainer.js @@ -1,6 +1,8 @@ import React from 'react' import { BrowserRouter as Router, Routes, Route } from 'react-router-dom' import { Box } from '@mui/material' +import { QueryParamProvider } from 'use-query-params' +import { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6' import Basket from './Basket' import Search from './Search' import ArgaToolbar from './ArgaToolbar' @@ -10,10 +12,12 @@ function AppContainer() { - - } /> - } /> - + + + } /> + } /> + + ) diff --git a/packages/react/src/components/FacetsBar.js b/packages/react/src/components/FacetsBar.js index 5402b40..09e666c 100644 --- a/packages/react/src/components/FacetsBar.js +++ b/packages/react/src/components/FacetsBar.js @@ -11,9 +11,11 @@ import { } from '@mui/material' import SearchIcon from '@mui/icons-material/Search' import CloseIcon from '@mui/icons-material/Close' -import { useSearchParams } from 'react-router-dom' +// import { useSearchParams } from 'react-router-dom' import FacetSelect from './FacetSelect' import theme from './theme' +import useUrlParams from '../hooks/UrlParams' +// import config from './config' /** * Component to output a "filter" bar for filtering search results @@ -26,27 +28,42 @@ import theme from './theme' */ export default function FacetsBar({ pageState, - setPageState, + // setPageState, fqState, - setFqState, + // setFqState, }) { // State for search input - bind it to `pageState.q`. I'm not using it directly due to it repeatedly calling // SOLR when the user is typing. User has to click search icon or hit enter to bind it to the `pageState.q` - const [inputState, setInputState] = useState('') - const [searchParams, setSearchParams] = useSearchParams() + const [inputState, setInputState] = useState('') // search input field + const [solrParams, setSolrParams] = useUrlParams() useEffect(() => { - if ((!inputState && pageState.q) || inputState !== pageState.q) { - setInputState(pageState.q) + if ((!inputState && solrParams.q) || inputState !== solrParams.q) { + setInputState(solrParams.q) } - }, [pageState.q]) + }, [solrParams.q]) + // callback triggered by enter or clicking the search action button (magnifier icon) const searchClickEvent = () => { - setPageState((old) => ({ - ...old, - q: inputState, - })) - setFqState({}) + // setPageState((old) => ({ + // ...old, + // q: inputState, + // })) + // setFqState({}) + // console.log('searchClickEvent', inputState) + setSolrParams((old) => { + const copy = { ...old } + delete copy.fq + // copy.delete('fq') // q has changed so we reset any fq filters + copy.q = inputState // replace q value + return copy + }) + + // ({ + // ...old, + // old.delete('fq'), + // q: inputState, + // })) } const searchKeyPress = (e) => { @@ -55,16 +72,15 @@ export default function FacetsBar({ } } + // callback for the [x] on the search input text field const clearSearch = () => { - setPageState((old) => ({ - ...old, - q: '', - page: 1, - })) - setFqState({}) setInputState('') - searchParams.delete('q') - setSearchParams(searchParams) + setSolrParams((old) => { + const copy = { ...old } + delete copy.q // remove from URL + delete copy.fq // q has changed so we remove any fq params too + return copy + }) } const facetsDisplay = {} @@ -118,12 +134,11 @@ export default function FacetsBar({ return content } - const handleDelete = (fqName) => () => { - setFqState((current) => { - const copy = { ...current } - delete copy[fqName] - return copy - }) + // callback for the [x] on any set facet filters + const removeFilter = (fqName) => () => { + const fqCopy = { ...solrParams.fq } + delete fqCopy[fqName] + setSolrParams((old) => ({ ...old, fq: fqCopy })) } return ( @@ -140,7 +155,7 @@ export default function FacetsBar({ setInputState(e.target.value)} onKeyPress={searchKeyPress} sx={{ @@ -159,7 +174,7 @@ export default function FacetsBar({ {inputState && ( @@ -209,7 +224,7 @@ export default function FacetsBar({ }, }} variant="outlined" - onClick={handleDelete(fqName)} + onClick={removeFilter(fqName)} endIcon={} > {formatFacetText(fqName)} @@ -233,7 +248,7 @@ export default function FacetsBar({ field={field} fieldValues={facetsDisplay[field]} fqState={fqState[field] || []} - setFqState={setFqState} + // setFqState={setFqState} /> ))} diff --git a/packages/react/src/components/GridView.js b/packages/react/src/components/GridView.js index a74f593..58ea05c 100644 --- a/packages/react/src/components/GridView.js +++ b/packages/react/src/components/GridView.js @@ -2,12 +2,18 @@ import { useEffect } from 'react' // import { } from '@mui/icons-material' import { Box, Grid, TablePagination } from '@mui/material' import SpeciesCard from './SpeciesCard' +import useUrlParams from '../hooks/UrlParams' function GridView({ pageState, setPageState, setRecordState }) { - useEffect(() => { - setPageState((old) => ({ ...old, groupResults: true, pageSize: 24 })) - }, [pageState.groupResults, pageState.pageState]) const defaultPageSize = 24 + const [solrParams, setSolrParams] = useUrlParams() + + useEffect(() => { + setPageState((old) => ({ ...old, groupResults: true })) + }, []) + + const page = solrParams.page || 1 + const pageSize = solrParams.pageSize || defaultPageSize return ( <> @@ -49,25 +55,25 @@ function GridView({ pageState, setPageState, setRecordState }) { component="div" rowsPerPageOptions={[12, 24, 48, 96]} // pagination - page={pageState.page - 1} - rowsPerPage={pageState.pageSize || defaultPageSize} + page={page - 1} // component uses zero-based `page` count + rowsPerPage={pageSize} onPageChange={(event, newPage) => - setPageState((old) => ({ ...old, page: newPage + 1 })) + setSolrParams((old) => ({ ...old, page: newPage + 1 })) } onRowsPerPageChange={(event) => - setPageState((old) => ({ + setSolrParams((old) => ({ ...old, - page: 1, + page: 1, // reset to page 1 when rows per page changes pageSize: parseInt(event.target.value, 10), })) } - count={Math.ceil( - pageState.total / pageState.pageSize || defaultPageSize - )} - // page={page} - // onPageChange={handleChangePage} - // rowsPerPage={rowsPerPage} - // onRowsPerPageChange={handleChangeRowsPerPage} + count={ + pageState?.total + ? Math.ceil( + pageState.total / pageSize // TODO: buggy: fix OR'ed value + ) + : 1 + } /> {/* { + // if (searchParams.get(field)) { + // solrParams[field] = searchParams.get(field) + // } + // }) + + const [solrParams, setSolrParams] = useUrlParams() + const [pageState, setPageState] = useState({ isLoading: false, data: [], species: [], - total: 0, - page: 1, - // pageSize: 25, - field: '', // sort 'vernacularName' - sort: '', // order 'asc' - q: '', + // total: 0, + // page: 1, + // // pageSize: 25, + // field: '', // sort 'vernacularName' + // sort: '', // order 'asc' + // q: '', // Note: `fq` is in its own state var below (`fqState`) - groupResults: false, + groupResults: false, // can derive this from the current facetResults: [], }) - const [fqState, setFqState] = useState({}) + // const [fqState, setFqState] = useState({}) const fqRef = useRef() - fqRef.current = fqState // so `fqState` can be read in callbacks (normally `fqState` is always empty in `fqUpdate`) + fqRef.current = solrParams.fq // so `fqState` can be read in callbacks (normally `fqState` is always empty in `fqUpdate`) const [recordState, setRecordState] = useState({ isLoading: false, @@ -172,9 +183,6 @@ function Search() { setTabValue(newValue) } - // const { search } = useLocation(); - const [searchParams] = useSearchParams() - /** * Callback attached to Chip elements in the results table of datagrid. * Triggers new search with `fq` param added for given Chip. @@ -185,7 +193,8 @@ function Search() { const existingValues = fqRef.current[fieldName]?.length > 0 ? fqRef.current[fieldName] : [] const fq = { [fieldName]: [...existingValues, value] } - setFqState((old) => ({ ...old, ...fq })) + // setFqState((old) => ({ ...old, ...fq })) + setSolrParams((old) => ({ ...old, fq })) e.stopPropagation() e.preventDefault() }, []) @@ -197,6 +206,7 @@ function Search() { */ const buildFqList = useCallback(() => { const fqParamList = [] + const fqState = solrParams.fq ?? [] Object.keys(fqState).forEach((key) => { const tag = facetFields[key]?.tag ? `{!tag=${facetFields[key].tag}}` : '' @@ -213,7 +223,7 @@ function Search() { }) return fqParamList.join('&fq=') - }, [fqState]) + }, [solrParams.fq]) /** * Build string for SOLR `facet.field` params. @@ -393,6 +403,8 @@ function Search() { // Fetch list of records - SOLR select useEffect(() => { const abortController = new AbortController() // if mulitple record requests - last one wins + const page = solrParams.page || config.solrParams.page + const pageSize = solrParams.pageSize || config.solrParams.pageSize const fetchData = async () => { setPageState((old) => ({ @@ -400,20 +412,19 @@ function Search() { isLoading: true, })) // calculate SOLR startIndex param - const startIndex = - pageState.page * pageState.pageSize - pageState.pageSize + const startIndex = page * pageSize - pageSize const groupParams = pageState.groupResults ? '&group=true&group.field=scientificName&group.limit=99' : '' - const query = pageState.q || defaultQuery + const query = solrParams.q || config.solrParams.q const url = `${serverUrlPrefix}/select?q=${query}&fq=${buildFqList()}&fl=${columnDataFields.join( ',' )}&facet=true&facet.field=${buildFacetList().join( '&facet.field=' - )}&facet.mincount=1&&rows=${ - pageState.pageSize - }&start=${startIndex}&sort=${ - pageState.field ? `${pageState.field}+${pageState.sort}` : '' + )}&facet.mincount=1&&rows=${pageSize}&start=${startIndex}&sort=${ + solrParams.sortField + ? `${solrParams.sortField}+${solrParams.sortDirection}` + : '' }${groupParams}&defType=${queryParser}&qf=${Object.keys(queryFields) .map((k) => `${k}^${queryFields[k]}`) .join('+')}&bq=${boostQuery.join('+')}&mm=${minMatch}&debugQuery=true` @@ -452,13 +463,13 @@ function Search() { abortController.abort() } }, [ - pageState.page, - pageState.pageSize, - pageState.field, - pageState.sort, - pageState.q, + solrParams.page, + solrParams.pageSize, + solrParams.field, + solrParams.sort, + solrParams.q, pageState.groupResults, - fqState, + solrParams.fq, columnDataFields, ]) @@ -485,18 +496,19 @@ function Search() { }, [recordState.id]) // Listen for `?q={query}` URL (linked search) - useEffect(() => { - if (searchParams.get('q')) { - setPageState((old) => ({ ...old, q: searchParams.get('q') })) - } - }, [searchParams]) + // useEffect(() => { + // if (searchParams.get('q')) { + // setPageState((old) => ({ ...old, q: searchParams.get('q') })) + // } + // }, [searchParams]) // keeping this in for next refactor // eslint-disable-next-line const searchKeyPress = (e) => { if (e.key === 'Enter') { - setPageState((old) => ({ ...old, q: e.target.value, page: 1 })) - setFqState({}) + // setPageState((old) => ({ ...old, q: e.target.value, page: 1 })) + setSolrParams({ q: e.target.value, page: 1, fq: [] }) + // setFqState({}) // datagridRef.current.focus() // e.preventDefault() } @@ -597,7 +609,7 @@ function Search() { setPageState={setPageState} searchKeyPress={searchKeyPress} fqState={fqRef.current || {}} - setFqState={setFqState} + // setFqState={setFqState} /> @@ -655,7 +667,7 @@ function Search() { p: 2, }} > - + /> */} diff --git a/packages/react/src/components/config.js b/packages/react/src/components/config.js index faaca78..901408e 100644 --- a/packages/react/src/components/config.js +++ b/packages/react/src/components/config.js @@ -30,6 +30,14 @@ const config = { DR_BOLD: 'dr375', }, urls: externalUrls, + solrParams: { + q: '*:*', + fq: [], + sortDirection: '', + sortField: '', + page: 1, + pageSize: 24, + }, } export default config diff --git a/packages/react/src/hooks/UrlParams.js b/packages/react/src/hooks/UrlParams.js new file mode 100644 index 0000000..26e2fba --- /dev/null +++ b/packages/react/src/hooks/UrlParams.js @@ -0,0 +1,59 @@ +// import { useSearchParams } from 'react-router-dom' +// import { URLSearchParams } from 'url' +import { + useQueryParams, + StringParam, + NumberParam, + ArrayParam, + withDefault, +} from 'use-query-params' +// import config from '../components/config' +// import { SolrParams } from '../types/solrTypes' + +const FqParam = withDefault(ArrayParam, []) // support mutliple `fq` values in URL - `?fq=foo:one&fq:bar:two` + +export default function useUrlParams() { + const [solrParams, setSolrParams] = useQueryParams({ + q: StringParam, + filters: FqParam, + sortDirection: StringParam, + sortField: StringParam, + page: NumberParam, + pageSize: NumberParam, + }) + + // const [searchParams, setSearchParams] = useSearchParams() + // const solrParams = { ...config.solrParams } + // const defaultSolrParams = config.solrParams + + // Object.keys(config.solrParams).forEach((field) => { + // // check if any of the solrParams are contained in the URL search params object + // // and assign to `solrParams` if present. + // if (searchParams.get(field)) { + // solrParams[field] = searchParams.get(field) + // } + // }) + + // // might need to be wrapped in useCallback() ?? + // const setSolrParams = (params) => { + // // const paramsCopy: URLSearchParamsInit = { ...params } + // console.log('setSolrParams params:', params) + // setSearchParams((old) => ({ + // q: params.q || old.q || defaultSolrParams.q, + // fq: params.fq || old.fq || defaultSolrParams.fq, + // sortField: + // params.sortField || old.sortField || defaultSolrParams.sortField, + // sortDirecion: + // params.sortDirection || + // old.sortDirection || + // defaultSolrParams.sortDirection, + // page: params.page?.toString() || old.page || defaultSolrParams.page, + // pageSize: + // params.pageSize?.toString() || + // old.pageSize || + // defaultSolrParams.pageSize, + // })) + // } + + return [solrParams, setSolrParams] +} diff --git a/packages/react/src/types/solrTypes.ts b/packages/react/src/types/solrTypes.ts new file mode 100644 index 0000000..f3289c8 --- /dev/null +++ b/packages/react/src/types/solrTypes.ts @@ -0,0 +1,8 @@ +export interface SolrParams { + q: string, + fq?: string[], + sortDirection?: string, + sortField?: string, + page?: number, + pageSize?: number, +} \ No newline at end of file