1
1
import clsx from 'clsx' ;
2
- import React , { useState } from 'react' ;
2
+ import React from 'react' ;
3
3
import { ColumnListModel , LabelModel } from '../../api' ;
4
4
import { CheckTypes } from '../../shared/routes' ;
5
5
import { useDecodedParams } from '../../utils' ;
6
6
import SectionWrapper from '../Dashboard/SectionWrapper' ;
7
7
import { Pagination } from '../Pagination' ;
8
- import SvgIcon from '../SvgIcon' ;
9
- import ColumnListItem from './ColumnListItem' ;
10
- function getValueForKey < T > ( obj : T , key : string ) : string | undefined {
11
- const keys = key . split ( '.' ) ;
12
- let value : any = obj ;
13
-
14
- for ( const k of keys ) {
15
- value = value ?. [ k ] ;
16
- if ( value === undefined ) {
17
- break ;
18
- }
19
- }
20
8
21
- return value ?. toString ( ) ;
22
- }
9
+ import Loader from '../Loader' ;
10
+ import ColumnListItem from './ColumnListItem' ;
11
+ import renderItem from './renderItem' ;
23
12
24
13
type TButtonTabs = {
25
14
label : string ;
@@ -51,27 +40,27 @@ const headeritems: TButtonTabs[] = [
51
40
label : 'Labels' ,
52
41
value : 'labels'
53
42
} ,
54
- { label : 'Data Quality KPI' , value : 'data-quality-kpi' , sortable : false }
43
+ { label : 'Data Quality KPI' , value : 'data-quality-kpi' }
55
44
] ;
56
45
57
46
type TColumnListProps = {
58
47
columns : TColumnWithSchema [ ] ;
59
- setColumns : any ;
60
48
filters : any ;
61
49
onChangeFilters : ( filters : any ) => void ;
62
50
labels : TLabel [ ] ;
63
51
onChangeLabels : ( index : number ) => void ;
52
+ loading : boolean ;
64
53
} ;
65
54
66
55
type TLabel = LabelModel & { clicked : boolean } ;
67
56
68
57
function ColumnList ( {
69
58
columns,
70
- setColumns,
71
59
filters,
72
60
onChangeFilters,
73
61
labels,
74
- onChangeLabels
62
+ onChangeLabels,
63
+ loading
75
64
} : TColumnListProps ) {
76
65
const {
77
66
checkTypes,
@@ -82,48 +71,6 @@ function ColumnList({
82
71
connection : string ;
83
72
schema : string ;
84
73
} = useDecodedParams ( ) ;
85
- const [ sortingDir , setSortingDir ] = useState < 'asc' | 'desc' > ( 'asc' ) ;
86
-
87
- const renderItem = (
88
- label : string ,
89
- key : string ,
90
- sortable ?: boolean ,
91
- toRotate ?: boolean
92
- ) => {
93
- const sortTables = ( key : string ) : void => {
94
- setColumns ( ( prev : any ) => {
95
- const array = [ ...prev ] ;
96
- array . sort ( ( a , b ) => {
97
- const valueA = getValueForKey ( a , key ) ;
98
- const valueB = getValueForKey ( b , key ) ;
99
-
100
- return sortingDir === 'asc'
101
- ? ( valueA || '' ) . localeCompare ( valueB || '' )
102
- : ( valueB || '' ) . localeCompare ( valueA || '' ) ;
103
- } ) ;
104
-
105
- setSortingDir ( ( prev ) => ( prev === 'asc' ? 'desc' : 'asc' ) ) ;
106
- return array ;
107
- } ) ;
108
- } ;
109
- return (
110
- < th
111
- className = "px-4 cursor-pointer"
112
- onClick = { ( ) => sortable !== false && sortTables ( key ) }
113
- key = { key }
114
- >
115
- < div className = "flex text-sm items-center relative" >
116
- < span className = { clsx ( toRotate ? ' z-9' : '' ) } > { label } </ span >
117
- { sortable !== false && (
118
- < div className = "flex flex-col items-center" >
119
- < SvgIcon name = "chevron-up" className = "w-3 h-2" />
120
- < SvgIcon name = "chevron-down" className = "w-3 h-2" />
121
- </ div >
122
- ) }
123
- </ div >
124
- </ th >
125
- ) ;
126
- } ;
127
74
128
75
const getDimensionKey = ( ) => {
129
76
const uniqueDimensions : string [ ] = [ ] ;
@@ -158,20 +105,17 @@ function ColumnList({
158
105
...basicDimensionTypes . map ( ( x ) => ( {
159
106
label : x ,
160
107
value : x ,
161
- sortable : false ,
162
108
toRotate : true
163
109
} ) ) ,
164
110
165
111
...getDimensionKey ( ) . map ( ( x ) => ( {
166
112
label : x ,
167
113
value : x ,
168
- sortable : false ,
169
114
toRotate : true
170
115
} ) ) ,
171
116
{
172
117
label : 'Actions' ,
173
- value : 'actions' ,
174
- sortable : false
118
+ value : 'actions'
175
119
}
176
120
] ;
177
121
@@ -191,7 +135,7 @@ function ColumnList({
191
135
< div className = "w-[280px]" >
192
136
< SectionWrapper
193
137
title = "Filter by labels"
194
- className = "text-sm w-[250px] mx-4 mb-4 mt-6 "
138
+ className = "text-xs w-[250px] mx-4 mb-4 mt-6 "
195
139
>
196
140
{ labels . map ( ( label , index ) => (
197
141
< div
@@ -212,48 +156,52 @@ function ColumnList({
212
156
</ div >
213
157
214
158
< div className = "overflow-x-auto" >
215
- < table >
159
+ < table className = "absolute top-25" >
216
160
< thead >
217
161
< tr className = "mb-2" >
218
162
{ headerItems . map (
219
163
( item ) =>
220
164
item ?. label &&
221
165
item . value &&
222
- renderItem (
223
- item . label ,
224
- item . value ,
225
- item . sortable ,
226
- item . toRotate
227
- )
166
+ renderItem ( item . label , item . value , item . toRotate )
228
167
) }
229
168
</ tr >
230
169
</ thead >
231
- < tbody >
232
- { columns . map ( ( item , index ) => (
233
- < ColumnListItem
234
- key = { index }
235
- item = { item }
236
- dimensionKeys = { getDimensionKey ( ) }
170
+ { loading ? (
171
+ < div className = "ml-5 flex items-start justify-normal" >
172
+ < Loader
173
+ isFull = { false }
174
+ className = "w-8 h-8 fill-green-700 mt-5"
237
175
/>
238
- ) ) }
239
- </ tbody >
176
+ </ div >
177
+ ) : (
178
+ < tbody >
179
+ { columns . map ( ( item , index ) => (
180
+ < ColumnListItem
181
+ key = { index }
182
+ item = { item }
183
+ dimensionKeys = { getDimensionKey ( ) }
184
+ />
185
+ ) ) }
186
+ </ tbody >
187
+ ) }
188
+ < div className = "px-4 my-5 pb-6 flex justify-end" >
189
+ < Pagination
190
+ page = { filters . page || 1 }
191
+ pageSize = { filters . pageSize || 50 }
192
+ isEnd = { isEnd }
193
+ totalPages = { 10 }
194
+ onChange = { ( page , pageSize ) =>
195
+ onChangeFilters ( {
196
+ page,
197
+ pageSize
198
+ } )
199
+ }
200
+ />
201
+ </ div >
240
202
</ table >
241
203
</ div >
242
204
</ div >
243
- < div className = "px-4 my-5" >
244
- < Pagination
245
- page = { filters . page || 1 }
246
- pageSize = { filters . pageSize || 50 }
247
- isEnd = { isEnd }
248
- totalPages = { 10 }
249
- onChange = { ( page , pageSize ) =>
250
- onChangeFilters ( {
251
- page,
252
- pageSize
253
- } )
254
- }
255
- />
256
- </ div >
257
205
</ div >
258
206
) ;
259
207
}
0 commit comments