Skip to content

Commit

Permalink
fix / cleanup page
Browse files Browse the repository at this point in the history
  • Loading branch information
psiddharthdesign committed Aug 14, 2024
1 parent 3de8c96 commit b1109ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,86 +1,24 @@
import { Pagination } from "@/components/Pagination";
import { getLoggedInUserOrganizationRole } from "@/data/user/organizations";
import { getAllProjectsListInOrganization, getProjectIdsInOrganization, getProjectsCountForUser, getProjectsList, getProjectsTotalCount, getSlimProjectsForUser } from "@/data/user/projects";
import { getProjectsCountForUser, getProjectsListForUser } from "@/data/user/projects";
import { serverGetLoggedInUser } from "@/utils/server/serverGetLoggedInUser";
import { projectsfilterSchema } from "@/utils/zod-schemas/params";
import { OrganizationProjectsTable } from "../projects/OrganizationProjectsTable";
import { DriftAlert, generateDummyDriftAlerts } from "./drift-alerts";



export async function UserDriftedProjectsWithPagination({
organizationId,
searchParams,
}: { organizationId: string; searchParams: unknown }) {
const filters = projectsfilterSchema.parse(searchParams);

const projectIdsForDriftAlerts = await getProjectIdsInOrganization(organizationId, 2);

// Once drift_alerts table is created, we will use that to fetch the alerts and check the count to be greater than 0
// For now, we are adding dummy alerts from dummyData.ts

// using dummy data to get drifted project ids
// TODO: once drift_alerts table is created, we will use that to fetch the alerts and check the count to be greater than 0

const driftAlerts: DriftAlert[] = generateDummyDriftAlerts(projectIdsForDriftAlerts);

// get unique project ids from the drift alerts
const driftedProjectIds = Array.from(new Set(driftAlerts.map(alert => alert.project_id)));

const [{ id: userId }, userRole] = await Promise.all([
serverGetLoggedInUser(),
getLoggedInUserOrganizationRole(organizationId),
getLoggedInUserOrganizationRole(organizationId)
]);

// const [projects, totalPages] = await Promise.all([
// getProjectsListForUser({ ...filters, organizationId, userRole, userId }),
// getProjectsCountForUser({ ...filters, organizationId, userId }),
// ]);

const [projects, totalPages] = await Promise.all([
getSlimProjectsForUser({ projectIds: driftedProjectIds, userRole, userId }),
getProjectsListForUser({ ...filters, organizationId, userRole, userId }),
getProjectsCountForUser({ ...filters, organizationId, userId }),
]);



return (
<>
<OrganizationProjectsTable projects={projects} />
<Pagination totalPages={totalPages} />
</>
);
}

export async function AllProjectsTableWithPagination({
organizationId,
searchParams,
}: { organizationId: string; searchParams: unknown }) {
const filters = projectsfilterSchema.parse(searchParams);
const [projects, totalPages] = await Promise.all([
getAllProjectsListInOrganization({ ...filters, organizationId }),
getProjectsTotalCount({ ...filters, organizationId }),
]);
return (
<>
<OrganizationProjectsTable projects={projects} />
<Pagination totalPages={totalPages} />
</>
);
}


export async function ProjectsTableWithPagination({
organizationId,
teamId,
searchParams,
}: { organizationId: string; teamId: number | null; searchParams: unknown }) {
const filters = projectsfilterSchema.parse(searchParams);
const [projects, totalPages] = await Promise.all([
getProjectsList({ ...filters, organizationId, teamId }),
getProjectsTotalCount({ ...filters, organizationId }),
]);

return (
<>
<OrganizationProjectsTable projects={projects} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PageHeading } from "@/components/PageHeading";
import { Search } from "@/components/Search";
import { T } from "@/components/ui/Typography";
import {
projectsfilterSchema,
Expand Down Expand Up @@ -27,6 +28,14 @@ export default async function DriftsPage({
title="Drifts"
subTitle="You can see the drifted projects within teams, or within your organization."
/>
<div className="md:w-1/3">
<Search placeholder="Search projects" />
{filters.query && (
<p className="text-sm ml-2 mt-4">
Searching for <span className="font-bold">{filters.query}</span>
</p>
)}
</div>
{
<Suspense
fallback={
Expand Down

0 comments on commit b1109ea

Please sign in to comment.