Skip to content

Commit e122ef0

Browse files
refactor: migrate cluster reducer to ts
1 parent bbe1fca commit e122ef0

File tree

7 files changed

+32
-20
lines changed

7 files changed

+32
-20
lines changed

src/components/ClusterInfo/ClusterInfo.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {Tablet} from '../Tablet';
1515
//@ts-ignore
1616
import {hideTooltip, showTooltip} from '../../store/reducers/tooltip';
1717
//@ts-ignore
18-
import {getClusterInfo} from '../../store/reducers/cluster';
18+
import {getClusterInfo} from '../../store/reducers/cluster/cluster';
1919
//@ts-ignore
2020
import {clusterName, backend, customBackend} from '../../store';
2121

@@ -68,6 +68,8 @@ class ClusterInfo extends React.Component<ClusterInfoProps> {
6868
return 0;
6969
}
7070

71+
private autofetcher: any;
72+
7173
componentDidMount() {
7274
const {setHeader} = this.props;
7375
setHeader([
@@ -107,8 +109,6 @@ class ClusterInfo extends React.Component<ClusterInfoProps> {
107109
return <div className={b(null, className)}>{helper || this.renderContent()}</div>;
108110
}
109111

110-
private autofetcher: any;
111-
112112
private getInfo() {
113113
const {cluster = {}, additionalClusterInfo = [], singleClusterMode} = this.props;
114114
const {StorageTotal, StorageUsed} = cluster;

src/containers/Header/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Divider from '../../components/Divider/Divider';
88
import {Icon} from '../../components/Icon';
99

1010
import {clusterName as clusterNameLocation, backend, customBackend} from '../../store';
11-
import {getClusterInfo} from '../../store/reducers/cluster';
11+
import {getClusterInfo} from '../../store/reducers/cluster/cluster';
1212
import {getHostInfo} from '../../store/reducers/host';
1313
import {HeaderItemType} from '../../store/reducers/header';
1414

src/services/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
5555
node_id: id,
5656
});
5757
}
58-
getTenants() {
58+
getTenants(clusterName?: string) {
5959
return this.get<TTenantInfo>(this.getPath('/viewer/json/tenantinfo'), {
6060
tablets: 1,
6161
storage: 1,
62+
cluster_name: clusterName,
6263
});
6364
}
6465
getTenantInfo({path}: {path: string}) {

src/store/reducers/cluster.js renamed to src/store/reducers/cluster/cluster.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import {createRequestActionTypes, createApiRequest} from '../utils';
2-
import '../../services/api';
1+
import type {Reducer} from 'redux';
32

4-
const FETCH_CLUSTER = createRequestActionTypes('cluster', 'FETCH_CLUSTER');
3+
import '../../../services/api';
4+
import {createRequestActionTypes, createApiRequest} from '../../utils';
5+
import type {ClusterAction, ClusterState} from './types';
6+
7+
export const FETCH_CLUSTER = createRequestActionTypes('cluster', 'FETCH_CLUSTER');
58

69
const initialState = {loading: true, wasLoaded: false};
710

8-
const cluster = function (state = initialState, action) {
11+
const cluster: Reducer<ClusterState, ClusterAction> = (state = initialState, action) => {
912
switch (action.type) {
1013
case FETCH_CLUSTER.REQUEST: {
1114
return {
@@ -14,17 +17,9 @@ const cluster = function (state = initialState, action) {
1417
};
1518
}
1619
case FETCH_CLUSTER.SUCCESS: {
17-
const {data} = action;
18-
const clusterInfo = data.cluster ? data.cluster.cluster : data;
19-
const clusterName = data.cluster?.title || data.Name;
2020
return {
2121
...state,
22-
data: {
23-
...clusterInfo,
24-
balancer: data.cluster?.balancer,
25-
solomon: data.cluster?.solomon,
26-
Name: clusterName,
27-
},
22+
data: action.data,
2823
loading: false,
2924
wasLoaded: true,
3025
error: undefined,
@@ -42,7 +37,7 @@ const cluster = function (state = initialState, action) {
4237
}
4338
};
4439

45-
export function getClusterInfo(clusterName) {
40+
export function getClusterInfo(clusterName?: string) {
4641
return createApiRequest({
4742
request: window.api.getClusterInfo(clusterName),
4843
actions: FETCH_CLUSTER,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {FETCH_CLUSTER} from './cluster';
2+
3+
import type {TClusterInfo} from '../../../types/api/cluster';
4+
import type {ApiRequestAction} from '../../utils';
5+
6+
export interface ClusterState {
7+
loading: boolean;
8+
wasLoaded: boolean;
9+
data?: TClusterInfo;
10+
error?: unknown;
11+
}
12+
13+
export type ClusterAction = ApiRequestAction<typeof FETCH_CLUSTER, TClusterInfo, unknown>;

src/store/reducers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {combineReducers} from 'redux';
22

33
import nodes from './nodes';
4-
import cluster from './cluster';
4+
import cluster from './cluster/cluster';
55
import tenant from './tenant';
66
import storage from './storage';
77
import node from './node';

src/types/api/cluster.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ export interface TClusterInfo {
3131
Tenants?: string;
3232
/** uint64 */
3333
Tablets?: string;
34+
35+
Balancer?: string; // additional
36+
Solomon?: string; // additional
3437
}

0 commit comments

Comments
 (0)