tenantpilot/lib/utils/policyBadges.ts
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

57 lines
1.7 KiB
TypeScript

/**
* Policy Type Badge Configuration
* Maps Intune policy types to Shadcn Badge variants and colors
*/
export type PolicyBadgeVariant = 'default' | 'secondary' | 'destructive' | 'outline';
interface PolicyBadgeConfig {
variant: PolicyBadgeVariant;
label: string;
}
/**
* Maps policy type to badge configuration
* Based on Microsoft Intune policy categories
*/
export function getPolicyBadgeConfig(policyType: string): PolicyBadgeConfig {
const type = policyType.toLowerCase();
// Security & Protection
if (type.includes('security') || type.includes('defender') || type.includes('threat')) {
return { variant: 'destructive', label: formatPolicyType(policyType) };
}
// Compliance & Conditional Access
if (type.includes('compliance') || type.includes('conditional')) {
return { variant: 'default', label: formatPolicyType(policyType) };
}
// Configuration Profiles
if (type.includes('configuration') || type.includes('profile') || type.includes('settings')) {
return { variant: 'secondary', label: formatPolicyType(policyType) };
}
// App Management
if (type.includes('app') || type.includes('application')) {
return { variant: 'outline', label: formatPolicyType(policyType) };
}
// Default for unknown types
return { variant: 'secondary', label: formatPolicyType(policyType) };
}
/**
* Formats policy type string for display
* Converts camelCase/PascalCase to readable format
*/
function formatPolicyType(policyType: string): string {
return policyType
.replace(/([A-Z])/g, ' $1') // Add space before capital letters
.trim()
.replace(/\s+/g, ' ') // Collapse multiple spaces
.split(' ')
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join(' ');
}