tenantpilot/components/policy-explorer/PolicyTable.tsx
Ahmed Darrazi f592e5f55b feat: Policy Explorer UX Upgrade (003)
Implemented MVP with all core features:
- Browse 50 newest policies on load with null filtering
- Click row to view details in slide-over sheet
- JSON detection and pretty formatting
- Search with real-time filtering
- Badge colors for policy types (Security=red, Compliance=blue, Config=gray, App=outline)
- Navigation consolidated to 'Policy Explorer'

New components:
- PolicyTable.tsx - table with badges and hover effects
- PolicySearchContainer.tsx - search state management
- PolicyDetailSheet.tsx - JSON detail view with formatting
- PolicyExplorerClient.tsx - client wrapper
- lib/utils/policyBadges.ts - badge color mapping

Updated:
- lib/actions/policySettings.ts - added getRecentPolicySettings() with null filtering
- app/(app)/search/page.tsx - converted to Server Component
- config/nav.ts - renamed Search to Policy Explorer, removed All Settings
- components/search/EmptyState.tsx - updated messaging

Tasks complete: 36/47 (MVP ready)
- Phase 1-7: All critical features implemented
- Phase 8: Core polish complete (T041), optional tasks remain

TypeScript:  No errors
Status: Production-ready MVP
2025-12-07 02:28:15 +01:00

81 lines
2.5 KiB
TypeScript

'use client';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table';
import { Card, CardContent } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import type { PolicySettingSearchResult } from '@/lib/actions/policySettings';
import { getPolicyBadgeConfig } from '@/lib/utils/policyBadges';
import { formatDistanceToNow } from 'date-fns';
import { de } from 'date-fns/locale';
interface PolicyTableProps {
policies: PolicySettingSearchResult[];
onRowClick: (policy: PolicySettingSearchResult) => void;
}
export function PolicyTable({ policies, onRowClick }: PolicyTableProps) {
if (policies.length === 0) {
return null;
}
return (
<Card>
<CardContent className="p-0">
<div className="overflow-x-auto">
<Table>
<TableHeader>
<TableRow>
<TableHead>Setting Name</TableHead>
<TableHead>Setting Value</TableHead>
<TableHead>Policy Name</TableHead>
<TableHead>Policy Type</TableHead>
<TableHead>Last Synced</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{policies.map((policy) => (
<TableRow
key={policy.id}
onClick={() => onRowClick(policy)}
className="cursor-pointer hover:bg-accent"
>
<TableCell className="font-medium">
{policy.settingName}
</TableCell>
<TableCell className="max-w-xs truncate">
{policy.settingValue}
</TableCell>
<TableCell>{policy.policyName}</TableCell>
<TableCell>
{(() => {
const badgeConfig = getPolicyBadgeConfig(policy.policyType);
return (
<Badge variant={badgeConfig.variant}>
{badgeConfig.label}
</Badge>
);
})()}
</TableCell>
<TableCell className="text-muted-foreground text-sm">
{formatDistanceToNow(new Date(policy.lastSyncedAt), {
addSuffix: true,
locale: de,
})}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
</CardContent>
</Card>
);
}