11import React from 'react' ;
22
33import DataTable from '@gravity-ui/react-data-table' ;
4- import { Select , TableColumnSetup } from '@gravity-ui/uikit' ;
4+ import { Flex , Select , TableColumnSetup , Text } from '@gravity-ui/uikit' ;
55import { Helmet } from 'react-helmet-async' ;
66
77import { AutoRefreshControl } from '../../components/AutoRefreshControl/AutoRefreshControl' ;
88import { ResponseError } from '../../components/Errors/ResponseError' ;
99import { Loader } from '../../components/Loader' ;
1010import { ResizeableDataTable } from '../../components/ResizeableDataTable/ResizeableDataTable' ;
1111import { Search } from '../../components/Search' ;
12+ import {
13+ useDeleteClusterFeatureAvailable ,
14+ useEditClusterFeatureAvailable ,
15+ } from '../../store/reducers/capabilities/hooks' ;
1216import { changeClustersFilters , clustersApi } from '../../store/reducers/clusters/clusters' ;
1317import {
14- aggregateClustersInfo ,
1518 filterClusters ,
1619 selectClusterNameFilter ,
1720 selectServiceFilter ,
1821 selectStatusFilter ,
1922 selectVersionFilter ,
2023} from '../../store/reducers/clusters/selectors' ;
24+ import { setHeaderBreadcrumbs } from '../../store/reducers/header/header' ;
25+ import { uiFactory } from '../../uiFactory/uiFactory' ;
2126import { DEFAULT_TABLE_SETTINGS } from '../../utils/constants' ;
2227import { useAutoRefreshInterval , useTypedDispatch , useTypedSelector } from '../../utils/hooks' ;
2328import { useSelectedColumns } from '../../utils/hooks/useSelectedColumns' ;
2429import { getMinorVersion } from '../../utils/versions' ;
2530
26- import { ClustersStatistics } from './ClustersStatistics' ;
27- import { CLUSTERS_COLUMNS , CLUSTERS_COLUMNS_WIDTH_LS_KEY } from './columns' ;
31+ import { CLUSTERS_COLUMNS_WIDTH_LS_KEY , getClustersColumns } from './columns' ;
2832import {
2933 CLUSTERS_SELECTED_COLUMNS_KEY ,
3034 COLUMNS_NAMES ,
@@ -44,6 +48,15 @@ export function Clusters() {
4448
4549 const dispatch = useTypedDispatch ( ) ;
4650
51+ React . useEffect ( ( ) => {
52+ dispatch ( setHeaderBreadcrumbs ( 'clusters' , { } ) ) ;
53+ } , [ dispatch ] ) ;
54+
55+ const isEditClusterAvailable =
56+ useEditClusterFeatureAvailable ( ) && uiFactory . onEditCluster !== undefined ;
57+ const isDeleteClusterAvailable =
58+ useDeleteClusterFeatureAvailable ( ) && uiFactory . onDeleteCluster !== undefined ;
59+
4760 const clusterName = useTypedSelector ( selectClusterNameFilter ) ;
4861 const status = useTypedSelector ( selectStatusFilter ) ;
4962 const service = useTypedSelector ( selectServiceFilter ) ;
@@ -62,8 +75,12 @@ export function Clusters() {
6275 dispatch ( changeClustersFilters ( { version : value } ) ) ;
6376 } ;
6477
78+ const rawColumns = React . useMemo ( ( ) => {
79+ return getClustersColumns ( { isEditClusterAvailable, isDeleteClusterAvailable} ) ;
80+ } , [ isDeleteClusterAvailable , isEditClusterAvailable ] ) ;
81+
6582 const { columnsToShow, columnsToSelect, setColumns} = useSelectedColumns (
66- CLUSTERS_COLUMNS ,
83+ rawColumns ,
6784 CLUSTERS_SELECTED_COLUMNS_KEY ,
6885 COLUMNS_TITLES ,
6986 DEFAULT_COLUMNS ,
@@ -99,11 +116,6 @@ export function Clusters() {
99116 return filterClusters ( clusters ?? [ ] , { clusterName, status, service, version} ) ;
100117 } , [ clusterName , clusters , service , status , version ] ) ;
101118
102- const aggregation = React . useMemo (
103- ( ) => aggregateClustersInfo ( filteredClusters ) ,
104- [ filteredClusters ] ,
105- ) ;
106-
107119 const statuses = React . useMemo ( ( ) => {
108120 return Array . from (
109121 new Set (
@@ -114,14 +126,29 @@ export function Clusters() {
114126 . map ( ( el ) => ( { value : el , content : el } ) ) ;
115127 } , [ clusters ] ) ;
116128
129+ const renderPageTitle = ( ) => {
130+ return (
131+ < Flex justifyContent = "space-between" >
132+ < Flex gap = { 2 } >
133+ < Text variant = "header-1" > { i18n ( 'page_title' ) } </ Text >
134+ < Text variant = "header-1" color = "secondary" >
135+ { clusters ?. length }
136+ </ Text >
137+ </ Flex >
138+ < AutoRefreshControl className = { b ( 'autorefresh' ) } />
139+ </ Flex >
140+ ) ;
141+ } ;
142+
117143 return (
118144 < div className = { b ( ) } >
119145 < Helmet >
120146 < title > { i18n ( 'page_title' ) } </ title >
121147 </ Helmet >
122148
123- < ClustersStatistics stats = { aggregation } count = { filteredClusters . length } />
124- < div className = { b ( 'controls' ) } >
149+ { renderPageTitle ( ) }
150+
151+ < Flex >
125152 < div className = { b ( 'control' , { wide : true } ) } >
126153 < Search
127154 placeholder = { i18n ( 'controls_search-placeholder' ) }
@@ -178,8 +205,7 @@ export function Clusters() {
178205 sortable = { false }
179206 />
180207 </ div >
181- < AutoRefreshControl className = { b ( 'autorefresh' ) } />
182- </ div >
208+ </ Flex >
183209 { query . isError ? < ResponseError error = { query . error } className = { b ( 'error' ) } /> : null }
184210 { query . isLoading ? < Loader size = "l" /> : null }
185211 { query . fulfilledTimeStamp ? (
0 commit comments