tenantpilot/lib/types/policy-table.ts
Ahmed Darrazi 41e80b6c0c
All checks were successful
Trigger Cloudarix Deploy / call-webhook (push) Successful in 2s
feat(policy-explorer-v2): implement MVP Phase 1-3
 New Features
- Advanced data table with TanStack Table v8 + Server Actions
- Server-side pagination (10/25/50/100 rows per page)
- Multi-column sorting with visual indicators
- Column management (show/hide, resize) persisted to localStorage
- URL state synchronization for shareable filtered views
- Sticky header with compact/comfortable density modes

📦 Components Added
- PolicyTableV2.tsx - Main table with TanStack integration
- PolicyTableColumns.tsx - 7 column definitions with sorting
- PolicyTablePagination.tsx - Pagination controls
- PolicyTableToolbar.tsx - Density toggle + column visibility menu
- ColumnVisibilityMenu.tsx - Show/hide columns dropdown

🔧 Hooks Added
- usePolicyTable.ts - TanStack Table initialization
- useURLState.ts - URL query param sync with nuqs
- useTablePreferences.ts - localStorage persistence

🎨 Server Actions Updated
- getPolicySettingsV2 - Pagination + sorting + filtering + Zod validation
- exportPolicySettingsCSV - Server-side CSV generation (max 5000 rows)

📚 Documentation Added
- Intune Migration Guide (1400+ lines) - Reverse engineering strategy
- Intune Reference Version tracking
- Tasks completed: 22/62 (Phase 1-3)

 Zero TypeScript compilation errors
 All MVP success criteria met (pagination, sorting, column management)
 Ready for Phase 4-7 (filtering, export, detail view, polish)

Refs: specs/004-policy-explorer-v2/tasks.md
2025-12-10 00:18:05 +01:00

138 lines
4.1 KiB
TypeScript

/**
* Policy Explorer V2 - Type Definitions
*
* This file defines TypeScript interfaces for the advanced data table feature.
* These types manage client-side table state, URL state synchronization, and localStorage persistence.
*/
import type { SortingState, VisibilityState, ColumnSizingState } from '@tanstack/react-table';
/**
* DataTableState - Client-side ephemeral state for TanStack Table
*
* Manages pagination, sorting, column visibility/sizing, row selection, and density mode.
* This state is NOT persisted - it's derived from URL params and localStorage preferences.
*/
export interface DataTableState {
pagination: {
pageIndex: number; // 0-based page index
pageSize: 10 | 25 | 50 | 100;
};
sorting: SortingState; // TanStack Table sorting state: Array<{ id: string; desc: boolean }>
columnVisibility: VisibilityState; // TanStack Table visibility state: { [columnId: string]: boolean }
columnSizing: ColumnSizingState; // TanStack Table sizing state: { [columnId: string]: number }
rowSelection: {
[rowId: string]: boolean; // Selected row IDs for CSV export
};
density: 'compact' | 'comfortable'; // Row height mode
}
/**
* FilterState - Synced with URL and stored in localStorage
*
* Manages user-applied filters for policy types and search query.
* These are persisted in URL query params for shareable links.
*/
export interface FilterState {
policyTypes: string[]; // ['deviceConfiguration', 'compliancePolicy']
searchQuery: string; // Text search in settingName/policyName
}
/**
* TablePreferences - Persisted in localStorage
*
* Stores user-specific table preferences across sessions.
* Includes a version field for schema migrations when adding new features.
*/
export interface TablePreferences {
version: 1; // Schema version for migrations
columnVisibility: { [columnId: string]: boolean };
columnSizing: { [columnId: string]: number };
columnOrder: string[]; // Ordered column IDs for reordering
density: 'compact' | 'comfortable';
defaultPageSize: 10 | 25 | 50 | 100;
}
/**
* PolicySettingRow - Row data shape for the table
*
* Extends the base PolicySetting type with computed fields for display.
*/
export interface PolicySettingRow {
id: string;
tenantId: string;
policyName: string;
policyType: string;
settingName: string;
settingValue: string;
graphPolicyId: string;
lastSyncedAt: Date;
createdAt: Date;
}
/**
* PaginationMeta - Server response metadata
*
* Returned by Server Actions to provide pagination state to the client.
*/
export interface PaginationMeta {
totalCount: number;
pageCount: number;
currentPage: number;
pageSize: number;
hasNextPage: boolean;
hasPreviousPage: boolean;
}
/**
* GetPolicySettingsParams - Server Action input
*
* Parameters for fetching policy settings with pagination, sorting, and filtering.
*/
export interface GetPolicySettingsParams {
page: number; // 0-based page index
pageSize: 10 | 25 | 50 | 100;
sortBy?: 'settingName' | 'policyName' | 'policyType' | 'lastSyncedAt';
sortDir?: 'asc' | 'desc';
policyTypes?: string[];
searchQuery?: string;
}
/**
* GetPolicySettingsResult - Server Action output
*
* Response from Server Action with data and pagination metadata.
*/
export interface GetPolicySettingsResult {
success: boolean;
data?: PolicySettingRow[];
meta?: PaginationMeta;
error?: string;
}
/**
* ExportPolicySettingsParams - Server Action input for CSV export
*
* Parameters for server-side CSV generation (max 5000 rows).
*/
export interface ExportPolicySettingsParams {
policyTypes?: string[];
searchQuery?: string;
sortBy?: 'settingName' | 'policyName' | 'policyType' | 'lastSyncedAt';
sortDir?: 'asc' | 'desc';
maxRows?: number; // Default: 5000
}
/**
* ExportPolicySettingsResult - Server Action output for CSV export
*
* Returns CSV content as string with suggested filename.
*/
export interface ExportPolicySettingsResult {
success: boolean;
csv?: string;
filename?: string;
rowCount?: number;
error?: string;
}