Skip to content

feat: Extract search results per page into a config variable #1922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ const configDefault: AppConfig = {
maxNestedColumns: 500,
},
productTour: {},
searchPagination: {
resultsPerPage: 10,
},
};

export default configDefault;
12 changes: 12 additions & 0 deletions frontend/amundsen_application/static/js/config/config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface AppConfig {
tableQualityChecks: TableQualityChecksConfig;
nestedColumns: NestedColumnConfig;
productTour: ToursConfig;
searchPagination: SearchPagination;
}

/**
Expand Down Expand Up @@ -74,6 +75,7 @@ export interface AppConfigCustom {
tableQualityChecks?: TableQualityChecksConfig;
nestedColumns?: NestedColumnConfig;
productTour?: ToursConfig;
searchPagination?: SearchPagination;
}

/**
Expand Down Expand Up @@ -529,3 +531,13 @@ export interface TourStep {
*/
disableBeacon?: boolean;
}

/**
* Configuration for search results pagination
*/
export interface SearchPagination {
/**
* Number of results per page
*/
resultsPerPage: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,10 @@ export function getProductToursFor(
export function searchHighlightingEnabled(resource: ResourceType): boolean {
return AppConfig.resourceConfig[resource].searchHighlight.enableHighlight;
}

/**
* Returns the search results pagination configuration
*/
export function getSearchResultsPerPage(): number {
return AppConfig.searchPagination.resultsPerPage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -872,3 +872,12 @@ describe('getProductToursFor', () => {
});
});
});

