Skip to content
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

Remove pagelimit default #933

Merged
merged 6 commits into from
Mar 5, 2024
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
2 changes: 1 addition & 1 deletion overrides/react/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export interface PaginateProps {
handlePageChange?: (payload: Partial<PaginatePayload>) => void;
reFetch: (payload: PaginatePayload) => any;
pageTokenMap: Record<number, PageToken>;
itemsPerPage?: number;
itemsPerPage: number;
currentPageItemsCount: number;
children?: any;
}
2 changes: 1 addition & 1 deletion overrides/svelte/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export interface PaginateProps {
handlePageChange?: (payload: Partial<PaginatePayload>) => void;
reFetch: (payload: PaginatePayload) => any;
pageTokenMap: Record<number, PageToken>;
itemsPerPage?: number;
itemsPerPage: number;
currentPageItemsCount: number;
children?: any;
}
2 changes: 1 addition & 1 deletion overrides/vue/vue3/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export interface PaginateProps {
handlePageChange?: (payload: Partial<PaginatePayload>) => void;
reFetch: (payload: PaginatePayload) => any;
pageTokenMap: Record<number, PageToken>;
itemsPerPage?: number;
itemsPerPage: number;
currentPageItemsCount: number;
children?: any;
}
4 changes: 2 additions & 2 deletions src/dsync/DirectoryList/index.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -172,7 +172,7 @@ export default function DirectoryList(props: DirectoryListProps) {
<LoadingContainer isBusy={state.isDirectoryListLoading}>
<Show when={state.isPaginated}>
<Paginate
itemsPerPage={props.paginate?.itemsPerPage}
itemsPerPage={props.paginate!.itemsPerPage}
currentPageItemsCount={state.directoryListData.length}
handlePageChange={props.paginate?.handlePageChange}
reFetch={reFetch}
Expand Down
2 changes: 1 addition & 1 deletion src/dsync/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface DirectoryListProps {
tableProps?: Pick<TableProps, 'tableCaption' | 'classNames'>;
tenant?: string;
product?: string;
paginate?: Partial<Pick<PaginateProps, 'itemsPerPage' | 'handlePageChange'>>;
paginate?: Pick<PaginateProps, 'itemsPerPage'> & Partial<Pick<PaginateProps, 'handlePageChange'>>;
}

export interface EditDirectoryProps {
Expand Down
22 changes: 9 additions & 13 deletions src/shared/Paginate/index.lite.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -31,21 +27,21 @@ 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 });
// Trigger data re-fetch with new offset
typeof props.reFetch === 'function' &&
props.reFetch({
offset: newOffset,
limit: state._itemsPerPage,
limit: props.itemsPerPage,
pageToken: props.pageTokenMap[currentOffset],
});
},
Expand All @@ -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`);
Expand All @@ -77,7 +73,7 @@ export default function Paginate(props: PaginateProps) {
typeof props.reFetch === 'function' &&
props.reFetch({
offset: 0,
limit: state._itemsPerPage,
limit: props.itemsPerPage,
});
}
}
Expand Down
1 change: 0 additions & 1 deletion src/shared/Paginate/utils.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export interface PaginateProps {
handlePageChange?: (payload: Partial<PaginatePayload>) => void;
reFetch: (payload: PaginatePayload) => any;
pageTokenMap: Record<number, PageToken>;
itemsPerPage?: number;
itemsPerPage: number;
currentPageItemsCount: number;
children?: any;
}
4 changes: 2 additions & 2 deletions src/sso/connections/ConnectionList/index.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -195,7 +195,7 @@ export default function ConnectionList(props: ConnectionListProps) {
<LoadingContainer isBusy={state.isConnectionListLoading}>
<Show when={state.isPaginated}>
<Paginate
itemsPerPage={props.paginate?.itemsPerPage}
itemsPerPage={props.paginate!.itemsPerPage}
currentPageItemsCount={state.connectionListData.length}
handlePageChange={props.paginate?.handlePageChange}
reFetch={reFetch}
Expand Down
2 changes: 1 addition & 1 deletion src/sso/connections/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface ConnectionListProps {
product?: string;
// If true will sort the list display based on sortOrder of the connection
displaySorted?: boolean;
paginate?: Partial<Pick<PaginateProps, 'itemsPerPage' | 'handlePageChange'>>;
paginate?: Pick<PaginateProps, 'itemsPerPage'> & Partial<Pick<PaginateProps, 'handlePageChange'>>;
}

export interface CreateConnectionProps {
Expand Down