1- import { createSlice } from '@reduxjs/toolkit' ;
1+ import { createSelector , createSlice } from '@reduxjs/toolkit' ;
22import type { Dispatch , PayloadAction } from '@reduxjs/toolkit' ;
33import { skipToken } from '@reduxjs/toolkit/query' ;
44import { StringParam , useQueryParam } from 'use-query-params' ;
@@ -7,12 +7,17 @@ import type {ClusterTab} from '../../../containers/Cluster/utils';
77import { clusterTabsIds , isClusterTab } from '../../../containers/Cluster/utils' ;
88import { parseTraceFields } from '../../../services/parsers/parseMetaCluster' ;
99import type { TClusterInfo } from '../../../types/api/cluster' ;
10- import { DEFAULT_CLUSTER_TAB_KEY } from '../../../utils/constants' ;
10+ import { CLUSTER_DEFAULT_TITLE , DEFAULT_CLUSTER_TAB_KEY } from '../../../utils/constants' ;
1111import { isQueryErrorResponse } from '../../../utils/query' ;
12+ import type { RootState } from '../../defaultStore' ;
1213import { api } from '../api' ;
1314
1415import type { ClusterGroupsStats , ClusterState } from './types' ;
15- import { createSelectClusterGroupsQuery , parseGroupsStatsQueryResponse } from './utils' ;
16+ import {
17+ createSelectClusterGroupsQuery ,
18+ normalizeDomain ,
19+ parseGroupsStatsQueryResponse ,
20+ } from './utils' ;
1621
1722const defaultClusterTabLS = localStorage . getItem ( DEFAULT_CLUSTER_TAB_KEY ) ;
1823
@@ -61,7 +66,6 @@ export const clusterApi = api.injectEndpoints({
6166 const clusterData = await window . api . getClusterInfo ( clusterName , { signal} ) ;
6267
6368 const clusterRoot = clusterData . Domain ;
64-
6569 // Without domain we cannot get stats from system tables
6670 if ( ! clusterRoot ) {
6771 return { data : { clusterData} } ;
@@ -134,3 +138,24 @@ export function useClusterBaseInfo() {
134138 monitoring,
135139 } ;
136140}
141+
142+ const createClusterInfoSelector = createSelector (
143+ ( clusterName ?: string ) => clusterName ,
144+ ( clusterName ) => clusterApi . endpoints . getClusterInfo . select ( clusterName ) ,
145+ ) ;
146+
147+ export const selectClusterInfo = createSelector (
148+ ( state : RootState ) => state ,
149+ ( _state : RootState , clusterName ?: string ) => createClusterInfoSelector ( clusterName ) ,
150+ ( state , selectGetClusterInfo ) => selectGetClusterInfo ( state ) . data ,
151+ ) ;
152+
153+ export const selectClusterTitle = createSelector (
154+ ( _state : RootState , clusterName ?: string ) => clusterName ,
155+ ( state : RootState , clusterName ?: string ) => selectClusterInfo ( state , clusterName ) ,
156+ ( clusterName , clusterInfo ) => {
157+ const { Name, Domain} = clusterInfo ?. clusterData || { } ;
158+
159+ return Name || clusterName || normalizeDomain ( Domain ) || CLUSTER_DEFAULT_TITLE ;
160+ } ,
161+ ) ;
0 commit comments