From 215e22dfe7a877d10623858e92f7b58cb23fd956 Mon Sep 17 00:00:00 2001 From: Aswin V Date: Tue, 5 Mar 2024 23:55:08 +0530 Subject: [PATCH] Remove pagelimit default (#933) * Remove pageLimit default and make itemsPerPage required * Fix typings * isPaginated should be `if paginate or itemsPerPage is not defined` --- overrides/react/src/shared/types.ts | 2 +- overrides/svelte/src/shared/types.ts | 2 +- overrides/vue/vue3/src/shared/types.ts | 2 +- src/dsync/DirectoryList/index.lite.tsx | 4 ++-- src/dsync/types.ts | 2 +- src/shared/Paginate/index.lite.tsx | 22 ++++++++----------- src/shared/Paginate/utils.ts | 1 - src/shared/types.ts | 2 +- .../connections/ConnectionList/index.lite.tsx | 4 ++-- src/sso/connections/types.ts | 2 +- 10 files changed, 19 insertions(+), 24 deletions(-) delete mode 100644 src/shared/Paginate/utils.ts diff --git a/overrides/react/src/shared/types.ts b/overrides/react/src/shared/types.ts index 721e66e90..95b282644 100644 --- a/overrides/react/src/shared/types.ts +++ b/overrides/react/src/shared/types.ts @@ -168,7 +168,7 @@ export interface PaginateProps { handlePageChange?: (payload: Partial) => void; reFetch: (payload: PaginatePayload) => any; pageTokenMap: Record; - itemsPerPage?: number; + itemsPerPage: number; currentPageItemsCount: number; children?: any; } diff --git a/overrides/svelte/src/shared/types.ts b/overrides/svelte/src/shared/types.ts index 0978a1d7a..a3f957315 100644 --- a/overrides/svelte/src/shared/types.ts +++ b/overrides/svelte/src/shared/types.ts @@ -123,7 +123,7 @@ export interface PaginateProps { handlePageChange?: (payload: Partial) => void; reFetch: (payload: PaginatePayload) => any; pageTokenMap: Record; - itemsPerPage?: number; + itemsPerPage: number; currentPageItemsCount: number; children?: any; } diff --git a/overrides/vue/vue3/src/shared/types.ts b/overrides/vue/vue3/src/shared/types.ts index 786db13e8..692528166 100644 --- a/overrides/vue/vue3/src/shared/types.ts +++ b/overrides/vue/vue3/src/shared/types.ts @@ -131,7 +131,7 @@ export interface PaginateProps { handlePageChange?: (payload: Partial) => void; reFetch: (payload: PaginatePayload) => any; pageTokenMap: Record; - itemsPerPage?: number; + itemsPerPage: number; currentPageItemsCount: number; children?: any; } diff --git a/src/dsync/DirectoryList/index.lite.tsx b/src/dsync/DirectoryList/index.lite.tsx index 54ad33c86..ff2a55455 100644 --- a/src/dsync/DirectoryList/index.lite.tsx +++ b/src/dsync/DirectoryList/index.lite.tsx @@ -30,7 +30,7 @@ export default function DirectoryList(props: DirectoryListProps) { return props.urls.get; }, get isPaginated() { - return props.paginate !== undefined; + return props.paginate?.itemsPerPage !== undefined; }, get actions(): TableProps['actions'] { return [ @@ -172,7 +172,7 @@ export default function DirectoryList(props: DirectoryListProps) { ; tenant?: string; product?: string; - paginate?: Partial>; + paginate?: Pick & Partial>; } export interface EditDirectoryProps { diff --git a/src/shared/Paginate/index.lite.tsx b/src/shared/Paginate/index.lite.tsx index 08f2a0a6d..fe2504afb 100644 --- a/src/shared/Paginate/index.lite.tsx +++ b/src/shared/Paginate/index.lite.tsx @@ -1,28 +1,24 @@ import { Show, onMount, onUnMount, useStore } from '@builder.io/mitosis'; import Button from '../Button/index.lite'; import { PaginateProps } from '../types'; -import { ITEMS_PER_PAGE_DEFAULT } from './utils'; import styles from './index.module.css'; import PaginateContext from './paginate.context.lite'; export default function Paginate(props: PaginateProps) { const state = useStore({ _offset: 0, - get _itemsPerPage() { - return props.itemsPerPage ?? ITEMS_PER_PAGE_DEFAULT; - }, get isPaginationHidden(): boolean { - return state._offset === 0 && props.currentPageItemsCount < state._itemsPerPage; + return state._offset === 0 && props.currentPageItemsCount < props.itemsPerPage; }, get isPreviousDisabled(): boolean { return state._offset === 0; }, get isNextDisabled(): boolean { - return props.currentPageItemsCount < state._itemsPerPage; + return props.currentPageItemsCount < props.itemsPerPage; }, handlePreviousClick() { const currentOffset = state._offset; - const newOffset = currentOffset - state._itemsPerPage; + const newOffset = currentOffset - props.itemsPerPage; state._offset = newOffset; // Update query string in URL @@ -31,13 +27,13 @@ export default function Paginate(props: PaginateProps) { typeof props.reFetch === 'function' && props.reFetch({ offset: newOffset, - limit: state._itemsPerPage, - pageToken: props.pageTokenMap[newOffset - state._itemsPerPage], + limit: props.itemsPerPage, + pageToken: props.pageTokenMap[newOffset - props.itemsPerPage], }); }, handleNextClick() { const currentOffset = state._offset; - const newOffset = currentOffset + state._itemsPerPage; + const newOffset = currentOffset + props.itemsPerPage; state._offset = newOffset; // Update query string in URL typeof props.handlePageChange === 'function' && props.handlePageChange({ offset: newOffset }); @@ -45,7 +41,7 @@ export default function Paginate(props: PaginateProps) { typeof props.reFetch === 'function' && props.reFetch({ offset: newOffset, - limit: state._itemsPerPage, + limit: props.itemsPerPage, pageToken: props.pageTokenMap[currentOffset], }); }, @@ -68,7 +64,7 @@ export default function Paginate(props: PaginateProps) { typeof props.reFetch === 'function' && props.reFetch({ offset: _offsetFromBrowserQS, - limit: state._itemsPerPage, + limit: props.itemsPerPage, }); } else { // console.log(`no offset found in url, setting offset to 0 in url`); @@ -77,7 +73,7 @@ export default function Paginate(props: PaginateProps) { typeof props.reFetch === 'function' && props.reFetch({ offset: 0, - limit: state._itemsPerPage, + limit: props.itemsPerPage, }); } } diff --git a/src/shared/Paginate/utils.ts b/src/shared/Paginate/utils.ts deleted file mode 100644 index 0cf86c1cc..000000000 --- a/src/shared/Paginate/utils.ts +++ /dev/null @@ -1 +0,0 @@ -export const ITEMS_PER_PAGE_DEFAULT = 15; diff --git a/src/shared/types.ts b/src/shared/types.ts index e7d6c30ee..9c91b389c 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -160,7 +160,7 @@ export interface PaginateProps { handlePageChange?: (payload: Partial) => void; reFetch: (payload: PaginatePayload) => any; pageTokenMap: Record; - itemsPerPage?: number; + itemsPerPage: number; currentPageItemsCount: number; children?: any; } diff --git a/src/sso/connections/ConnectionList/index.lite.tsx b/src/sso/connections/ConnectionList/index.lite.tsx index f9eb54329..667a4f30d 100644 --- a/src/sso/connections/ConnectionList/index.lite.tsx +++ b/src/sso/connections/ConnectionList/index.lite.tsx @@ -23,7 +23,7 @@ export default function ConnectionList(props: ConnectionListProps) { return props.urls.get; }, get isPaginated() { - return props.paginate !== undefined; + return props.paginate?.itemsPerPage !== undefined; }, get colsToDisplay() { return (props.cols || ['name', 'provider', 'tenant', 'product', 'type', 'status', 'actions']).map( @@ -195,7 +195,7 @@ export default function ConnectionList(props: ConnectionListProps) { >; + paginate?: Pick & Partial>; } export interface CreateConnectionProps {