Skip to content

Commit 125d556

Browse files
authored
feat(Header): use cluster domain if cluster name is undefined (#1271)
1 parent f22bdba commit 125d556

File tree

5 files changed

+57
-22
lines changed

5 files changed

+57
-22
lines changed

src/containers/Cluster/Cluster.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import {AutoRefreshControl} from '../../components/AutoRefreshControl/AutoRefres
99
import {EntityStatus} from '../../components/EntityStatus/EntityStatus';
1010
import {InternalLink} from '../../components/InternalLink';
1111
import routes, {getLocationObjectFromHref} from '../../routes';
12-
import {clusterApi, updateDefaultClusterTab} from '../../store/reducers/cluster/cluster';
12+
import {
13+
clusterApi,
14+
selectClusterTitle,
15+
updateDefaultClusterTab,
16+
} from '../../store/reducers/cluster/cluster';
1317
import {setHeaderBreadcrumbs} from '../../store/reducers/header/header';
1418
import type {
1519
AdditionalClusterProps,
@@ -18,7 +22,6 @@ import type {
1822
AdditionalVersionsProps,
1923
} from '../../types/additionalProps';
2024
import {cn} from '../../utils/cn';
21-
import {CLUSTER_DEFAULT_TITLE} from '../../utils/constants';
2225
import {useTypedDispatch, useTypedSelector} from '../../utils/hooks';
2326
import {parseVersionsToVersionToColorMap} from '../../utils/versions';
2427
import {NodesWrapper} from '../Nodes/NodesWrapper';
@@ -58,6 +61,10 @@ export function Cluster({
5861
backend: StringParam,
5962
});
6063

64+
const clusterTitle = useTypedSelector((state) =>
65+
selectClusterTitle(state, clusterName ?? undefined),
66+
);
67+
6168
const {
6269
data: {clusterData: cluster = {}, groupsStats} = {},
6370
isLoading: infoLoading,
@@ -66,11 +73,9 @@ export function Cluster({
6673

6774
const clusterError = error && typeof error === 'object' ? error : undefined;
6875

69-
const {Name} = cluster;
70-
7176
React.useEffect(() => {
7277
dispatch(setHeaderBreadcrumbs('cluster', {}));
73-
}, [dispatch, Name]);
78+
}, [dispatch]);
7479

7580
const versionToColor = React.useMemo(() => {
7681
if (additionalVersionsProps?.getVersionToColorMap) {
@@ -88,13 +93,12 @@ export function Cluster({
8893
<EntityStatus
8994
size="m"
9095
status={cluster?.Overall}
91-
name={cluster?.Name ?? CLUSTER_DEFAULT_TITLE}
96+
name={clusterTitle}
9297
className={b('title')}
9398
/>
9499
);
95100
};
96101

97-
const clusterTitle = cluster?.Name ?? clusterName ?? CLUSTER_DEFAULT_TITLE;
98102
const activeTab = React.useMemo(
99103
() => clusterTabs.find(({id}) => id === activeTabId),
100104
[activeTabId],

src/services/api.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ import type {DescribeConsumerResult} from '../types/api/consumer';
1414
import type {FeatureFlagConfigs} from '../types/api/featureFlags';
1515
import type {HealthCheckAPIResponse} from '../types/api/healthcheck';
1616
import type {JsonHotKeysResponse} from '../types/api/hotkeys';
17-
import type {
18-
MetaCluster,
19-
MetaClusters,
20-
MetaGeneralClusterInfo,
21-
MetaTenants,
22-
} from '../types/api/meta';
17+
import type {MetaBaseClusterInfo, MetaCluster, MetaClusters, MetaTenants} from '../types/api/meta';
2318
import type {ModifyDiskResponse} from '../types/api/modifyDisk';
2419
import type {TNetInfo} from '../types/api/netInfo';
2520
import type {TNodesInfo} from '../types/api/nodes';
@@ -826,7 +821,7 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
826821
getClusterBaseInfo(
827822
_clusterName: string,
828823
_opts: AxiosOptions = {},
829-
): Promise<MetaGeneralClusterInfo> {
824+
): Promise<MetaBaseClusterInfo> {
830825
throw new Error('Method is not implemented.');
831826
}
832827
}
@@ -861,8 +856,8 @@ export class YdbWebVersionAPI extends YdbEmbeddedAPI {
861856
getClusterBaseInfo(
862857
clusterName: string,
863858
{concurrentId, signal}: AxiosOptions = {},
864-
): Promise<MetaGeneralClusterInfo> {
865-
return this.get<MetaGeneralClusterInfo[]>(
859+
): Promise<MetaBaseClusterInfo> {
860+
return this.get<MetaBaseClusterInfo[]>(
866861
`${META_BACKEND || ''}/meta/db_clusters`,
867862
{
868863
name: clusterName,

src/store/reducers/cluster/cluster.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createSlice} from '@reduxjs/toolkit';
1+
import {createSelector, createSlice} from '@reduxjs/toolkit';
22
import type {Dispatch, PayloadAction} from '@reduxjs/toolkit';
33
import {skipToken} from '@reduxjs/toolkit/query';
44
import {StringParam, useQueryParam} from 'use-query-params';
@@ -7,12 +7,17 @@ import type {ClusterTab} from '../../../containers/Cluster/utils';
77
import {clusterTabsIds, isClusterTab} from '../../../containers/Cluster/utils';
88
import {parseTraceFields} from '../../../services/parsers/parseMetaCluster';
99
import 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';
1111
import {isQueryErrorResponse} from '../../../utils/query';
12+
import type {RootState} from '../../defaultStore';
1213
import {api} from '../api';
1314

1415
import type {ClusterGroupsStats, ClusterState} from './types';
15-
import {createSelectClusterGroupsQuery, parseGroupsStatsQueryResponse} from './utils';
16+
import {
17+
createSelectClusterGroupsQuery,
18+
normalizeDomain,
19+
parseGroupsStatsQueryResponse,
20+
} from './utils';
1621

1722
const 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+
);

src/store/reducers/cluster/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,11 @@ export const parseGroupsStatsQueryResponse = (
8686

8787
return result;
8888
};
89+
90+
export function normalizeDomain(domain?: string) {
91+
if (!domain) {
92+
return undefined;
93+
}
94+
const normalizedDomain = domain.startsWith('/') ? domain.slice(1) : domain;
95+
return normalizedDomain.toUpperCase();
96+
}

src/types/api/meta.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface MetaExtendedClusterInfo extends MetaGeneralClusterInfo {
2222
versions?: MetaClusterVersion[];
2323
}
2424

25-
export interface MetaGeneralClusterInfo {
25+
export interface MetaBaseClusterInfo {
2626
owner?: string;
2727
location?: string;
2828
image?: string;
@@ -38,11 +38,14 @@ export interface MetaGeneralClusterInfo {
3838
description?: string;
3939
balancer?: string;
4040
service?: string;
41-
cluster?: MetaViewerClusterInfo;
4241
trace_view?: string;
4342
trace_check?: string;
4443
}
4544

45+
export interface MetaGeneralClusterInfo extends MetaBaseClusterInfo {
46+
cluster?: MetaViewerClusterInfo;
47+
}
48+
4649
// In case of error in viewer /cluster request mvp return error field instead of cluster data
4750
export interface MetaViewerClusterInfo extends TClusterInfo {
4851
error?: string;

0 commit comments

Comments
 (0)