mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Fix pagination breaks on to many results (#831)
* handle to many results * update search test * get transaction history based on ddo chainId * revert last commit * changed title and description * reduce paragraphs * added constant for maximum number of pages
This commit is contained in:
parent
969ac96417
commit
0eb6c15cda
@ -1,6 +1,7 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement } from 'react'
|
||||||
import classNames from 'classnames/bind'
|
import classNames from 'classnames/bind'
|
||||||
import styles from './PageHeader.module.css'
|
import styles from './PageHeader.module.css'
|
||||||
|
import Markdown from '../atoms/Markdown'
|
||||||
|
|
||||||
const cx = classNames.bind(styles)
|
const cx = classNames.bind(styles)
|
||||||
|
|
||||||
@ -21,7 +22,9 @@ export default function PageHeader({
|
|||||||
return (
|
return (
|
||||||
<header className={styleClasses}>
|
<header className={styleClasses}>
|
||||||
<h1 className={styles.title}>{title}</h1>
|
<h1 className={styles.title}>{title}</h1>
|
||||||
{description && <p className={styles.description}>{description}</p>}
|
{description && (
|
||||||
|
<Markdown text={description} className={styles.description} />
|
||||||
|
)}
|
||||||
</header>
|
</header>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React, { useState, useEffect, ReactElement } from 'react'
|
import React, { useState, useEffect, ReactElement } from 'react'
|
||||||
import ReactPaginate from 'react-paginate'
|
import ReactPaginate from 'react-paginate'
|
||||||
import styles from './Pagination.module.css'
|
import styles from './Pagination.module.css'
|
||||||
|
import { MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS } from '../../utils/aquarius'
|
||||||
import { ReactComponent as Arrow } from '../../images/arrow.svg'
|
import { ReactComponent as Arrow } from '../../images/arrow.svg'
|
||||||
|
|
||||||
interface PaginationProps {
|
interface PaginationProps {
|
||||||
@ -56,7 +57,11 @@ export default function Pagination({
|
|||||||
|
|
||||||
return totalPageNumbers && totalPageNumbers > 1 ? (
|
return totalPageNumbers && totalPageNumbers > 1 ? (
|
||||||
<ReactPaginate
|
<ReactPaginate
|
||||||
pageCount={totalPageNumbers}
|
pageCount={
|
||||||
|
totalPageNumbers > MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS
|
||||||
|
? MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS
|
||||||
|
: totalPageNumbers
|
||||||
|
}
|
||||||
// react-pagination starts counting at 0, we start at 1
|
// react-pagination starts counting at 0, we start at 1
|
||||||
initialPage={currentPage ? currentPage - 1 : 0}
|
initialPage={currentPage ? currentPage - 1 : 0}
|
||||||
// adapt based on media query match
|
// adapt based on media query match
|
||||||
|
@ -14,10 +14,12 @@ import { useUserPreferences } from '../../../providers/UserPreferences'
|
|||||||
|
|
||||||
export default function SearchPage({
|
export default function SearchPage({
|
||||||
location,
|
location,
|
||||||
setTotalResults
|
setTotalResults,
|
||||||
|
setTotalPagesNumber
|
||||||
}: {
|
}: {
|
||||||
location: Location
|
location: Location
|
||||||
setTotalResults: (totalResults: number) => void
|
setTotalResults: (totalResults: number) => void
|
||||||
|
setTotalPagesNumber: (totalPagesNumber: number) => void
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { appConfig } = useSiteMetadata()
|
const { appConfig } = useSiteMetadata()
|
||||||
const parsed = queryString.parse(location.search)
|
const parsed = queryString.parse(location.search)
|
||||||
@ -45,6 +47,7 @@ export default function SearchPage({
|
|||||||
)
|
)
|
||||||
setQueryResult(queryResult)
|
setQueryResult(queryResult)
|
||||||
setTotalResults(queryResult.totalResults)
|
setTotalResults(queryResult.totalResults)
|
||||||
|
setTotalPagesNumber(queryResult.totalPages)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
initSearch()
|
initSearch()
|
||||||
|
@ -5,11 +5,13 @@ import Page from '../components/templates/Page'
|
|||||||
import queryString from 'query-string'
|
import queryString from 'query-string'
|
||||||
import { accountTruncate } from '../utils/web3'
|
import { accountTruncate } from '../utils/web3'
|
||||||
import ethereumAddress from 'ethereum-address'
|
import ethereumAddress from 'ethereum-address'
|
||||||
|
import { MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS } from '../utils/aquarius'
|
||||||
|
|
||||||
export default function PageGatsbySearch(props: PageProps): ReactElement {
|
export default function PageGatsbySearch(props: PageProps): ReactElement {
|
||||||
const parsed = queryString.parse(props.location.search)
|
const parsed = queryString.parse(props.location.search)
|
||||||
const { text, owner, tags, categories } = parsed
|
const { text, owner, tags, categories } = parsed
|
||||||
const [totalResults, setTotalResults] = useState<number>()
|
const [totalResults, setTotalResults] = useState<number>()
|
||||||
|
const [totalPagesNumber, setTotalPagesNumber] = useState<number>()
|
||||||
|
|
||||||
const isETHAddress = ethereumAddress.isAddress(text as string)
|
const isETHAddress = ethereumAddress.isAddress(text as string)
|
||||||
const searchValue =
|
const searchValue =
|
||||||
@ -32,10 +34,23 @@ export default function PageGatsbySearch(props: PageProps): ReactElement {
|
|||||||
}`
|
}`
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page title={title} uri={props.uri}>
|
<Page
|
||||||
|
title={
|
||||||
|
totalPagesNumber > MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS
|
||||||
|
? `>10000 results for ${searchValue}`
|
||||||
|
: title
|
||||||
|
}
|
||||||
|
description={
|
||||||
|
totalPagesNumber &&
|
||||||
|
totalPagesNumber > MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS &&
|
||||||
|
'**Results displayed are limited to the first 10k, please refine your search.**'
|
||||||
|
}
|
||||||
|
uri={props.uri}
|
||||||
|
>
|
||||||
<PageSearch
|
<PageSearch
|
||||||
location={props.location}
|
location={props.location}
|
||||||
setTotalResults={(totalResults) => setTotalResults(totalResults)}
|
setTotalResults={(totalResults) => setTotalResults(totalResults)}
|
||||||
|
setTotalPagesNumber={(totalPages) => setTotalPagesNumber(totalPages)}
|
||||||
/>
|
/>
|
||||||
</Page>
|
</Page>
|
||||||
)
|
)
|
||||||
|
@ -14,6 +14,8 @@ import { PriceList, getAssetsPriceList } from './subgraph'
|
|||||||
import axios, { CancelToken, AxiosResponse } from 'axios'
|
import axios, { CancelToken, AxiosResponse } from 'axios'
|
||||||
import { metadataCacheUri } from '../../app.config'
|
import { metadataCacheUri } from '../../app.config'
|
||||||
|
|
||||||
|
export const MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS = 476
|
||||||
|
|
||||||
function getQueryForAlgorithmDatasets(algorithmDid: string, chainId?: number) {
|
function getQueryForAlgorithmDatasets(algorithmDid: string, chainId?: number) {
|
||||||
return {
|
return {
|
||||||
query: {
|
query: {
|
||||||
|
@ -14,10 +14,15 @@ describe('Search', () => {
|
|||||||
const results = totalResults
|
const results = totalResults
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setTotalPagesNumber = (totalPages: number) => {
|
||||||
|
const pages = totalPages
|
||||||
|
}
|
||||||
|
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<LocationProvider history={history}>
|
<LocationProvider history={history}>
|
||||||
<Search
|
<Search
|
||||||
location={{ search: '?text=water' } as any}
|
location={{ search: '?text=water' } as any}
|
||||||
|
setTotalPagesNumber={(totalPages) => setTotalPagesNumber(totalPages)}
|
||||||
setTotalResults={(totalResults) => setTotalResults(totalResults)}
|
setTotalResults={(totalResults) => setTotalResults(totalResults)}
|
||||||
/>
|
/>
|
||||||
</LocationProvider>
|
</LocationProvider>
|
||||||
|
Loading…
Reference in New Issue
Block a user