@@ -3,71 +3,82 @@ import React from 'react';
3
3
import { AccessDenied } from '../../components/Errors/403' ;
4
4
import { ResponseError } from '../../components/Errors/ResponseError' ;
5
5
import { ResizeableDataTable } from '../../components/ResizeableDataTable/ResizeableDataTable' ;
6
+ import { TableSkeleton } from '../../components/TableSkeleton/TableSkeleton' ;
6
7
import { TableWithControlsLayout } from '../../components/TableWithControlsLayout/TableWithControlsLayout' ;
7
- import { operationsApi } from '../../store/reducers/operations' ;
8
- import { useAutoRefreshInterval } from '../../utils/hooks' ;
8
+ import { DEFAULT_TABLE_SETTINGS } from '../../utils/constants' ;
9
9
import { isAccessError } from '../../utils/response' ;
10
10
11
11
import { OperationsControls } from './OperationsControls' ;
12
12
import { getColumns } from './columns' ;
13
13
import { OPERATIONS_SELECTED_COLUMNS_KEY } from './constants' ;
14
14
import i18n from './i18n' ;
15
15
import { b } from './shared' ;
16
+ import { useOperationsInfiniteQuery } from './useOperationsInfiniteQuery' ;
16
17
import { useOperationsQueryParams } from './useOperationsQueryParams' ;
17
18
18
19
interface OperationsProps {
19
20
database : string ;
21
+ scrollContainerRef ?: React . RefObject < HTMLElement > ;
20
22
}
21
23
22
- export function Operations ( { database} : OperationsProps ) {
23
- const [ autoRefreshInterval ] = useAutoRefreshInterval ( ) ;
24
-
25
- const { kind, searchValue, pageSize, pageToken, handleKindChange, handleSearchChange} =
24
+ export function Operations ( { database, scrollContainerRef} : OperationsProps ) {
25
+ const { kind, searchValue, pageSize, handleKindChange, handleSearchChange} =
26
26
useOperationsQueryParams ( ) ;
27
27
28
- const { data, isLoading, error, refetch} = operationsApi . useGetOperationListQuery (
29
- { database, kind, page_size : pageSize , page_token : pageToken } ,
30
- {
31
- pollingInterval : autoRefreshInterval ,
32
- } ,
33
- ) ;
34
-
35
- const filteredOperations = React . useMemo ( ( ) => {
36
- if ( ! data ?. operations ) {
37
- return [ ] ;
38
- }
39
- return data . operations . filter ( ( op ) =>
40
- op . id ?. toLowerCase ( ) . includes ( searchValue . toLowerCase ( ) ) ,
41
- ) ;
42
- } , [ data ?. operations , searchValue ] ) ;
28
+ const { operations, isLoading, isLoadingMore, error, refreshTable, totalCount} =
29
+ useOperationsInfiniteQuery ( {
30
+ database,
31
+ kind,
32
+ pageSize,
33
+ searchValue,
34
+ scrollContainerRef,
35
+ } ) ;
43
36
44
37
if ( isAccessError ( error ) ) {
45
38
return < AccessDenied position = "left" /> ;
46
39
}
47
40
41
+ const settings = React . useMemo ( ( ) => {
42
+ return {
43
+ ...DEFAULT_TABLE_SETTINGS ,
44
+ sortable : false ,
45
+ } ;
46
+ } , [ ] ) ;
47
+
48
48
return (
49
49
< TableWithControlsLayout >
50
50
< TableWithControlsLayout . Controls >
51
51
< OperationsControls
52
52
kind = { kind }
53
53
searchValue = { searchValue }
54
- entitiesCountCurrent = { filteredOperations . length }
55
- entitiesCountTotal = { data ?. operations ?. length }
54
+ entitiesCountCurrent = { operations . length }
55
+ entitiesCountTotal = { totalCount }
56
56
entitiesLoading = { isLoading }
57
57
handleKindChange = { handleKindChange }
58
58
handleSearchChange = { handleSearchChange }
59
59
/>
60
60
</ TableWithControlsLayout . Controls >
61
61
{ error ? < ResponseError error = { error } /> : null }
62
62
< TableWithControlsLayout . Table loading = { isLoading } className = { b ( 'table' ) } >
63
- { data ? (
63
+ { operations . length > 0 || isLoading ? (
64
64
< ResizeableDataTable
65
- columns = { getColumns ( { database, refreshTable : refetch } ) }
65
+ columns = { getColumns ( { database, refreshTable, kind } ) }
66
66
columnsWidthLSKey = { OPERATIONS_SELECTED_COLUMNS_KEY }
67
- data = { filteredOperations }
67
+ data = { operations }
68
+ settings = { settings }
68
69
emptyDataMessage = { i18n ( 'title_empty' ) }
69
70
/>
70
- ) : null }
71
+ ) : (
72
+ < div > { i18n ( 'title_empty' ) } </ div >
73
+ ) }
74
+ { isLoadingMore && (
75
+ < TableSkeleton
76
+ showHeader = { false }
77
+ rows = { 3 }
78
+ delay = { 0 }
79
+ className = { b ( 'loading-more' ) }
80
+ />
81
+ ) }
71
82
</ TableWithControlsLayout . Table >
72
83
</ TableWithControlsLayout >
73
84
) ;
0 commit comments