Update Active Directory sites page to display site details in a table

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 705f2157-ef97-4fbd-89e4-8c7f2ecaea90
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7ed01c5f-a82d-405a-b728-b2e3d127c60c/0728d421-d119-4a15-876b-b3825b0e616d.jpg
This commit is contained in:
alphaeusmote
2025-04-10 00:05:41 +00:00
parent 56090d1a27
commit 8cbf4cf23e
+197 -189
View File
@@ -552,7 +552,7 @@ export default function SitesPage() {
<div> <div>
<CardTitle>Active Directory Sites</CardTitle> <CardTitle>Active Directory Sites</CardTitle>
<CardDescription> <CardDescription>
Manage physical locations in your Active Directory infrastructure. View and manage sites in your Active Directory environment.
</CardDescription> </CardDescription>
</div> </div>
<div className="flex gap-2"> <div className="flex gap-2">
@@ -579,104 +579,108 @@ export default function SitesPage() {
</div> </div>
</CardHeader> </CardHeader>
<CardContent> <CardContent>
{!selectedConnection ? ( <Table>
<div className="text-center py-10"> <TableHeader>
<p className="text-muted-foreground">Please select a connection to view sites.</p> <TableRow>
</div> <TableHead>Name</TableHead>
) : isLoadingSites ? ( <TableHead>Description</TableHead>
<div className="space-y-3"> <TableHead>Location</TableHead>
{[...Array(5)].map((_, i) => ( <TableHead>Associated Subnets</TableHead>
<div key={i} className="flex items-center space-x-4"> <TableHead>Actions</TableHead>
<Skeleton className="h-12 w-full" /> </TableRow>
</div> </TableHeader>
))} <TableBody>
</div> {!selectedConnection ? (
) : sitesError ? (
<div className="text-center py-10">
<p className="text-destructive font-medium">Error loading sites</p>
<p className="text-muted-foreground">{sitesError.message || "Unknown error occurred"}</p>
</div>
) : (
<Table>
<TableHeader>
<TableRow> <TableRow>
<TableHead>Name</TableHead> <TableCell colSpan={5} className="text-center py-6">
<TableHead>Description</TableHead> <p className="text-muted-foreground">Please select a connection to view sites.</p>
<TableHead>Location</TableHead> </TableCell>
<TableHead>Associated Subnets</TableHead>
<TableHead>Actions</TableHead>
</TableRow> </TableRow>
</TableHeader> ) : isLoadingSites ? (
<TableBody> <TableRow>
{sitesData?.data && sitesData.data.length > 0 ? ( <TableCell colSpan={5} className="p-0 border-0">
sitesData.data.map((site: AdSite) => ( <div className="space-y-3 p-4">
<TableRow key={site.objectGUID}> {[...Array(5)].map((_, i) => (
<TableCell className="font-medium">{site.name}</TableCell> <Skeleton key={i} className="h-12 w-full" />
<TableCell>{site.description || '—'}</TableCell> ))}
<TableCell>{site.location || '—'}</TableCell> </div>
<TableCell> </TableCell>
{site.subnets && site.subnets.length > 0 </TableRow>
? site.subnets.map((subnet, idx) => ( ) : sitesError ? (
<Badge key={idx} variant="outline" className="mr-1"> <TableRow>
{subnet.split(',')[0].replace('CN=', '')} <TableCell colSpan={5} className="text-center py-6">
</Badge> <p className="text-destructive font-medium">Error loading sites</p>
)) <p className="text-muted-foreground">{sitesError.message || "Unknown error occurred"}</p>
: '—'} </TableCell>
</TableCell> </TableRow>
<TableCell> ) : sitesData?.data && sitesData.data.length > 0 ? (
<div className="flex space-x-2"> sitesData.data.map((site: AdSite) => (
<Button <TableRow key={site.objectGUID}>
variant="outline" <TableCell className="font-medium">{site.name}</TableCell>
size="sm" <TableCell>{site.description || '—'}</TableCell>
onClick={() => setEditingSite(site)} <TableCell>{site.location || '—'}</TableCell>
> <TableCell>
<Edit className="h-4 w-4" /> {site.subnets && site.subnets.length > 0
</Button> ? site.subnets.map((subnet, idx) => (
<AlertDialog> <Badge key={idx} variant="outline" className="mr-1">
<AlertDialogTrigger asChild> {subnet.split(',')[0].replace('CN=', '')}
<Button </Badge>
variant="outline" ))
size="sm" : '—'}
className="text-destructive" </TableCell>
<TableCell>
<div className="flex space-x-2">
<Button
variant="outline"
size="sm"
onClick={() => setEditingSite(site)}
>
<Edit className="h-4 w-4" />
</Button>
<AlertDialog>
<AlertDialogTrigger asChild>
<Button
variant="outline"
size="sm"
className="text-destructive"
>
<Trash2 className="h-4 w-4" />
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
Are you sure you want to delete this site?
</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will permanently delete the
site "{site.name}" and all of its data from the server.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={() => deleteSiteMutation.mutate(site.objectGUID)}
className="bg-destructive text-destructive-foreground"
> >
<Trash2 className="h-4 w-4" /> Delete
</Button> </AlertDialogAction>
</AlertDialogTrigger> </AlertDialogFooter>
<AlertDialogContent> </AlertDialogContent>
<AlertDialogHeader> </AlertDialog>
<AlertDialogTitle> </div>
Are you sure you want to delete this site?
</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will permanently delete the
site "{site.name}" and all of its data from the server.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={() => deleteSiteMutation.mutate(site.objectGUID)}
className="bg-destructive text-destructive-foreground"
>
Delete
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</TableCell>
</TableRow>
))
) : (
<TableRow>
<TableCell colSpan={5} className="text-center py-6">
<p className="text-muted-foreground">No sites found for this connection.</p>
</TableCell> </TableCell>
</TableRow> </TableRow>
)} ))
</TableBody> ) : (
</Table> <TableRow>
)} <TableCell colSpan={5} className="text-center py-6">
<p className="text-muted-foreground">No sites found for this connection.</p>
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
{/* Pagination for sites */} {/* Pagination for sites */}
{sitesData?.data && sitesData.data.length > 0 && totalSitePages > 1 && ( {sitesData?.data && sitesData.data.length > 0 && totalSitePages > 1 && (
@@ -840,106 +844,110 @@ export default function SitesPage() {
</div> </div>
</CardHeader> </CardHeader>
<CardContent> <CardContent>
{!selectedConnection ? ( <Table>
<div className="text-center py-10"> <TableHeader>
<p className="text-muted-foreground">Please select a connection to view subnets.</p> <TableRow>
</div> <TableHead>Name</TableHead>
) : isLoadingSubnets ? ( <TableHead>CIDR</TableHead>
<div className="space-y-3"> <TableHead>Description</TableHead>
{[...Array(5)].map((_, i) => ( <TableHead>Location</TableHead>
<div key={i} className="flex items-center space-x-4"> <TableHead>Site</TableHead>
<Skeleton className="h-12 w-full" /> <TableHead>Actions</TableHead>
</div> </TableRow>
))} </TableHeader>
</div> <TableBody>
) : subnetsError ? ( {!selectedConnection ? (
<div className="text-center py-10">
<p className="text-destructive font-medium">Error loading subnets</p>
<p className="text-muted-foreground">{subnetsError.message || "Unknown error occurred"}</p>
</div>
) : (
<Table>
<TableHeader>
<TableRow> <TableRow>
<TableHead>Name</TableHead> <TableCell colSpan={6} className="text-center py-6">
<TableHead>CIDR</TableHead> <p className="text-muted-foreground">Please select a connection to view subnets.</p>
<TableHead>Description</TableHead> </TableCell>
<TableHead>Location</TableHead>
<TableHead>Site</TableHead>
<TableHead>Actions</TableHead>
</TableRow> </TableRow>
</TableHeader> ) : isLoadingSubnets ? (
<TableBody> <TableRow>
{subnetsData?.data && subnetsData.data.length > 0 ? ( <TableCell colSpan={6} className="p-0 border-0">
subnetsData.data.map((subnet: AdSubnet) => ( <div className="space-y-3 p-4">
<TableRow key={subnet.objectGUID}> {[...Array(5)].map((_, i) => (
<TableCell className="font-medium">{subnet.name}</TableCell> <Skeleton key={i} className="h-12 w-full" />
<TableCell>{subnet.cidr || '—'}</TableCell> ))}
<TableCell>{subnet.description || '—'}</TableCell> </div>
<TableCell>{subnet.location || '—'}</TableCell> </TableCell>
<TableCell> </TableRow>
{subnet.siteObject ? ( ) : subnetsError ? (
<Badge variant="outline"> <TableRow>
{subnet.siteObject.split(',')[0].replace('CN=', '')} <TableCell colSpan={6} className="text-center py-6">
</Badge> <p className="text-destructive font-medium">Error loading subnets</p>
) : ( <p className="text-muted-foreground">{subnetsError.message || "Unknown error occurred"}</p>
'—' </TableCell>
)} </TableRow>
</TableCell> ) : subnetsData?.data && subnetsData.data.length > 0 ? (
<TableCell> subnetsData.data.map((subnet: AdSubnet) => (
<div className="flex space-x-2"> <TableRow key={subnet.objectGUID}>
<Button <TableCell className="font-medium">{subnet.name}</TableCell>
variant="outline" <TableCell>{subnet.cidr || '—'}</TableCell>
size="sm" <TableCell>{subnet.description || '—'}</TableCell>
onClick={() => setEditingSubnet(subnet)} <TableCell>{subnet.location || '—'}</TableCell>
> <TableCell>
<Edit className="h-4 w-4" /> {subnet.siteObject ? (
</Button> <Badge variant="outline">
<AlertDialog> {subnet.siteObject.split(',')[0].replace('CN=', '')}
<AlertDialogTrigger asChild> </Badge>
<Button ) : (
variant="outline" '—'
size="sm" )}
className="text-destructive" </TableCell>
<TableCell>
<div className="flex space-x-2">
<Button
variant="outline"
size="sm"
onClick={() => setEditingSubnet(subnet)}
>
<Edit className="h-4 w-4" />
</Button>
<AlertDialog>
<AlertDialogTrigger asChild>
<Button
variant="outline"
size="sm"
className="text-destructive"
>
<Trash2 className="h-4 w-4" />
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
Are you sure you want to delete this subnet?
</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will permanently delete the
subnet "{subnet.name}" and all of its data from the server.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={() => deleteSubnetMutation.mutate(subnet.objectGUID)}
className="bg-destructive text-destructive-foreground"
> >
<Trash2 className="h-4 w-4" /> Delete
</Button> </AlertDialogAction>
</AlertDialogTrigger> </AlertDialogFooter>
<AlertDialogContent> </AlertDialogContent>
<AlertDialogHeader> </AlertDialog>
<AlertDialogTitle> </div>
Are you sure you want to delete this subnet?
</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will permanently delete the
subnet "{subnet.name}" and all of its data from the server.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={() => deleteSubnetMutation.mutate(subnet.objectGUID)}
className="bg-destructive text-destructive-foreground"
>
Delete
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</TableCell>
</TableRow>
))
) : (
<TableRow>
<TableCell colSpan={6} className="text-center py-6">
<p className="text-muted-foreground">No subnets found for this connection.</p>
</TableCell> </TableCell>
</TableRow> </TableRow>
)} ))
</TableBody> ) : (
</Table> <TableRow>
)} <TableCell colSpan={6} className="text-center py-6">
<p className="text-muted-foreground">No subnets found for this connection.</p>
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
{/* Pagination for subnets */} {/* Pagination for subnets */}
{subnetsData?.data && subnetsData.data.length > 0 && totalSubnetPages > 1 && ( {subnetsData?.data && subnetsData.data.length > 0 && totalSubnetPages > 1 && (