Delete assets/js/dashboard/stats/modals/breakdown-table.tsx with huggingface_hub
Browse files
assets/js/dashboard/stats/modals/breakdown-table.tsx
DELETED
|
@@ -1,139 +0,0 @@
|
|
| 1 |
-
import React, { ReactNode, useRef } from 'react'
|
| 2 |
-
import { XMarkIcon } from '@heroicons/react/20/solid'
|
| 3 |
-
|
| 4 |
-
import { SearchInput } from '../../components/search-input'
|
| 5 |
-
import { Table } from '../../components/table'
|
| 6 |
-
import { ColumnConfiguration } from '../breakdowns'
|
| 7 |
-
import RocketIcon from './rocket-icon'
|
| 8 |
-
import { QueryStatus } from '@tanstack/react-query'
|
| 9 |
-
import { useAppNavigate } from '../../navigation/use-app-navigate'
|
| 10 |
-
import { rootRoute } from '../../router'
|
| 11 |
-
|
| 12 |
-
export function BreakdownTable<T>({
|
| 13 |
-
title,
|
| 14 |
-
isPending,
|
| 15 |
-
isFetching,
|
| 16 |
-
onSearch,
|
| 17 |
-
hasNextPage,
|
| 18 |
-
isFetchingNextPage,
|
| 19 |
-
fetchNextPage,
|
| 20 |
-
columns,
|
| 21 |
-
data,
|
| 22 |
-
status,
|
| 23 |
-
error,
|
| 24 |
-
displayError = true,
|
| 25 |
-
onClose,
|
| 26 |
-
getRowKey
|
| 27 |
-
}: {
|
| 28 |
-
title: ReactNode
|
| 29 |
-
onSearch?: (input: string) => void
|
| 30 |
-
isPending: boolean
|
| 31 |
-
isFetching: boolean
|
| 32 |
-
hasNextPage: boolean
|
| 33 |
-
isFetchingNextPage: boolean
|
| 34 |
-
fetchNextPage: () => void
|
| 35 |
-
columns: ColumnConfiguration<T>[] | null
|
| 36 |
-
data?: { pages: T[][] }
|
| 37 |
-
status?: QueryStatus
|
| 38 |
-
error?: Error | null
|
| 39 |
-
/** Controls whether the component displays API request errors or ignores them. */
|
| 40 |
-
displayError?: boolean
|
| 41 |
-
onClose?: () => void
|
| 42 |
-
getRowKey: (row: T) => string
|
| 43 |
-
}) {
|
| 44 |
-
const searchRef = useRef<HTMLInputElement>(null)
|
| 45 |
-
const navigate = useAppNavigate()
|
| 46 |
-
const handleClose =
|
| 47 |
-
onClose ?? (() => navigate({ path: rootRoute.path, search: (s) => s }))
|
| 48 |
-
|
| 49 |
-
return (
|
| 50 |
-
<div className="min-h-[min(30rem,66vh)] flex flex-col flex-1 overflow-auto">
|
| 51 |
-
<div className="flex justify-between items-center gap-4">
|
| 52 |
-
<div className="flex items-center gap-4 w-full">
|
| 53 |
-
<h1 className="shrink-0 mb-0.5 text-base md:text-lg font-bold dark:text-gray-100">
|
| 54 |
-
{title}
|
| 55 |
-
</h1>
|
| 56 |
-
{typeof onSearch === 'function' && (
|
| 57 |
-
<SearchInput
|
| 58 |
-
searchRef={searchRef}
|
| 59 |
-
onSearch={onSearch}
|
| 60 |
-
className={
|
| 61 |
-
displayError && status === 'error'
|
| 62 |
-
? '[&_input]:pointer-events-none'
|
| 63 |
-
: ''
|
| 64 |
-
}
|
| 65 |
-
/>
|
| 66 |
-
)}
|
| 67 |
-
{!isPending && isFetching && <SmallLoadingSpinner />}
|
| 68 |
-
</div>
|
| 69 |
-
<button
|
| 70 |
-
type="button"
|
| 71 |
-
onClick={handleClose}
|
| 72 |
-
aria-label="Close modal"
|
| 73 |
-
className="text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300"
|
| 74 |
-
>
|
| 75 |
-
<XMarkIcon className="size-5" />
|
| 76 |
-
</button>
|
| 77 |
-
</div>
|
| 78 |
-
<div className="my-3 md:my-4 border-b border-gray-250 dark:border-gray-750"></div>
|
| 79 |
-
<div className="flex-1 overflow-auto">
|
| 80 |
-
{displayError && status === 'error' && <ErrorMessage error={error} />}
|
| 81 |
-
{isPending && <InitialLoadingSpinner />}
|
| 82 |
-
{columns && data && (
|
| 83 |
-
<Table data={data} columns={columns} getRowKey={getRowKey} />
|
| 84 |
-
)}
|
| 85 |
-
{!isPending && !isFetching && hasNextPage && (
|
| 86 |
-
<LoadMore
|
| 87 |
-
onClick={() => fetchNextPage()}
|
| 88 |
-
isFetchingNextPage={isFetchingNextPage}
|
| 89 |
-
/>
|
| 90 |
-
)}
|
| 91 |
-
</div>
|
| 92 |
-
</div>
|
| 93 |
-
)
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
const InitialLoadingSpinner = () => (
|
| 97 |
-
<div className="w-full h-full flex flex-col justify-center">
|
| 98 |
-
<div className="mx-auto loading">
|
| 99 |
-
<div />
|
| 100 |
-
</div>
|
| 101 |
-
</div>
|
| 102 |
-
)
|
| 103 |
-
|
| 104 |
-
const SmallLoadingSpinner = () => (
|
| 105 |
-
<div data-testid="small-loading-spinner" className="loading sm">
|
| 106 |
-
<div />
|
| 107 |
-
</div>
|
| 108 |
-
)
|
| 109 |
-
|
| 110 |
-
const ErrorMessage = ({ error }: { error?: unknown }) => (
|
| 111 |
-
<div className="grid grid-rows-2 text-gray-700 dark:text-gray-300">
|
| 112 |
-
<div className="text-center self-end">
|
| 113 |
-
<RocketIcon />
|
| 114 |
-
</div>
|
| 115 |
-
<div className="text-lg text-center">
|
| 116 |
-
{error
|
| 117 |
-
? (error as { message: string }).message
|
| 118 |
-
: 'Error loading data. Refresh the page to try again'}
|
| 119 |
-
</div>
|
| 120 |
-
</div>
|
| 121 |
-
)
|
| 122 |
-
|
| 123 |
-
const LoadMore = ({
|
| 124 |
-
onClick,
|
| 125 |
-
isFetchingNextPage
|
| 126 |
-
}: {
|
| 127 |
-
onClick: () => void
|
| 128 |
-
isFetchingNextPage: boolean
|
| 129 |
-
}) => (
|
| 130 |
-
<div className="flex flex-col w-full my-4 items-center justify-center h-10">
|
| 131 |
-
{isFetchingNextPage ? (
|
| 132 |
-
<SmallLoadingSpinner />
|
| 133 |
-
) : (
|
| 134 |
-
<button onClick={onClick} type="button" className="button">
|
| 135 |
-
Load more
|
| 136 |
-
</button>
|
| 137 |
-
)}
|
| 138 |
-
</div>
|
| 139 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|