Skip to content

Commit

Permalink
feat(search) Allow users to update the number of search results per p…
Browse files Browse the repository at this point in the history
…age (#5212)

Co-authored-by: Chris Collins <chriscollins@Chriss-MBP-2-3.lan>
  • Loading branch information
chriscollins3456 and Chris Collins authored Jun 24, 2022
1 parent 68762a2 commit 4c9554e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 7 additions & 3 deletions datahub-web-react/src/app/search/SearchPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import * as QueryString from 'query-string';
import { useHistory, useLocation, useParams } from 'react-router';
import { Alert } from 'antd';
Expand Down Expand Up @@ -39,13 +39,15 @@ export const SearchPage = () => {
.filter((filter) => filter.field === ENTITY_FILTER_NAME)
.map((filter) => filter.value.toUpperCase() as EntityType);

const [numResultsPerPage, setNumResultsPerPage] = useState(SearchCfg.RESULTS_PER_PAGE);

const { data, loading, error } = useGetSearchResultsForMultipleQuery({
variables: {
input: {
types: entityFilters,
query,
start: (page - 1) * SearchCfg.RESULTS_PER_PAGE,
count: SearchCfg.RESULTS_PER_PAGE,
start: (page - 1) * numResultsPerPage,
count: numResultsPerPage,
filters: filtersWithoutEntities,
},
},
Expand Down Expand Up @@ -118,6 +120,8 @@ export const SearchPage = () => {
loading={loading}
onChangeFilters={onChangeFilters}
onChangePage={onChangePage}
numResultsPerPage={numResultsPerPage}
setNumResultsPerPage={setNumResultsPerPage}
/>
</SearchablePage>
);
Expand Down
14 changes: 12 additions & 2 deletions datahub-web-react/src/app/search/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ interface Props {
}) => Promise<SearchResultsInterface | null | undefined>;
entityFilters: EntityType[];
filtersWithoutEntities: FacetFilterInput[];
numResultsPerPage: number;
setNumResultsPerPage: (numResults: number) => void;
}

export const SearchResults = ({
Expand All @@ -151,6 +153,8 @@ export const SearchResults = ({
callSearchOnVariables,
entityFilters,
filtersWithoutEntities,
numResultsPerPage,
setNumResultsPerPage,
}: Props) => {
const pageStart = searchResponse?.start || 0;
const pageSize = searchResponse?.count || 0;
Expand All @@ -175,6 +179,10 @@ export const SearchResults = ({
onChangeFilters(newFilters);
};

const updateNumResults = (_currentNum: number, newNum: number) => {
setNumResultsPerPage(newNum);
};

const history = useHistory();

const combinedSiblingSearchResults = combineSiblingsInSearchResults(searchResponse?.searchResults);
Expand Down Expand Up @@ -257,11 +265,13 @@ export const SearchResults = ({
<PaginationControlContainer>
<Pagination
current={page}
pageSize={SearchCfg.RESULTS_PER_PAGE}
pageSize={numResultsPerPage}
total={totalResults}
showLessItems
onChange={onChangePage}
showSizeChanger={false}
showSizeChanger={totalResults > SearchCfg.RESULTS_PER_PAGE}
onShowSizeChange={updateNumResults}
pageSizeOptions={['10', '20', '50']}
/>
</PaginationControlContainer>
{authenticatedUserUrn && (
Expand Down

0 comments on commit 4c9554e

Please sign in to comment.