|
| 1 | +import * as React from 'react' |
| 2 | +import { |
| 3 | + TopBarFilter, |
| 4 | + FilterChip, |
| 5 | + AddFilterButton, |
| 6 | + FilterDropdownSection, |
| 7 | +} from '~/components/FilterComponents' |
| 8 | + |
| 9 | +const ACTION_LABELS: Record<string, string> = { |
| 10 | + 'user.capabilities.update': 'Updated Capabilities', |
| 11 | + 'user.adsDisabled.update': 'Updated Ads Status', |
| 12 | + 'user.sessions.revoke': 'Revoked Sessions', |
| 13 | + 'role.create': 'Created Role', |
| 14 | + 'role.update': 'Updated Role', |
| 15 | + 'role.delete': 'Deleted Role', |
| 16 | + 'role.assignment.create': 'Assigned Role', |
| 17 | + 'role.assignment.delete': 'Removed Role', |
| 18 | + 'banner.create': 'Created Banner', |
| 19 | + 'banner.update': 'Updated Banner', |
| 20 | + 'banner.delete': 'Deleted Banner', |
| 21 | + 'feed.entry.create': 'Created Feed Entry', |
| 22 | + 'feed.entry.update': 'Updated Feed Entry', |
| 23 | + 'feed.entry.delete': 'Deleted Feed Entry', |
| 24 | + 'feedback.moderate': 'Moderated Feedback', |
| 25 | +} |
| 26 | + |
| 27 | +const TARGET_TYPES = [ |
| 28 | + { value: 'user', label: 'User' }, |
| 29 | + { value: 'role', label: 'Role' }, |
| 30 | + { value: 'banner', label: 'Banner' }, |
| 31 | + { value: 'feed_entry', label: 'Feed Entry' }, |
| 32 | + { value: 'feedback', label: 'Feedback' }, |
| 33 | +] |
| 34 | + |
| 35 | +interface AuditFilters { |
| 36 | + actorId?: string |
| 37 | + action?: string |
| 38 | + targetType?: string |
| 39 | +} |
| 40 | + |
| 41 | +interface AuditTopBarFiltersProps { |
| 42 | + filters: AuditFilters |
| 43 | + onFilterChange: (filters: Partial<AuditFilters>) => void |
| 44 | + onClearFilters: () => void |
| 45 | +} |
| 46 | + |
| 47 | +export function AuditTopBarFilters({ |
| 48 | + filters, |
| 49 | + onFilterChange, |
| 50 | + onClearFilters, |
| 51 | +}: AuditTopBarFiltersProps) { |
| 52 | + const hasActiveFilters = Boolean( |
| 53 | + filters.actorId || filters.action || filters.targetType, |
| 54 | + ) |
| 55 | + |
| 56 | + return ( |
| 57 | + <TopBarFilter |
| 58 | + search={{ |
| 59 | + value: filters.actorId || '', |
| 60 | + onChange: (value) => onFilterChange({ actorId: value || undefined }), |
| 61 | + placeholder: 'Search by actor ID...', |
| 62 | + }} |
| 63 | + onClearAll={onClearFilters} |
| 64 | + hasActiveFilters={hasActiveFilters} |
| 65 | + > |
| 66 | + {/* Active Filter Chips */} |
| 67 | + {filters.action && ( |
| 68 | + <FilterChip |
| 69 | + label={`Action: ${ACTION_LABELS[filters.action] || filters.action}`} |
| 70 | + onRemove={() => onFilterChange({ action: undefined })} |
| 71 | + /> |
| 72 | + )} |
| 73 | + {filters.targetType && ( |
| 74 | + <FilterChip |
| 75 | + label={`Target: ${TARGET_TYPES.find((t) => t.value === filters.targetType)?.label || filters.targetType}`} |
| 76 | + onRemove={() => onFilterChange({ targetType: undefined })} |
| 77 | + /> |
| 78 | + )} |
| 79 | + |
| 80 | + {/* Add Filter Dropdown */} |
| 81 | + <AddFilterButton> |
| 82 | + {/* Action Filter */} |
| 83 | + <FilterDropdownSection title="Action" defaultExpanded> |
| 84 | + <select |
| 85 | + value={filters.action || ''} |
| 86 | + onChange={(e) => |
| 87 | + onFilterChange({ action: e.target.value || undefined }) |
| 88 | + } |
| 89 | + className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-blue-500" |
| 90 | + > |
| 91 | + <option value="">All actions</option> |
| 92 | + {Object.entries(ACTION_LABELS).map(([value, label]) => ( |
| 93 | + <option key={value} value={value}> |
| 94 | + {label} |
| 95 | + </option> |
| 96 | + ))} |
| 97 | + </select> |
| 98 | + </FilterDropdownSection> |
| 99 | + |
| 100 | + {/* Target Type Filter */} |
| 101 | + <FilterDropdownSection title="Target Type" defaultExpanded> |
| 102 | + <select |
| 103 | + value={filters.targetType || ''} |
| 104 | + onChange={(e) => |
| 105 | + onFilterChange({ targetType: e.target.value || undefined }) |
| 106 | + } |
| 107 | + className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-blue-500" |
| 108 | + > |
| 109 | + <option value="">All types</option> |
| 110 | + {TARGET_TYPES.map(({ value, label }) => ( |
| 111 | + <option key={value} value={value}> |
| 112 | + {label} |
| 113 | + </option> |
| 114 | + ))} |
| 115 | + </select> |
| 116 | + </FilterDropdownSection> |
| 117 | + </AddFilterButton> |
| 118 | + </TopBarFilter> |
| 119 | + ) |
| 120 | +} |
0 commit comments