11import React from 'react' ;
22
33import { 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' ;
64
7- import { EntitiesCount } from '../../components/EntitiesCount' ;
85import { AccessDenied } from '../../components/Errors/403' ;
96import { isAccessError } from '../../components/Errors/PageError/PageError' ;
107import { ResponseError } from '../../components/Errors/ResponseError' ;
118import { Illustration } from '../../components/Illustration' ;
12- import { ProblemFilter } from '../../components/ProblemFilter' ;
139import { ResizeableDataTable } from '../../components/ResizeableDataTable/ResizeableDataTable' ;
14- import { Search } from '../../components/Search' ;
1510import { TableWithControlsLayout } from '../../components/TableWithControlsLayout/TableWithControlsLayout' ;
16- import { UptimeFilter } from '../../components/UptimeFIlter' ;
1711import { NODES_COLUMNS_WIDTH_LS_KEY } from '../../components/nodesColumns/constants' ;
1812import { nodesApi } from '../../store/reducers/nodes/nodes' ;
1913import { filterNodes } from '../../store/reducers/nodes/selectors' ;
2014import 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' ;
2716import type { AdditionalNodesProps } from '../../types/additionalProps' ;
28- import { cn } from '../../utils/cn' ;
2917import { 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' ;
4120
21+ import { NodesControls } from './NodesControls/NodesControls' ;
4222import { useNodesSelectedColumns } from './columns/hooks' ;
4323import i18n from './i18n' ;
24+ import { getRowClassName } from './shared' ;
25+ import { useNodesPageQueryParams } from './useNodesPageQueryParams' ;
4426
4527import './Nodes.scss' ;
4628
47- const b = cn ( 'ydb-nodes' ) ;
48-
4929interface NodesProps {
5030 path ?: string ;
5131 database ?: string ;
5232 additionalNodesProps ?: AdditionalNodesProps ;
5333}
5434
5535export 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 ( ) ;
6438
65- const problemFilter = useTypedSelector ( selectProblemFilter ) ;
6639 const [ autoRefreshInterval ] = useAutoRefreshInterval ( ) ;
6740
6841 const { columnsToShow, columnsToSelect, setColumns} = useNodesSelectedColumns ( {
@@ -84,18 +57,6 @@ export const Nodes = ({path, database, additionalNodesProps = {}}: NodesProps) =
8457 setSortValue ( sortParams as NodesSortParams ) ;
8558 } ) ;
8659
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-
9960 const nodes = React . useMemo ( ( ) => {
10061 return filterNodes ( data ?. Nodes , { searchValue, uptimeFilter, problemFilter} ) ;
10162 } , [ data , searchValue , uptimeFilter , problemFilter ] ) ;
@@ -104,38 +65,19 @@ export const Nodes = ({path, database, additionalNodesProps = {}}: NodesProps) =
10465
10566 const renderControls = ( ) => {
10667 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+ />
13075 ) ;
13176 } ;
13277
13378 const renderTable = ( ) => {
13479 if ( nodes . length === 0 ) {
135- if (
136- problemFilter !== ProblemFilterValues . ALL ||
137- uptimeFilter !== NodesUptimeFilterValues . All
138- ) {
80+ if ( problemFilter !== 'All' || uptimeFilter !== NodesUptimeFilterValues . All ) {
13981 return < Illustration name = "thumbsUp" width = "200" /> ;
14082 }
14183 }
@@ -149,7 +91,7 @@ export const Nodes = ({path, database, additionalNodesProps = {}}: NodesProps) =
14991 sortOrder = { sort }
15092 onSort = { handleSort }
15193 emptyDataMessage = { i18n ( 'empty.default' ) }
152- rowClassName = { ( row ) => b ( 'node' , { unavailable : isUnavailableNode ( row ) } ) }
94+ rowClassName = { getRowClassName }
15395 />
15496 ) ;
15597 } ;
0 commit comments