7.3 KiB
Enforcements Page Implementation
Date: 2026-02-05
Status: Complete
Overview
Added a comprehensive Enforcements page to the web UI to provide visibility into rule activations and enforcement tracking. The implementation follows the same patterns used in the Events and Executions pages for consistency.
Changes Made
New Files Created
-
attune/web/src/pages/enforcements/EnforcementsPage.tsx- List view for all enforcements with pagination
- Real-time updates via WebSocket
- Multi-filter support (rule, trigger, event ID, status)
- Client-side filtering for rule reference (since API only supports rule ID filtering)
- URL query parameter support for deep linking from other pages
- Responsive table layout with enforcement details
-
attune/web/src/pages/enforcements/EnforcementDetailPage.tsx- Detailed view of individual enforcements
- Display of rule, trigger, and event relationships
- Condition type and status badges with color coding
- Expandable sections for conditions, configuration, and payload
- Quick links to related entities (rule, event, trigger, executions)
- Informational sections explaining enforcement status and condition types
Modified Files
-
attune/web/src/App.tsx- Added routes for
/enforcements(list page) - Added routes for
/enforcements/:id(detail page) - Imported the new enforcement page components
- Added routes for
-
attune/web/src/components/layout/MainLayout.tsx- Added "Enforcements" navigation item to sidebar
- Positioned between "Event History" and "Sensor List"
- Uses
CheckCircleicon from lucide-react
Features Implemented
List Page (/enforcements)
-
Filtering:
- Rule reference (client-side text matching)
- Event ID (API-level filtering)
- Trigger reference (API-level filtering)
- Status (created, processed, disabled)
-
Display Columns:
- Enforcement ID
- Rule (with link to rule detail page)
- Trigger reference
- Associated event ID (with link)
- Condition type badge (all/any)
- Status badge (color-coded)
- Creation timestamp (relative and absolute)
- Actions (View Details link)
-
Real-time Updates:
- WebSocket integration for live enforcement creation
- Live update indicator in header
- Auto-refresh on new enforcements
-
Pagination:
- 20 items per page
- Previous/Next navigation
- Page indicator
-
URL Query Parameters:
- Support for
?event=123from Event detail page - Support for
?rule=456from Rule detail page - Support for
?trigger_ref=core.webhook - Support for
?status=processed
- Support for
Detail Page (/enforcements/:id)
-
Overview Section:
- Rule (with link if available)
- Trigger reference
- Associated event (with link if available)
- Status and condition type badges
- Creation timestamp
-
Data Sections:
- Rule Conditions: JSON display of evaluation criteria
- Configuration: JSON display of enforcement config (if present)
- Payload: JSON display of enforcement payload data
-
Quick Links:
- View Rule
- View Event
- View Trigger
- View Related Executions
- View Similar Enforcements
-
Metadata:
- Enforcement ID
- Rule ID and reference
- Event ID
- Trigger reference
- Creation timestamp
-
Informational Cards:
- Explanation of enforcement concept
- Condition type details (all vs any)
- Status meaning (created, processed, disabled)
Technical Details
Status Color Coding
- Processed: Green (bg-green-100, text-green-800)
- Created: Blue (bg-blue-100, text-blue-800)
- Disabled: Gray (bg-gray-100, text-gray-800)
Condition Type Color Coding
- All: Purple (bg-purple-100, text-purple-800)
- Any: Indigo (bg-indigo-100, text-indigo-800)
API Integration
Uses existing hooks from @/hooks/useEvents:
useEnforcements(params)- List enforcements with filtersuseEnforcement(id)- Get single enforcement by ID
Supports filtering via:
event: Filter by event ID (i64)status: Filter by status enumtriggerRef: Filter by trigger reference stringrule: Filter by rule ID (i64) - not currently used in UI
WebSocket Integration
Subscribes to enforcement entity notifications for real-time updates:
- Invalidates enforcement queries on new enforcement creation
- Shows connection status indicator
- Stable callback to prevent unnecessary re-renders
Design Patterns Followed
-
Consistency with Existing Pages:
- Same layout structure as Events and Executions pages
- Similar filter UI patterns
- Consistent table styling and pagination
- Matching detail page layout with 3-column grid
-
Error Handling:
- Loading states with spinner
- Error states with user-friendly messages
- Empty states with helpful text
- Graceful handling of missing data
-
Performance:
- Stable callbacks for WebSocket handlers
- Memoization considerations from ExecutionsPage
- Efficient filter state management
- URL query parameter initialization in useEffect
-
Accessibility:
- Semantic HTML structure
- Proper label associations
- Keyboard navigation support
- Screen reader friendly
Integration Points
From Other Pages
The following pages can now link to enforcements:
- Event Detail Page - "→ View Enforcements" link with
?event={id}filter - Rule Pages - Can link with
?rule={id}filter - Execution Detail Page - Shows enforcement ID, could link to detail page
To Other Pages
Enforcements page links to:
- Rule detail pages (
/rules/{rule}) - Event detail pages (
/events/{event}) - Trigger pages (
/triggers/{trigger_ref}) - Execution list with enforcement filter
Build Status
✅ TypeScript compilation successful
✅ Vite build successful (561.82 kB gzip: 148.63 kB)
✅ No compiler warnings or errors
✅ All routes registered correctly
Future Enhancements
Potential improvements for future iterations:
-
Server-side Rule Reference Filtering:
- Add
rule_refparameter to API endpoint - Remove client-side filtering limitation with pagination
- Add
-
Bulk Operations:
- Select multiple enforcements
- Batch status updates
- Export functionality
-
Advanced Filtering:
- Date range filtering
- Combined filter logic (AND/OR)
- Save filter presets
-
Visualizations:
- Enforcement timeline
- Success/failure rate charts
- Rule activation frequency
-
Direct Actions:
- Re-trigger enforcement
- Disable/enable enforcement
- Copy enforcement configuration
Testing Recommendations
Manual testing should verify:
- ✅ List page loads and displays enforcements
- ✅ All filters work correctly (rule, trigger, event, status)
- ✅ Pagination functions properly
- ✅ Detail page displays all enforcement data
- ✅ Links navigate to correct pages
- ✅ WebSocket live updates work
- ✅ URL query parameters initialize filters
- ✅ Clear filters resets all state
- ✅ Empty states display correctly
- ✅ Error states handle failures gracefully
Notes
- Client-side rule reference filtering is a workaround since the API only supports filtering by rule ID (integer) not rule_ref (string)
- This may cause inconsistencies with pagination when rule filter is active
- Consider adding
rule_refparameter to the API endpoint in future - WebSocket notifications use the
enforcemententity type (ensure backend sends these)