1
1
import React from 'react' ;
2
2
3
3
import { ASCENDING } from '@gravity-ui/react-data-table/build/esm/lib/constants' ;
4
- import { TableColumnSetup } from '@gravity-ui/uikit' ;
5
- import { StringParam , useQueryParams } from 'use-query-params' ;
6
4
7
- import { EntitiesCount } from '../../components/EntitiesCount' ;
8
5
import { AccessDenied } from '../../components/Errors/403' ;
9
6
import { isAccessError } from '../../components/Errors/PageError/PageError' ;
10
7
import { ResponseError } from '../../components/Errors/ResponseError' ;
11
8
import { Illustration } from '../../components/Illustration' ;
12
- import { ProblemFilter } from '../../components/ProblemFilter' ;
13
9
import { ResizeableDataTable } from '../../components/ResizeableDataTable/ResizeableDataTable' ;
14
- import { Search } from '../../components/Search' ;
15
10
import { TableWithControlsLayout } from '../../components/TableWithControlsLayout/TableWithControlsLayout' ;
16
- import { UptimeFilter } from '../../components/UptimeFIlter' ;
17
11
import { NODES_COLUMNS_WIDTH_LS_KEY } from '../../components/nodesColumns/constants' ;
18
12
import { nodesApi } from '../../store/reducers/nodes/nodes' ;
19
13
import { filterNodes } from '../../store/reducers/nodes/selectors' ;
20
14
import type { NodesSortParams } from '../../store/reducers/nodes/types' ;
21
- import {
22
- ProblemFilterValues ,
23
- changeFilter ,
24
- selectProblemFilter ,
25
- } from '../../store/reducers/settings/settings' ;
26
- import type { ProblemFilterValue } from '../../store/reducers/settings/types' ;
15
+ import { useProblemFilter } from '../../store/reducers/settings/hooks' ;
27
16
import type { AdditionalNodesProps } from '../../types/additionalProps' ;
28
- import { cn } from '../../utils/cn' ;
29
17
import { DEFAULT_TABLE_SETTINGS } from '../../utils/constants' ;
30
- import {
31
- useAutoRefreshInterval ,
32
- useTableSort ,
33
- useTypedDispatch ,
34
- useTypedSelector ,
35
- } from '../../utils/hooks' ;
36
- import {
37
- NodesUptimeFilterValues ,
38
- isUnavailableNode ,
39
- nodesUptimeFilterValuesSchema ,
40
- } from '../../utils/nodes' ;
18
+ import { useAutoRefreshInterval , useTableSort } from '../../utils/hooks' ;
19
+ import { NodesUptimeFilterValues } from '../../utils/nodes' ;
41
20
21
+ import { NodesControls } from './NodesControls/NodesControls' ;
42
22
import { useNodesSelectedColumns } from './columns/hooks' ;
43
23
import i18n from './i18n' ;
24
+ import { getRowClassName } from './shared' ;
25
+ import { useNodesPageQueryParams } from './useNodesPageQueryParams' ;
44
26
45
27
import './Nodes.scss' ;
46
28
47
- const b = cn ( 'ydb-nodes' ) ;
48
-
49
29
interface NodesProps {
50
30
path ?: string ;
51
31
database ?: string ;
52
32
additionalNodesProps ?: AdditionalNodesProps ;
53
33
}
54
34
55
35
export const Nodes = ( { path, database, additionalNodesProps = { } } : NodesProps ) => {
56
- const [ queryParams , setQueryParams ] = useQueryParams ( {
57
- uptimeFilter : StringParam ,
58
- search : StringParam ,
59
- } ) ;
60
- const uptimeFilter = nodesUptimeFilterValuesSchema . parse ( queryParams . uptimeFilter ) ;
61
- const searchValue = queryParams . search ?? '' ;
62
-
63
- const dispatch = useTypedDispatch ( ) ;
36
+ const { searchValue, uptimeFilter} = useNodesPageQueryParams ( ) ;
37
+ const { problemFilter} = useProblemFilter ( ) ;
64
38
65
- const problemFilter = useTypedSelector ( selectProblemFilter ) ;
66
39
const [ autoRefreshInterval ] = useAutoRefreshInterval ( ) ;
67
40
68
41
const { columnsToShow, columnsToSelect, setColumns} = useNodesSelectedColumns ( {
@@ -84,18 +57,6 @@ export const Nodes = ({path, database, additionalNodesProps = {}}: NodesProps) =
84
57
setSortValue ( sortParams as NodesSortParams ) ;
85
58
} ) ;
86
59
87
- const handleSearchQueryChange = ( value : string ) => {
88
- setQueryParams ( { search : value || undefined } , 'replaceIn' ) ;
89
- } ;
90
-
91
- const handleProblemFilterChange = ( value : ProblemFilterValue ) => {
92
- dispatch ( changeFilter ( value ) ) ;
93
- } ;
94
-
95
- const handleUptimeFilterChange = ( value : NodesUptimeFilterValues ) => {
96
- setQueryParams ( { uptimeFilter : value } , 'replaceIn' ) ;
97
- } ;
98
-
99
60
const nodes = React . useMemo ( ( ) => {
100
61
return filterNodes ( data ?. Nodes , { searchValue, uptimeFilter, problemFilter} ) ;
101
62
} , [ data , searchValue , uptimeFilter , problemFilter ] ) ;
@@ -104,38 +65,19 @@ export const Nodes = ({path, database, additionalNodesProps = {}}: NodesProps) =
104
65
105
66
const renderControls = ( ) => {
106
67
return (
107
- < React . Fragment >
108
- < Search
109
- onChange = { handleSearchQueryChange }
110
- placeholder = "Host name"
111
- className = { b ( 'search' ) }
112
- value = { searchValue }
113
- />
114
- < ProblemFilter value = { problemFilter } onChange = { handleProblemFilterChange } />
115
- < UptimeFilter value = { uptimeFilter } onChange = { handleUptimeFilterChange } />
116
- < TableColumnSetup
117
- popupWidth = { 200 }
118
- items = { columnsToSelect }
119
- showStatus
120
- onUpdate = { setColumns }
121
- sortable = { false }
122
- />
123
- < EntitiesCount
124
- total = { totalNodes }
125
- current = { nodes . length }
126
- label = { 'Nodes' }
127
- loading = { isLoading }
128
- />
129
- </ React . Fragment >
68
+ < NodesControls
69
+ columnsToSelect = { columnsToSelect }
70
+ handleSelectedColumnsUpdate = { setColumns }
71
+ entitiesCountCurrent = { nodes . length }
72
+ entitiesCountTotal = { totalNodes }
73
+ entitiesLoading = { isLoading }
74
+ />
130
75
) ;
131
76
} ;
132
77
133
78
const renderTable = ( ) => {
134
79
if ( nodes . length === 0 ) {
135
- if (
136
- problemFilter !== ProblemFilterValues . ALL ||
137
- uptimeFilter !== NodesUptimeFilterValues . All
138
- ) {
80
+ if ( problemFilter !== 'All' || uptimeFilter !== NodesUptimeFilterValues . All ) {
139
81
return < Illustration name = "thumbsUp" width = "200" /> ;
140
82
}
141
83
}
@@ -149,7 +91,7 @@ export const Nodes = ({path, database, additionalNodesProps = {}}: NodesProps) =
149
91
sortOrder = { sort }
150
92
onSort = { handleSort }
151
93
emptyDataMessage = { i18n ( 'empty.default' ) }
152
- rowClassName = { ( row ) => b ( 'node' , { unavailable : isUnavailableNode ( row ) } ) }
94
+ rowClassName = { getRowClassName }
153
95
/>
154
96
) ;
155
97
} ;
0 commit comments