describe('getSearchResultsPerPage', () => {
it('returns searchPagination.resultsPerPage defined in config', () => {
AppConfig.searchPagination.resultsPerPage = 10;
const actual = ConfigUtils.getSearchResultsPerPage();
const expected = AppConfig.searchPagination.resultsPerPage;
expect(actual).toBe(expected);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import globalState from 'fixtures/globalState';
import { ResourceType, SearchType } from 'interfaces';

import * as ConfigUtils from 'config/config-utils';
import { RESULTS_PER_PAGE } from 'pages/SearchPage/constants';
import * as API from '../v0';

jest.mock('axios');
Expand Down Expand Up @@ -42,7 +41,7 @@ describe('searchResource', () => {
it('resolves with empty object if dashboard resource search not supported', async () => {
axiosMockPost.mockClear();
const pageIndex = 0;
const resultsPerPage = RESULTS_PER_PAGE;
const resultsPerPage = ConfigUtils.getSearchResultsPerPage();
const resourceType = [ResourceType.dashboard];
const term = 'test';
expect.assertions(2);
Expand All @@ -63,7 +62,7 @@ describe('searchResource', () => {
axiosMockPost.mockClear();
userEnabledMock.mockImplementationOnce(() => false);
const pageIndex = 0;
const resultsPerPage = RESULTS_PER_PAGE;
const resultsPerPage = ConfigUtils.getSearchResultsPerPage();
const resourceType = [ResourceType.user];
const term = 'test';
expect.assertions(2);
Expand All @@ -88,7 +87,7 @@ describe('searchResource', () => {
const searchTerm = 'test';
const filters = { schema: { value: 'schema_name' } };
const searchType = SearchType.SUBMIT_TERM;
const resultsPerPage = RESULTS_PER_PAGE;
const resultsPerPage = ConfigUtils.getSearchResultsPerPage();
const highlightingOptions = {
table: {
enable_highlight: true,
Expand Down Expand Up @@ -121,7 +120,7 @@ describe('searchResource', () => {
const searchTerm = 'test';
const filters = { name: { value: 'test' } };
const searchType = SearchType.SUBMIT_TERM;
const resultsPerPage = RESULTS_PER_PAGE;
const resultsPerPage = ConfigUtils.getSearchResultsPerPage();
const highlightingOptions = {
dashboard: {
enable_highlight: true,
Expand Down Expand Up @@ -150,7 +149,7 @@ describe('searchResource', () => {
const searchHelperSpy = jest.spyOn(API, 'searchHelper');
await API.search(
0,
RESULTS_PER_PAGE,
ConfigUtils.getSearchResultsPerPage(),
[ResourceType.table],
'test',
{ schema: { value: 'schema_name' } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as qs from 'simple-query-string';
import { ResourceType, SearchType } from 'interfaces';

import { BrowserHistory, updateSearchUrl } from 'utils/navigationUtils';
import { RESULTS_PER_PAGE } from 'pages/SearchPage/constants';
import { getSearchResultsPerPage } from 'config/config-utils';
import * as API from './api/v0';

import {
Expand Down Expand Up @@ -249,7 +249,7 @@ export function* searchResourceWorker(
const response = yield call(
API.search,
pageIndex,
RESULTS_PER_PAGE,
getSearchResultsPerPage(),
[resource],
term,
state.filters,
Expand Down Expand Up @@ -281,7 +281,7 @@ export function* searchAllWorker(action: SearchAllRequest): SagaIterator {
const response = yield call(
API.search,
pageIndex,
RESULTS_PER_PAGE,
getSearchResultsPerPage(),
SEARCHABLE_RESOURCES,
term,
state.filters,
Expand Down Expand Up @@ -321,7 +321,7 @@ export function* inlineSearchWorker(action: InlineSearchRequest): SagaIterator {
const response = yield call(
API.search,
0,
RESULTS_PER_PAGE,
getSearchResultsPerPage(),
SEARCHABLE_RESOURCES,
term,
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ResourceType } from 'interfaces/Resources';
import { getDisplayNameByResource } from 'config/config-utils';

export const PAGINATION_PAGE_RANGE = 10;
export const RESULTS_PER_PAGE = 10;

// TODO: Hard-coded text strings should be translatable/customizable
export const DOCUMENT_TITLE_SUFFIX = ' - Amundsen Search';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
datasetFilterExample,
} from 'fixtures/search/filters';
import { getMockRouterProps } from 'fixtures/mockRouter';
import { getSearchResultsPerPage } from 'config/config-utils';
import {
DOCUMENT_TITLE_SUFFIX,
PAGE_INDEX_ERROR_MESSAGE,
RESULTS_PER_PAGE,
SEARCH_DEFAULT_MESSAGE,
SEARCH_ERROR_MESSAGE_PREFIX,
SEARCH_ERROR_MESSAGE_SUFFIX,
Expand Down Expand Up @@ -255,7 +255,7 @@ describe('SearchPage', () => {
content.children().find(PaginatedApiResourceList).props()
).toMatchObject({
activePage: 0,
itemsPerPage: RESULTS_PER_PAGE,
itemsPerPage: getSearchResultsPerPage(),
onPagination: props.setPageIndex,
slicedItems: testResults.results,
source: SEARCH_SOURCE_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import {
} from 'ducks/search/types';

import { Resource, ResourceType, SearchType } from 'interfaces';
import { getSearchResultsPerPage } from 'config/config-utils';
import SearchPanel from './SearchPanel';
import SearchFilter from './SearchFilter';
import ResourceSelector from './ResourceSelector';

import {
DOCUMENT_TITLE_SUFFIX,
PAGE_INDEX_ERROR_MESSAGE,
RESULTS_PER_PAGE,
SEARCH_DEFAULT_MESSAGE,
SEARCH_ERROR_MESSAGE_PREFIX,
SEARCH_ERROR_MESSAGE_SUFFIX,
Expand Down Expand Up @@ -116,7 +116,7 @@ export class SearchPage extends React.Component<SearchPageProps> {
getTabContent = (results: SearchResults<Resource>, tab: ResourceType) => {
const { hasFilters, searchTerm, setPageIndex, didSearch } = this.props;
const { page_index, total_results } = results;
const startIndex = RESULTS_PER_PAGE * page_index + 1;
const startIndex = getSearchResultsPerPage() * page_index + 1;
const tabLabel = this.generateTabLabel(tab);

const hasNoSearchInputOrAction =
Expand Down Expand Up @@ -168,7 +168,7 @@ export class SearchPage extends React.Component<SearchPageProps> {
<PaginatedApiResourceList
activePage={page_index}
onPagination={setPageIndex}
itemsPerPage={RESULTS_PER_PAGE}
itemsPerPage={getSearchResultsPerPage()}
slicedItems={results.results}
source={SEARCH_SOURCE_NAME}
totalItemsCount={total_results}
Expand All @@ -180,7 +180,7 @@ export class SearchPage extends React.Component<SearchPageProps> {
renderContent = () => {
const { isLoading } = this.props;
if (isLoading) {
return <ShimmeringResourceLoader numItems={RESULTS_PER_PAGE} />;
return <ShimmeringResourceLoader numItems={getSearchResultsPerPage()} />;
}

return this.renderSearchResults();
Expand Down