-
-
Notifications
You must be signed in to change notification settings - Fork 162
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
feat: Added Pagination to Environments Screen #780
base: develop
Are you sure you want to change the base?
feat: Added Pagination to Environments Screen #780
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
apps/platform/src/app/(main)/(project)/[workspace]/[project]/@environment/page.tsx
Show resolved
Hide resolved
@rajdip-b, Oh i see is it like increasing the perPage when the User clicks the Load More. like preview is 10 then again +10 = 20 when clicking on the Load More , and while api call it still holds the previous environments value before showing the new 20 environment is it like this is it like this. |
yeap |
@rajdip-b Now i done changes according to it u can check it. |
const [visibleCount, setVisibleCount] = useState<number>(INITIAL_DISPLAY_COUNT) | ||
const [page, setPage] = useState(0) | ||
const [hasMore, setHasMore] = useState(true) | ||
const [loading, setLoading] = useState(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename this to isLoading
to match out conventions
setEnvironments(data.items) | ||
const newData = page === 0 ? data.items : [...environments, ...data.items]; | ||
setEnvironments(newData); | ||
if (newData.length >= data.metadata.totalCount) setHasMore(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}) | ||
}, [selectedProject, page, getAllEnvironmentsOfProject, setEnvironments]) | ||
|
||
const handlePageShift = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel you should extract all of the logic in the use effect hook to a separate function.
- call that function once in use effect
- call that function whenever load more is clicked
@chetan102, please resolve all open reviews! |
@@ -39,24 +39,32 @@ function EnvironmentPage(): React.JSX.Element { | |||
) | |||
|
|||
useEffect(() => { | |||
if (!selectedProject) return | |||
setLoading(true) | |||
if(!selectedProject) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this check since its already present in handleEnvironmentsFetch
handleEnvironmentsFetch(); | ||
}, [selectedProject, getAllEnvironmentsOfProject, setEnvironments]) | ||
|
||
const handleEnvironmentsFetch = (newPage = 0) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename this to fetchEnvironments
handleEnvironmentsFetch(); | ||
}, [selectedProject, getAllEnvironmentsOfProject, setEnvironments]) | ||
|
||
const handleEnvironmentsFetch = (newPage = 0) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove newPage
. it should be using the page
state var
setEnvironments(newData); | ||
if (newData.length >= data.metadata.totalCount) setHasMore(false); | ||
const newData = newPage === 0 ? data.items : [...environments, ...data.items] | ||
if(newPage == 0 && page !== 0) setPage(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line doesnt make sense. initially you should set page
to -1 or null. before calling getAllEnvironmentsOfProject
, you should always increment the value of page
using setPage(prev => prev+1)
const newData = newPage === 0 ? data.items : [...environments, ...data.items] | ||
if(newPage == 0 && page !== 0) setPage(0); | ||
setEnvironments(newData) | ||
if (newData.length >= data.metadata.totalCount) setHasMore(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can check for data.metadata.next
. if its null, you can set hasMore
to false
User description
Description
Now we dont get the all environments at one , now we can get it in the batch of 10 if user wants to see the next 10 environments they have to click on Load More Button
Fixes #707
Screenshots of relevant screens
Developer's checklist
If changes are made in the code:
Documentation Update
PR Type
Enhancement
Description
Added dynamic pagination to the environments page.
Introduced a "Load More" button for additional environments.
Limited initial environment display to 10 items.
Updated UI layout to support dynamic loading.
Changes walkthrough 📝
page.tsx
Added dynamic pagination and "Load More" button
apps/platform/src/app/(main)/(project)/[workspace]/[project]/@environment/page.tsx