forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discover] Data Grid Pagination Options (opensearch-project#5610)
* Added helper function to generate page options based on UI setting value. Signed-off-by: Kishor Rathva <kishorrathva8298@gmail.com> * Added dynamic pagination based on config value for data grid table Signed-off-by: Kishor Rathva <kishorrathva8298@gmail.com> * Update changelog Signed-off-by: Kishor Rathva <kishorrathva8298@gmail.com> * Removed service object from the props. Signed-off-by: kishor82 <kishorrathva8298@gmail.com> * Added suggested changes and updated tests. Signed-off-by: kishor82 <kishorrathva8298@gmail.com> * fix functional test issue due to ui setting Signed-off-by: kishor82 <kishorrathva8298@gmail.com> --------- Signed-off-by: Kishor Rathva <kishorrathva8298@gmail.com> Signed-off-by: kishor82 <kishorrathva8298@gmail.com>
- Loading branch information
Showing
6 changed files
with
96 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/plugins/discover/public/application/components/utils/page_size_options.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { defaultPageOptions, generatePageSizeOptions } from './page_size_options'; | ||
|
||
describe('generatePageSizeOptions', () => { | ||
it('generates default options and additional options based on sample size', () => { | ||
const sampleSize = 1000; | ||
|
||
const pageSizeOptions = generatePageSizeOptions(sampleSize); | ||
|
||
// Expected result based on the provided sample size | ||
const expectedOptions = [...defaultPageOptions, 500, 1000]; | ||
|
||
// Check if the generated options match the expected result | ||
expect(pageSizeOptions).toEqual(expectedOptions); | ||
}); | ||
|
||
it('handles edge case when sample size is less than maxSize', () => { | ||
const sampleSize = 50; | ||
|
||
// Call the function | ||
const pageSizeOptions = generatePageSizeOptions(sampleSize); | ||
|
||
// Check if the generated options match the expected result | ||
expect(pageSizeOptions).toEqual(defaultPageOptions); | ||
}); | ||
|
||
it('handles edge case when sample size is less than 0', () => { | ||
const sampleSize = -10; | ||
|
||
// Call the function | ||
const pageSizeOptions = generatePageSizeOptions(sampleSize); | ||
|
||
// Check if the generated options match the expected result | ||
expect(pageSizeOptions).toEqual(defaultPageOptions); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
src/plugins/discover/public/application/components/utils/page_size_options.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* Generates an array of pagination options based on the provided `pageSizeLimit`. | ||
* The array includes default values (25, 50, 100) and additional options derived from the `pageSizeLimit` setting. | ||
* Ensures uniqueness and sorts the array in ascending order, representing available page size options for pagination. | ||
* @param {number} pageSizeLimit - The sample size used to determine additional pagination options. | ||
* @returns {number[]} - An array of available page size options. | ||
*/ | ||
|
||
export const generatePageSizeOptions = (pageSizeLimit: number): number[] => { | ||
const isInDefaultRange = pageSizeLimit < defaultPageOptions[defaultPageOptions.length - 1]; | ||
|
||
if (pageSizeLimit && pageSizeLimit > 0 && !isInDefaultRange) { | ||
const stepSize = 500; | ||
const pageSizeFromSetting = [...Array(Math.ceil(pageSizeLimit / stepSize)).keys()].map( | ||
(i) => (i + 1) * stepSize | ||
); | ||
return Array.from(new Set([...defaultPageOptions, ...pageSizeFromSetting])).sort( | ||
(a, b) => a - b | ||
); | ||
} | ||
return defaultPageOptions; | ||
}; | ||
|
||
export const defaultPageOptions = [25, 50, 100]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters