()
| 36 | import { toast } from 'sonner'; |
| 37 | |
| 38 | export function ModelStatsTable() { |
| 39 | const router = useRouter(); |
| 40 | const searchParams = useSearchParams(); |
| 41 | const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false); |
| 42 | const [editingField, setEditingField] = useState<{ |
| 43 | id: string; |
| 44 | field: 'aaSlug' | 'isActive' | 'isFeatured' | 'isStealth'; |
| 45 | } | null>(null); |
| 46 | const [editValue, setEditValue] = useState(''); |
| 47 | const [updatingModelId, setUpdatingModelId] = useState<string | null>(null); |
| 48 | |
| 49 | const currentPage = parseInt(searchParams.get('page') || '1'); |
| 50 | const currentPageSize = parseInt(searchParams.get('limit') || '25'); |
| 51 | const currentSearch = searchParams.get('search') || ''; |
| 52 | const currentIsActive = (searchParams.get('isActive') || '') as '' | 'true' | 'false'; |
| 53 | |
| 54 | const { data, isLoading } = useModelStatsList({ |
| 55 | page: currentPage, |
| 56 | limit: currentPageSize, |
| 57 | sortBy: 'name', |
| 58 | sortOrder: 'asc', |
| 59 | search: currentSearch, |
| 60 | isActive: currentIsActive, |
| 61 | }); |
| 62 | |
| 63 | const updateModel = useUpdateModel(); |
| 64 | const createModel = useCreateModel(); |
| 65 | const triggerStatsUpdate = useTriggerStatsUpdate(); |
| 66 | const bustCache = useBustModelStatsCache(); |
| 67 | |
| 68 | const updateUrl = useCallback( |
| 69 | (params: Record<string, string>) => { |
| 70 | const newSearchParams = new URLSearchParams(searchParams.toString()); |
| 71 | Object.entries(params).forEach(([key, value]) => { |
| 72 | if (value) { |
| 73 | newSearchParams.set(key, value); |
| 74 | } else { |
| 75 | newSearchParams.delete(key); |
| 76 | } |
| 77 | }); |
| 78 | router.push(`/admin/model-stats?${newSearchParams.toString()}`); |
| 79 | }, |
| 80 | [router, searchParams] |
| 81 | ); |
| 82 | |
| 83 | const handleSearchChange = useCallback( |
| 84 | (searchTerm: string) => { |
| 85 | updateUrl({ |
| 86 | search: searchTerm, |
| 87 | page: '1', |
| 88 | limit: currentPageSize.toString(), |
| 89 | }); |
| 90 | }, |
| 91 | [currentPageSize, updateUrl] |
| 92 | ); |
| 93 | |
| 94 | const handlePageChange = useCallback( |
| 95 | (page: number) => { |
nothing calls this directly
no test coverage detected