File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed
catalog/app/containers/Search/Table Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -2,16 +2,29 @@ import * as React from 'react'
2
2
import * as M from '@material-ui/core'
3
3
import * as Lab from '@material-ui/lab'
4
4
5
+ interface SkeletonColumn {
6
+ key : React . Key
7
+ width : number
8
+ }
9
+
10
+ interface SkeletonRow {
11
+ key : React . Key
12
+ columns : SkeletonColumn [ ]
13
+ }
14
+
5
15
const randomColumnWidth = ( min : number = 80 , max : number = 200 ) =>
6
16
min + Math . floor ( Math . random ( ) * ( max - min + 1 ) )
7
17
8
- const createColumns = ( columnsLen : number ) =>
18
+ const createColumns = ( columnsLen : number ) : SkeletonColumn [ ] =>
9
19
Array . from ( { length : columnsLen } ) . map ( ( _c , key ) => ( {
10
20
key,
11
21
width : randomColumnWidth ( ) ,
12
22
} ) )
13
23
14
- export const useColumns = ( rowsLen : number = 30 , columnsLen : number = 5 ) =>
24
+ export const useSkeletonSizes = (
25
+ rowsLen : number = 30 ,
26
+ columnsLen : number = 5 ,
27
+ ) : SkeletonRow [ ] =>
15
28
React . useMemo (
16
29
( ) =>
17
30
Array . from ( { length : rowsLen } ) . map ( ( _r , key ) => ( {
@@ -40,7 +53,7 @@ interface TableProps {
40
53
}
41
54
42
55
export function Table ( { className } : TableProps ) {
43
- const rows = useColumns ( )
56
+ const rows = useSkeletonSizes ( )
44
57
if ( ! rows . length ) return null
45
58
const [ head , ...body ] = rows
46
59
return (
Original file line number Diff line number Diff line change @@ -1124,7 +1124,7 @@ const useLayoutStyles = M.makeStyles((t) => ({
1124
1124
interface LayoutProps {
1125
1125
hits : readonly Hit [ ]
1126
1126
columns : ColumnsMap
1127
- skeletons : ReturnType < typeof Skeleton . useColumns >
1127
+ skeletons : ReturnType < typeof Skeleton . useSkeletonSizes >
1128
1128
}
1129
1129
1130
1130
function Layout ( { hits, columns, skeletons } : LayoutProps ) {
@@ -1198,7 +1198,7 @@ interface TableViewProps {
1198
1198
function TableView ( { hits, bucket, metaFiltersState } : TableViewProps ) {
1199
1199
const { hiddenColumns } = useContext ( )
1200
1200
const [ columns , notReady ] = useColumns ( hiddenColumns , metaFiltersState , bucket )
1201
- const skeletons = Skeleton . useColumns (
1201
+ const skeletons = Skeleton . useSkeletonSizes (
1202
1202
notReady === Workflow . Loading ? hits . length + 1 : 0 ,
1203
1203
3 ,
1204
1204
)
You can’t perform that action at this time.
0 commit comments