From 13d4257c4f442ef7c36437fe59a69894926cecdc Mon Sep 17 00:00:00 2001 From: Arunavo Ray Date: Tue, 17 Jun 2025 16:52:15 +0530 Subject: [PATCH] refactor: enhance organization card display with status badges and improved layout --- .../organizations/OrganizationsList.tsx | 223 +++++++++++------- 1 file changed, 143 insertions(+), 80 deletions(-) diff --git a/src/components/organizations/OrganizationsList.tsx b/src/components/organizations/OrganizationsList.tsx index e9a5ffe..dbc3efe 100644 --- a/src/components/organizations/OrganizationsList.tsx +++ b/src/components/organizations/OrganizationsList.tsx @@ -1,14 +1,14 @@ import { useMemo } from "react"; import { Card } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; -import { Plus, RefreshCw, Building2 } from "lucide-react"; +import { Badge } from "@/components/ui/badge"; +import { Plus, RefreshCw, Building2, Check, AlertCircle, Clock } from "lucide-react"; import { SiGithub } from "react-icons/si"; import type { Organization } from "@/lib/db/schema"; import type { FilterParams } from "@/types/filter"; import Fuse from "fuse.js"; import { Skeleton } from "@/components/ui/skeleton"; -import { Checkbox } from "@/components/ui/checkbox"; -import { getStatusColor } from "@/lib/utils"; +import { cn } from "@/lib/utils"; interface OrganizationListProps { organizations: Organization[]; @@ -20,6 +20,22 @@ interface OrganizationListProps { onAddOrganization?: () => void; } +// Helper function to get status badge variant and icon +const getStatusBadge = (status: string | null) => { + switch (status) { + case "imported": + return { variant: "secondary" as const, label: "Not Mirrored", icon: null }; + case "mirroring": + return { variant: "outline" as const, label: "Mirroring", icon: Clock }; + case "mirrored": + return { variant: "default" as const, label: "Mirrored", icon: Check }; + case "failed": + return { variant: "destructive" as const, label: "Failed", icon: AlertCircle }; + default: + return { variant: "secondary" as const, label: "Unknown", icon: null }; + } +}; + export function OrganizationList({ organizations, isLoading, @@ -93,29 +109,45 @@ export function OrganizationList({
{filteredOrganizations.map((org, index) => { const isLoading = loadingOrgIds.has(org.id ?? ""); + const statusBadge = getStatusBadge(org.status); + const StatusIcon = statusBadge.icon; return ( - -
-
- - - {org.name} - + +
+
+
+ + + {org.name} + + + {org.membershipRole} + +
- - {org.membershipRole} - {/* needs to be updated */} - + + {StatusIcon && } + {statusBadge.label} +
@@ -125,58 +157,96 @@ export function OrganizationList({ {org.repositoryCount === 1 ? "repository" : "repositories"}
- {(org.publicRepositoryCount !== undefined || - org.privateRepositoryCount !== undefined || - org.forkRepositoryCount !== undefined) && ( -
- {org.publicRepositoryCount !== undefined && ( - -
- {org.publicRepositoryCount} public - - )} - {org.privateRepositoryCount !== undefined && org.privateRepositoryCount > 0 && ( - -
- {org.privateRepositoryCount} private - - )} - {org.forkRepositoryCount !== undefined && org.forkRepositoryCount > 0 && ( - -
- {org.forkRepositoryCount} fork{org.forkRepositoryCount !== 1 ? 's' : ''} - - )} -
- )} + {/* Always render this section to prevent layout shift */} +
+ {isLoading || (org.status === "mirroring" && org.publicRepositoryCount === undefined) ? ( + <> + + + + ) : ( + <> + {org.publicRepositoryCount !== undefined ? ( + +
+ {org.publicRepositoryCount} public + + ) : null} + {org.privateRepositoryCount !== undefined && org.privateRepositoryCount > 0 ? ( + +
+ {org.privateRepositoryCount} private + + ) : null} + {org.forkRepositoryCount !== undefined && org.forkRepositoryCount > 0 ? ( + +
+ {org.forkRepositoryCount} fork{org.forkRepositoryCount !== 1 ? 's' : ''} + + ) : null} + {/* Show a placeholder if no counts are available to maintain height */} + {org.publicRepositoryCount === undefined && + org.privateRepositoryCount === undefined && + org.forkRepositoryCount === undefined && ( + Loading counts... + )} + + )} +
-
- { - if (checked && !org.isIncluded && org.id) { - onMirror({ orgId: org.id }); - } - }} - /> - - - {isLoading && ( - +
+ {org.status === "imported" && ( + + )} + + {org.status === "mirroring" && ( + + )} + + {org.status === "mirrored" && ( + + )} + + {org.status === "failed" && ( + )}
@@ -185,19 +255,12 @@ export function OrganizationList({ href={`https://github.com/${org.name}`} target="_blank" rel="noopener noreferrer" + title="View on GitHub" >
- - {/* dont know if this looks good. maybe revised */} -
-
- {org.status} -
); })}