From 9f4575d9ab074f362c201a22079f043ad3988a40 Mon Sep 17 00:00:00 2001 From: Arpita Kate Date: Fri, 26 Apr 2024 18:06:25 +0000 Subject: [PATCH 1/7] Revert Changes for making pageSizes as default prop --- package.json | 2 +- src/datagrid/DataGrid.stories.tsx | 6 ++--- src/datagrid/DataGrid.tsx | 33 ++++++++++++++++++++-------- src/datagrid/DataGridStoriesData.tsx | 4 +++- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 0ca2fa42..d5110c04 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dellstorage/clarity-react", - "version": "1.2.11", + "version": "1.2.12", "description": "React components for Clarity UI", "license": "Apache-2.0", "private": false, diff --git a/src/datagrid/DataGrid.stories.tsx b/src/datagrid/DataGrid.stories.tsx index 5803b74e..c24590a4 100644 --- a/src/datagrid/DataGrid.stories.tsx +++ b/src/datagrid/DataGrid.stories.tsx @@ -47,7 +47,7 @@ import { paginationDetailsForDetailsPane, paginationRowsWithLinks, storeForDetailPane, - paginationDetailswithDefaultPageSizes, + paginationDetailswithPageSizes, } from "./DataGridStoriesData"; import {CustomFilter} from "./CustomFilter"; import {CustomFilterMulti} from "./CustomFilterMulti"; @@ -420,12 +420,12 @@ storiesOf("DataGrid", module) /> )) - .add("Grid with pagination and default pageSizes dropdown", () => ( + .add("Grid with pagination and pageSizes dropdown", () => (
diff --git a/src/datagrid/DataGrid.tsx b/src/datagrid/DataGrid.tsx index 0c06edf5..7afa818c 100644 --- a/src/datagrid/DataGrid.tsx +++ b/src/datagrid/DataGrid.tsx @@ -18,6 +18,7 @@ import {Icon, Direction} from "../icon"; import {Spinner, SpinnerSize} from "../spinner/Spinner"; import {HideShowColumns} from "./HideShowColumns"; import {DataGridColumnResize} from "./DataGridColumnResize"; +import {totalmem} from "os"; /** * General component description : @@ -213,7 +214,8 @@ export type DataGridSort = { * @param {lastPage} Index of the last page for the current data * @param {getPage} custom function to get page data for given page number * @param {compactFooter} if true will render compact pagination footer - * @param {pageSizes} Array containing pageSize which user can select from dropdown menu + * @param {pageSizes} Array containing pageSize which user can select from dropdown menu. + * Supports custom page sizes. For example["10", "20", "50", "100", CUSTOM_PAGE_SIZE_OPTION] * @param {maxCustomPageSize} Maximum limit for custom page size as well as for pageSize dropdown */ type DataGridPaginationProps = { @@ -278,8 +280,8 @@ export const DEFAULT_COLUMN_WIDTH: number = 100; export const DEFAULT_CURRENT_PAGE_NUMBER: number = 1; export const DEFAULT_PAGE_SIZE: number = 10; export const DEFAULT_TOTAL_ITEMS: number = 0; -export const DEFAULT_PAGE_SIZES: string[] = ["10", "20", "50", "100", "Custom"]; export const MAX_PAGE_SIZE: number = 1000; +export const CUSTOM_PAGE_SIZE_OPTION: string = "Custom"; /** * State for DataGrid : @@ -299,7 +301,16 @@ type DataGridState = { /** * State for DataGrid Pagination : + * @param {currentPage} Page index of the current page + * @param {pageSize} page size of the page. Default is 10 + * @param {totalItems} total number of items + * @param {firstItem} first item number in current page + * @param {lastItem} last item number in current page + * @param {totalPages} number of total pages + * @param {pageSizes} array of page sizes. can support string "custom" For example, ["10", "20", "50", "100", CUSTOM_PAGE_SIZE_OPTION] + * @param {compactFooter} if true renders compact pagination footer * @param {isCustomPageSizeSelected} if true renders input box to enter custom pageSize + * @param {maxCustomPageSize} maximum value for custom page size */ type DataGridPaginationState = { currentPage: number; @@ -390,7 +401,7 @@ export class DataGrid extends React.PureComponent pageSize, totalItems, compactFooter, - pageSizes = DEFAULT_PAGE_SIZES, + pageSizes, maxCustomPageSize = MAX_PAGE_SIZE, } = pagination; const currentPageNumber: number = currentPage || DEFAULT_CURRENT_PAGE_NUMBER; @@ -549,7 +560,10 @@ export class DataGrid extends React.PureComponent this.setState( prevState => ({ ...prevState, - pagination: {...prevState.pagination!, isCustomPageSizeSelected: evt.target.value === "Custom"}, + pagination: { + ...prevState.pagination!, + isCustomPageSizeSelected: evt.target.value === CUSTOM_PAGE_SIZE_OPTION, + }, }), () => { const {isCustomPageSizeSelected, currentPage} = this.state.pagination!; @@ -1519,7 +1533,7 @@ export class DataGrid extends React.PureComponent // Function to build pageSizes select private buildPageSizesSelect(): React.ReactElement { - const {pageSizes = DEFAULT_PAGE_SIZES, pageSize, isCustomPageSizeSelected} = this.state.pagination!; + const {pageSizes, pageSize, isCustomPageSizeSelected} = this.state.pagination!; const {itemText = DEFAULT_ITEM_TEXT} = this.props; return (
@@ -1622,7 +1636,7 @@ export class DataGrid extends React.PureComponent const {className, style, compactFooter} = this.props.pagination!; const {itemText = DEFAULT_ITEM_TEXT} = this.props; const showCompactFooter: boolean = compactFooter || this.isDetailPaneOpen(); - let {totalItems, firstItem, lastItem, pageSizes = DEFAULT_PAGE_SIZES} = this.state.pagination!; + let {totalItems, firstItem, lastItem, pageSizes} = this.state.pagination!; if (totalItems === 0) { firstItem = lastItem = 0; } @@ -1691,9 +1705,10 @@ export class DataGrid extends React.PureComponent const {pagination} = this.state; let renderPaginationFooter = false; if (pagination) { - const {totalItems, pageSize} = pagination; - if (totalItems && pageSize && totalItems > 0) { - renderPaginationFooter = true; + const {totalItems, pageSize, pageSizes} = pagination; + if (totalItems && pageSize) { + // Render pagination footer if pageSizes are given or if totalItems are greater than pageSize + renderPaginationFooter = pageSizes ? totalItems > 0 : totalItems >= pageSize; } } diff --git a/src/datagrid/DataGridStoriesData.tsx b/src/datagrid/DataGridStoriesData.tsx index 819cb7b8..5665f030 100644 --- a/src/datagrid/DataGridStoriesData.tsx +++ b/src/datagrid/DataGridStoriesData.tsx @@ -15,6 +15,7 @@ import {Button} from "../forms/button"; import {SortOrder, DataGridRow, DataGridFilterResult, DataGridColumn} from "."; import {Password} from "../forms/password/Password"; import {ToolTip, ToolTipDirection, ToolTipSize} from "../forms/tooltip/ToolTip"; +import {CUSTOM_PAGE_SIZE_OPTION} from "./DataGrid"; /** * General file description : @@ -595,10 +596,11 @@ export const paginationDetails = { pageSizes: ["5", "10"], }; -export const paginationDetailswithDefaultPageSizes = { +export const paginationDetailswithPageSizes = { totalItems: paginationRows.length, getPageData: getPageDataForCustomPageSize, pageSize: 10, + pageSizes: ["10", "20", "50", "100", CUSTOM_PAGE_SIZE_OPTION], }; export const paginationDetailsWithCompactFooter = { From f0d597e1999a7ef36a24bb4634dc0c855526a8ad Mon Sep 17 00:00:00 2001 From: Arpita Kate Date: Fri, 26 Apr 2024 18:09:22 +0000 Subject: [PATCH 2/7] Removed unused import --- src/datagrid/DataGrid.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/datagrid/DataGrid.tsx b/src/datagrid/DataGrid.tsx index 7afa818c..9ec48e70 100644 --- a/src/datagrid/DataGrid.tsx +++ b/src/datagrid/DataGrid.tsx @@ -18,7 +18,6 @@ import {Icon, Direction} from "../icon"; import {Spinner, SpinnerSize} from "../spinner/Spinner"; import {HideShowColumns} from "./HideShowColumns"; import {DataGridColumnResize} from "./DataGridColumnResize"; -import {totalmem} from "os"; /** * General component description : From e8a77cbf2d384cb85792fd00b49b333486f0fde1 Mon Sep 17 00:00:00 2001 From: Arpita Kate Date: Sat, 27 Apr 2024 17:36:08 +0000 Subject: [PATCH 3/7] Update datagrid pagination stories --- src/datagrid/DataGrid.tsx | 19 +++++++++++++------ src/datagrid/DataGridStoriesData.tsx | 11 ++++++----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/datagrid/DataGrid.tsx b/src/datagrid/DataGrid.tsx index 9ec48e70..942e8e6e 100644 --- a/src/datagrid/DataGrid.tsx +++ b/src/datagrid/DataGrid.tsx @@ -216,8 +216,9 @@ export type DataGridSort = { * @param {pageSizes} Array containing pageSize which user can select from dropdown menu. * Supports custom page sizes. For example["10", "20", "50", "100", CUSTOM_PAGE_SIZE_OPTION] * @param {maxCustomPageSize} Maximum limit for custom page size as well as for pageSize dropdown + * @param {isCustomPageSizeSelected} set to true if page sizes dropdown is present and custom option is selected */ -type DataGridPaginationProps = { +export type DataGridPaginationProps = { className?: string; style?: any; currentPage?: number; @@ -227,6 +228,7 @@ type DataGridPaginationProps = { compactFooter?: boolean; getPageData?: (pageIndex: number, pageSize: number) => Promise; maxCustomPageSize?: number; + isCustomPageSizeSelected?: boolean; }; /** @@ -279,7 +281,7 @@ export const DEFAULT_COLUMN_WIDTH: number = 100; export const DEFAULT_CURRENT_PAGE_NUMBER: number = 1; export const DEFAULT_PAGE_SIZE: number = 10; export const DEFAULT_TOTAL_ITEMS: number = 0; -export const MAX_PAGE_SIZE: number = 1000; +export const DEFAULT_MAX_PAGE_SIZE: number = 1000; export const CUSTOM_PAGE_SIZE_OPTION: string = "Custom"; /** @@ -401,11 +403,14 @@ export class DataGrid extends React.PureComponent totalItems, compactFooter, pageSizes, - maxCustomPageSize = MAX_PAGE_SIZE, + maxCustomPageSize, + isCustomPageSizeSelected, } = pagination; const currentPageNumber: number = currentPage || DEFAULT_CURRENT_PAGE_NUMBER; const datagridPageSize: number = pageSize || DEFAULT_PAGE_SIZE; const totalItemsInDatagrid: number = totalItems || DEFAULT_TOTAL_ITEMS; + const maxCustomPageSizeNumber: number = maxCustomPageSize || DEFAULT_MAX_PAGE_SIZE; + const isCustomPageSizeOptionSelected: boolean = isCustomPageSizeSelected || false; const firstItem: number = this.getFirstItemIndex(currentPageNumber, datagridPageSize); const lastItem: number = this.getLastItemIndex(datagridPageSize, totalItemsInDatagrid, firstItem); @@ -419,7 +424,8 @@ export class DataGrid extends React.PureComponent firstItem: firstItem, lastItem: lastItem, totalPages: this.getTotalPages(totalItemsInDatagrid, datagridPageSize), - maxCustomPageSize: maxCustomPageSize, + maxCustomPageSize: maxCustomPageSizeNumber, + isCustomPageSizeSelected: isCustomPageSizeOptionSelected, }; return paginationState; @@ -1513,12 +1519,13 @@ export class DataGrid extends React.PureComponent //Function to render textbox for custom pageSize private buildCustomPageSizeSelect = () => { + const {pageSize} = this.state.pagination!; return (
this.handleCustomPageSizeChange(evt)} + onKeyDown={evt => this.handleCustomPageSizeChangeOnKeyDown(evt)} + onKeyPress={allowOnlyIntegers} />
); @@ -1560,7 +1567,7 @@ export class DataGrid extends React.PureComponent })}
- {isCustomPageSizeSelected && this.buildCustomPageSizeSelect()} + {isCustomPageSizeSelected && this.buildCustomPageSizeInput()}
); @@ -1617,6 +1624,7 @@ export class DataGrid extends React.PureComponent aria-label="Current Page" onBlur={evt => this.handlePageChangeOnBlur(evt)} onKeyDown={evt => this.handlePageChangeOnKeyDown(evt)} + onKeyPress={allowOnlyIntegers} />  / {totalPages}