Skip to content

Commit

Permalink
feat(Table): adds page props
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-kumawat committed Sep 1, 2020
1 parent 2b152ed commit b5a1352
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/components/organisms/list/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface SharedListProps extends BaseProps {
onPageChange?: TableProps['onPageChange'];
headCellTooltip?: TableProps['headCellTooltip'];
separator?: TableProps['separator'];
page?: TableProps['page'];
}

type SyncListProps = SyncProps & SharedListProps;
Expand Down
6 changes: 6 additions & 0 deletions core/components/organisms/list/__stories__/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export const all = () => {
true
);

const page = number(
'page',
1
);

const paginationType = select(
'paginationType',
['basic', 'jump'],
Expand Down Expand Up @@ -131,6 +136,7 @@ export const all = () => {
separator={separator}
withPagination={withPagination}
paginationType={paginationType}
page={page}
pageSize={pageSize}
loaderSchema={applyLoaderSchema ? loaderSchema : undefined}
onRowClick={(rowData, rowIndex) => action(`on-row-click:- rowIndex: ${rowIndex} data: ${JSON.stringify(rowData)}`)()}
Expand Down
26 changes: 21 additions & 5 deletions core/components/organisms/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ interface SyncProps {
schema?: Schema;
/**
* Set for loading state of Table(in case of sync)
* @default false
*/
loading?: boolean;
/**
* Set for error state of Table(in case of sync)
* @default false
*/
error?: boolean;
/**
Expand Down Expand Up @@ -146,14 +148,17 @@ interface SharedTableProps extends BaseProps {
* Type of Table
*
* **Requires `onRowClick` for 'resource' Table**
* @default "data"
*/
type?: GridProps['type'];
/**
* Table cell size
* @default "standard"
*/
size?: GridProps['size'];
/**
* Allow Column reordering
* @default true
*/
draggable?: GridProps['draggable'];
/**
Expand Down Expand Up @@ -205,21 +210,28 @@ interface SharedTableProps extends BaseProps {
withCheckbox?: GridProps['withCheckbox'];
/**
* Set for visibility of Menu on Table Head Cell
* @default true
*/
showMenu?: GridProps['showMenu'];
/**
* Set for `Pagination` component in `Table`(**Not applied if pageSize >= totalRecords**)
* @default true
*/
withPagination?: GridProps['withPagination'];
/**
* Initial page passed to `Table`
* @default 1
*/
page?: PaginationProps['page'];
/**
* `Pagination` component type
* @default "jump"
*/
paginationType?: PaginationProps['type'];
/**
* Number of rows to be rendered on a page
*
* **Also used to control number of rows to be rendered while loading: true**
* @default 15
*/
pageSize?: GridProps['pageSize'];
/**
Expand All @@ -228,13 +240,15 @@ interface SharedTableProps extends BaseProps {
loaderSchema?: GridProps['loaderSchema'];
/**
* Set to allow multiple column sorting
* @default true
*/
multipleSorting?: boolean;
/**
* Initial sortingList passed to `Table`
* <pre className="DocPage-codeBlock">
* SortType: 'asc' | 'desc'
* </pre>
* @default []
*/
sortingList?: GridProps['sortingList'];
/**
Expand All @@ -243,6 +257,7 @@ interface SharedTableProps extends BaseProps {
* Filter: Array of selected values passed in dropdown
* `any[]`
* </pre>
* @default {}
*/
filterList?: GridProps['filterList'];
/**
Expand Down Expand Up @@ -287,16 +302,17 @@ const defaultProps = {
multipleSorting: true,
headerOptions: {},
paginationType: 'jump',
page: 1,
pageSize: 15,
loading: false,
draggable: true
};
type DefaultProps = Readonly<typeof defaultProps>;

export type SyncTableProps = SyncProps & SharedTableProps;
export type AsyncTableProps = AsyncProps & SharedTableProps;
export type SyncTableProps = SyncProps & SharedTableProps & DefaultProps;
export type AsyncTableProps = AsyncProps & SharedTableProps & DefaultProps;

export type TableProps = (AsyncTableProps & SyncTableProps) & DefaultProps;
export type TableProps = (AsyncTableProps & SyncTableProps);

interface TableState {
async: boolean;
Expand Down Expand Up @@ -333,7 +349,7 @@ export class Table extends React.Component<TableProps, TableState> {
async,
data: !async ? data : [],
schema: !async ? schema : [],
page: 1,
page: props.page,
sortingList: props.sortingList || [],
filterList: props.filterList || {},
totalRecords: !async ? data.length : 0,
Expand Down
6 changes: 6 additions & 0 deletions core/components/organisms/table/__stories__/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export const all = () => {
false
);

const page = number(
'page',
1
);

const paginationType = select(
'paginationType',
['basic', 'jump'],
Expand Down Expand Up @@ -156,6 +161,7 @@ export const all = () => {
nestedRows={nestedRows}
nestedRowRenderer={nestedRowRenderer}
withPagination={withPagination}
page={page}
paginationType={paginationType}
pageSize={pageSize}
loaderSchema={applyLoaderSchema ? loaderSchema : undefined}
Expand Down

0 comments on commit b5a1352

Please sign in to comment.