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

feat: Added Pagination to Environments Screen #780

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { useEffect } from 'react'
import { useEffect, useState } from 'react'
import { useAtom, useAtomValue, useSetAtom } from 'jotai'
import { EnvironmentSVG } from '@public/svg/dashboard'
import {
Expand All @@ -18,13 +18,16 @@ import ControllerInstance from '@/lib/controller-instance'
import { Button } from '@/components/ui/button'
import { useHttp } from '@/hooks/use-http'

const INITIAL_DISPLAY_COUNT = 10

function EnvironmentPage(): React.JSX.Element {
const setIsCreateEnvironmentOpen = useSetAtom(createEnvironmentOpenAtom)
const isDeleteEnvironmentOpen = useAtomValue(deleteEnvironmentOpenAtom)
const isEditEnvironmentOpen = useAtomValue(editEnvironmentOpenAtom)
const [environments, setEnvironments] = useAtom(environmentsOfProjectAtom)
const selectedProject = useAtomValue(selectedProjectAtom)
const selectedEnvironment = useAtomValue(selectedEnvironmentAtom)
const [visibleCount, setVisibleCount] = useState<number>(INITIAL_DISPLAY_COUNT)

const getAllEnvironmentsOfProject = useHttp(() =>
ControllerInstance.getInstance().environmentController.getAllEnvironmentsOfProject(
Expand Down Expand Up @@ -69,23 +72,30 @@ function EnvironmentPage(): React.JSX.Element {
</Button>
</div>
) : (
// Showing this when environments are present
<div
className={`grid h-fit w-full grid-cols-1 gap-8 p-3 text-white md:grid-cols-2 xl:grid-cols-3 ${isDeleteEnvironmentOpen ? 'inert' : ''} `}
>
{environments.map((environment) => (
<EnvironmentCard environment={environment} key={environment.id} />
))}
//Showing this when environments are present
<div className="flex w-full flex-col">
<div
className={`grid h-fit w-full grid-cols-1 gap-8 p-3 text-white md:grid-cols-2 xl:grid-cols-3 ${isDeleteEnvironmentOpen ? 'inert' : ''} `}
>
{environments.slice(0, visibleCount).map((environment) => (
<EnvironmentCard environment={environment} key={environment.id} />
))}

{/* Delete environment alert dialog */}
{isDeleteEnvironmentOpen && selectedEnvironment ? (
<ConfirmDeleteEnvironment />
) : null}
{/* Delete environment alert dialog */}
{isDeleteEnvironmentOpen && selectedEnvironment ? (
<ConfirmDeleteEnvironment />
) : null}

{/* Edit environment dialog */}
{isEditEnvironmentOpen && selectedEnvironment ? (
<EditEnvironmentDialogue />
) : null}
{/* Edit environment dialog */}
{isEditEnvironmentOpen && selectedEnvironment ? (
<EditEnvironmentDialogue />
) : null}
</div>
{visibleCount < environments.length && (
<div className="my-2 flex w-full justify-center py-2">
<Button onClick={()=> setVisibleCount((prev) => prev + INITIAL_DISPLAY_COUNT)}>Load More</Button>
</div>
)}
</div>
)}
</div>
Expand Down