@@ -4,22 +4,21 @@ import DataTable from '@gravity-ui/react-data-table';
44import { Select , TableColumnSetup } from '@gravity-ui/uikit' ;
55import { Helmet } from 'react-helmet-async' ;
66
7+ import { ResponseError } from '../../components/Errors/ResponseError' ;
78import { Loader } from '../../components/Loader' ;
89import { Search } from '../../components/Search' ;
9- import { changeClustersFilters , fetchClustersList } from '../../store/reducers/clusters/clusters' ;
10+ import { changeClustersFilters , clustersApi } from '../../store/reducers/clusters/clusters' ;
1011import {
12+ aggregateClustersInfo ,
13+ filterClusters ,
1114 selectClusterNameFilter ,
12- selectClustersAggregation ,
13- selectClustersList ,
14- selectFilteredClusters ,
15- selectLoadingFlag ,
1615 selectServiceFilter ,
1716 selectStatusFilter ,
1817 selectVersionFilter ,
19- selectVersions ,
2018} from '../../store/reducers/clusters/selectors' ;
21- import { DEFAULT_TABLE_SETTINGS } from '../../utils/constants' ;
22- import { useAutofetcher , useTypedDispatch , useTypedSelector } from '../../utils/hooks' ;
19+ import { DEFAULT_POLLING_INTERVAL , DEFAULT_TABLE_SETTINGS } from '../../utils/constants' ;
20+ import { useTypedDispatch , useTypedSelector } from '../../utils/hooks' ;
21+ import { getMinorVersion } from '../../utils/versions' ;
2322
2423import { ClustersStatistics } from './ClustersStatistics' ;
2524import { CLUSTERS_COLUMNS } from './columns' ;
@@ -37,23 +36,16 @@ import {useSelectedColumns} from './useSelectedColumns';
3736import './Clusters.scss' ;
3837
3938export function Clusters ( ) {
39+ const query = clustersApi . useGetClustersListQuery ( undefined , {
40+ pollingInterval : DEFAULT_POLLING_INTERVAL ,
41+ } ) ;
42+
4043 const dispatch = useTypedDispatch ( ) ;
4144
42- const loading = useTypedSelector ( selectLoadingFlag ) ;
43- const clusters = useTypedSelector ( selectClustersList ) ;
44- const filteredClusters = useTypedSelector ( selectFilteredClusters ) ;
45- const aggregation = useTypedSelector ( selectClustersAggregation ) ;
4645 const clusterName = useTypedSelector ( selectClusterNameFilter ) ;
4746 const status = useTypedSelector ( selectStatusFilter ) ;
4847 const service = useTypedSelector ( selectServiceFilter ) ;
4948 const version = useTypedSelector ( selectVersionFilter ) ;
50- const versions = useTypedSelector ( selectVersions ) ;
51-
52- const fetchData = React . useCallback ( ( ) => {
53- dispatch ( fetchClustersList ( ) ) ;
54- } , [ dispatch ] ) ;
55-
56- useAutofetcher ( fetchData , [ fetchData ] , true ) ;
5749
5850 const changeStatus = ( value : string [ ] ) => {
5951 dispatch ( changeClustersFilters ( { status : value } ) ) ;
@@ -76,24 +68,41 @@ export function Clusters() {
7668 [ COLUMNS_NAMES . TITLE ] ,
7769 ) ;
7870
79- const servicesToSelect = React . useMemo ( ( ) => {
71+ const clusters = query . data ;
72+
73+ const { servicesToSelect, versions} = React . useMemo ( ( ) => {
8074 const clustersServices = new Set < string > ( ) ;
75+ const uniqVersions = new Set < string > ( ) ;
8176
82- clusters . forEach ( ( cluster ) => {
77+ const clusterList = clusters ?? [ ] ;
78+ clusterList . forEach ( ( cluster ) => {
8379 if ( cluster . service ) {
8480 clustersServices . add ( cluster . service ) ;
8581 }
82+ cluster . cluster ?. Versions ?. forEach ( ( v ) => {
83+ uniqVersions . add ( getMinorVersion ( v ) ) ;
84+ } ) ;
8685 } ) ;
8786
88- return Array . from ( clustersServices ) . map ( ( clusterService ) => {
89- return {
90- value : clusterService ,
91- content : clusterService ,
92- } ;
93- } ) ;
87+ return {
88+ servicesToSelect : Array . from ( clustersServices ) . map ( ( value ) => ( {
89+ value,
90+ content : value ,
91+ } ) ) ,
92+ versions : Array . from ( uniqVersions ) . map ( ( value ) => ( { value, content : value } ) ) ,
93+ } ;
9494 } , [ clusters ] ) ;
9595
96- if ( loading && ! clusters . length ) {
96+ const filteredClusters = React . useMemo ( ( ) => {
97+ return filterClusters ( clusters ?? [ ] , { clusterName, status, service, version} ) ;
98+ } , [ clusterName , clusters , service , status , version ] ) ;
99+
100+ const aggregation = React . useMemo (
101+ ( ) => aggregateClustersInfo ( filteredClusters ) ,
102+ [ filteredClusters ] ,
103+ ) ;
104+
105+ if ( query . isLoading ) {
97106 return < Loader size = "l" /> ;
98107 }
99108
@@ -162,6 +171,7 @@ export function Clusters() {
162171 />
163172 </ div >
164173 </ div >
174+ { query . isError ? < ResponseError error = { query . error } className = { b ( 'error' ) } /> : null }
165175 < div className = { b ( 'table-wrapper' ) } >
166176 < div className = { b ( 'table-content' ) } >
167177 < DataTable
0 commit comments