-
Notifications
You must be signed in to change notification settings - Fork 611
feat: add new load more component #3033
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9fbe3f0
feat: add new load more component
ogzhanolguncu 38d6fcb
fix: add total logs query
ogzhanolguncu cca988d
feat: Add full count to ratelimit
ogzhanolguncu 1c226b8
feat: add total count to ratelimit overview
ogzhanolguncu 407b1fa
feat: hide count for api for now because its too costly
ogzhanolguncu 6e07914
chore: remove comments
ogzhanolguncu 7f9adf9
Merge branch 'main' into feat-table-new-load-more
perkinsjr 8e1638c
Merge branch 'main' into feat-table-new-load-more
chronark f70d0f4
Merge branch 'main' into feat-table-new-load-more
ogzhanolguncu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
72 changes: 65 additions & 7 deletions
72
apps/dashboard/components/virtual-table/components/loading-indicator.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -1,8 +1,66 @@ | ||
| export const LoadingIndicator = () => ( | ||
| <div className="fixed bottom-0 left-0 right-0 py-2 bg-background/90 backdrop-blur-sm border-t border-border"> | ||
| <div className="flex items-center justify-center gap-2 text-sm text-accent-11"> | ||
| <div className="h-1.5 w-1.5 rounded-full bg-accent-11 animate-pulse" /> | ||
| Loading more data | ||
| import { Button } from "@unkey/ui"; | ||
|
|
||
| type LoadMoreFooterProps = { | ||
| onLoadMore?: () => void; | ||
| isFetchingNextPage?: boolean; | ||
| totalVisible: number; | ||
| totalCount: number; | ||
| className?: string; | ||
| itemLabel?: string; | ||
| buttonText?: string; | ||
| hasMore?: boolean; | ||
| hide?: boolean; | ||
| countInfoText?: React.ReactNode; | ||
| }; | ||
|
|
||
| export const LoadMoreFooter = ({ | ||
| onLoadMore, | ||
| isFetchingNextPage = false, | ||
| totalVisible, | ||
| totalCount, | ||
| itemLabel = "items", | ||
| buttonText = "Load more", | ||
| hasMore = true, | ||
| countInfoText, | ||
| hide, | ||
| }: LoadMoreFooterProps) => { | ||
| const shouldShow = !!onLoadMore; | ||
|
|
||
| if (hide) { | ||
| return; | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| className="fixed bottom-0 left-0 right-0 w-full items-center justify-center flex z-10 transition-opacity duration-200" | ||
| style={{ | ||
| opacity: shouldShow ? 1 : 0, | ||
| pointerEvents: shouldShow ? "auto" : "none", | ||
| }} | ||
| > | ||
| <div className="w-[740px] border bg-gray-1 dark:bg-black border-gray-6 h-[60px] flex items-center justify-center p-[18px] rounded-[10px] drop-shadow-lg shadow-sm mb-5"> | ||
| <div className="flex w-full justify-between items-center text-[13px] text-accent-9"> | ||
| {countInfoText && <div>{countInfoText}</div>} | ||
| {!countInfoText && ( | ||
| <div className="flex gap-2"> | ||
| <span>Viewing</span> <span className="text-accent-12">{totalVisible}</span> | ||
| <span>of</span> | ||
| <span className="text-grayA-12">{totalCount}</span> | ||
| <span>{itemLabel}</span> | ||
| </div> | ||
| )} | ||
|
|
||
| <Button | ||
| variant="outline" | ||
| size="sm" | ||
| onClick={onLoadMore} | ||
| loading={isFetchingNextPage} | ||
| disabled={isFetchingNextPage || !hasMore} | ||
| > | ||
| {buttonText} | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| ); | ||
| }; |
This file contains hidden or 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
19 changes: 5 additions & 14 deletions
19
apps/dashboard/components/virtual-table/hooks/useTableHeight.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -1,36 +1,27 @@ | ||
| import { useEffect, useState } from "react"; | ||
|
|
||
| export const useTableHeight = ( | ||
| containerRef: React.RefObject<HTMLDivElement>, | ||
| headerHeight: number, | ||
| tableBorder: number, | ||
| ) => { | ||
| // Adds bottom spacing to prevent the table from extending to the edge of the viewport | ||
| const BREATHING_SPACE = 20; | ||
| export const useTableHeight = (containerRef: React.RefObject<HTMLDivElement>) => { | ||
| const [fixedHeight, setFixedHeight] = useState(0); | ||
|
|
||
| useEffect(() => { | ||
| const calculateHeight = () => { | ||
| if (!containerRef.current) { | ||
| return; | ||
| } | ||
| const rect = containerRef.current.getBoundingClientRect(); | ||
| const totalHeaderHeight = headerHeight + tableBorder; | ||
| const availableHeight = window.innerHeight - rect.top - totalHeaderHeight; | ||
| const availableHeight = window.innerHeight - rect.top - BREATHING_SPACE; | ||
| setFixedHeight(Math.max(availableHeight, 0)); | ||
| }; | ||
|
|
||
| calculateHeight(); | ||
| const resizeObserver = new ResizeObserver(calculateHeight); | ||
| window.addEventListener("resize", calculateHeight); | ||
|
|
||
| if (containerRef.current) { | ||
| resizeObserver.observe(containerRef.current); | ||
| } | ||
|
|
||
| return () => { | ||
| resizeObserver.disconnect(); | ||
| window.removeEventListener("resize", calculateHeight); | ||
| }; | ||
| }, [containerRef, headerHeight, tableBorder]); | ||
|
|
||
| }, [containerRef]); | ||
| return fixedHeight; | ||
| }; |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.