Skip to content

Commit bbe1fca

Browse files
refactor: migrate tenants reducer to ts
1 parent fcb0fec commit bbe1fca

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

src/containers/Tenants/Tenants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {formatCPU, formatBytesToGigabyte, formatNumber} from '../../utils';
2020
import {hideTooltip, showTooltip} from '../../store/reducers/tooltip';
2121
import {withSearch} from '../../HOCS';
2222
import {ALL, DEFAULT_TABLE_SETTINGS, TENANT_INITIAL_TAB_KEY} from '../../utils/constants';
23-
import {getTenantsInfo} from '../../store/reducers/tenants';
23+
import {getTenantsInfo} from '../../store/reducers/tenants/tenants';
2424
import {changeFilter, getSettingValue} from '../../store/reducers/settings';
2525
import {setHeader} from '../../store/reducers/header';
2626

src/store/reducers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import schema from './schema';
1515
import host from './host';
1616
import network from './network';
1717
import pool from './pool';
18-
import tenants from './tenants';
18+
import tenants from './tenants/tenants';
1919
import tablet from './tablet';
2020
import topic from './topic';
2121
import consumer from './consumer';

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

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

5-
const FETCH_TENANTS = createRequestActionTypes('tenants', 'FETCH_TENANTS');
3+
import '../../../services/api';
4+
import {createRequestActionTypes, createApiRequest} from '../../utils';
65

7-
const initialState = {loading: true, wasLoaded: false, data: {}};
6+
import type {TenantsAction, TenantsState} from './types';
87

9-
const tenants = function (state = initialState, action) {
8+
export const FETCH_TENANTS = createRequestActionTypes('tenants', 'FETCH_TENANTS');
9+
10+
const initialState = {loading: true, wasLoaded: false};
11+
12+
const tenants: Reducer<TenantsState, TenantsAction> = (state = initialState, action) => {
1013
switch (action.type) {
1114
case FETCH_TENANTS.REQUEST: {
1215
return {
@@ -35,20 +38,22 @@ const tenants = function (state = initialState, action) {
3538
}
3639
};
3740

38-
export function getTenantsInfo(clusterName) {
41+
export function getTenantsInfo(clusterName?: string) {
3942
return createApiRequest({
4043
request: window.api.getTenants(clusterName),
4144
actions: FETCH_TENANTS,
4245
dataHandler: (response, getState) => {
4346
const {singleClusterMode} = getState();
47+
4448
if (singleClusterMode) {
4549
return response.TenantInfo;
4650
} else {
47-
return response.databases?.map((tenant) => {
51+
return response.TenantInfo?.map((tenant) => {
4852
const node = tenant.Nodes ? tenant.Nodes[0] : {};
4953
const address =
5054
node.Host && node.Endpoints
51-
? _.find(node.Endpoints, {Name: 'http-mon'})?.Address
55+
? node.Endpoints.find((endpoint) => endpoint.Name === 'http-mon')
56+
?.Address
5257
: undefined;
5358
const backend = node.Host ? `${node.Host}${address ? address : ''}` : undefined;
5459
return {...tenant, backend};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {FETCH_TENANTS} from './tenants';
2+
3+
import type {TTenant} from '../../../types/api/tenant';
4+
import type {ApiRequestAction} from '../../utils';
5+
6+
export interface PreparedTenant extends TTenant {
7+
backend?: string;
8+
}
9+
10+
export interface TenantsState {
11+
loading: boolean;
12+
wasLoaded: boolean;
13+
tenants?: PreparedTenant[];
14+
error?: unknown;
15+
}
16+
17+
export type TenantsAction = ApiRequestAction<typeof FETCH_TENANTS, PreparedTenant[], unknown>;

src/types/api/tenant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface TTenant {
5454
CoresUsed: number;
5555
/** uint64 */
5656
StorageGroups: string;
57+
5758
MonitoringEndpoint?: string; // additional
5859
ControlPlane?: ControlPlane; // additional
5960
}

0 commit comments

Comments
 (0)