Skip to content

Commit 0ff2c9a

Browse files
refactor: migrate tenant reducer to ts (#408)
1 parent d7d671f commit 0ff2c9a

File tree

15 files changed

+160
-142
lines changed

15 files changed

+160
-142
lines changed

src/containers/Tenant/Diagnostics/Consumers/columns/columns.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import block from 'bem-cn-lite';
33
import qs from 'qs';
44

55
import type {IPreparedConsumerData} from '../../../../../types/store/topic';
6+
import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../../../store/reducers/tenant/constants';
67
import {SpeedMultiMeter} from '../../../../../components/SpeedMultiMeter';
78
import {InternalLink} from '../../../../../components/InternalLink';
89
import {formatMsToUptime} from '../../../../../utils';
910
import routes, {createHref} from '../../../../../routes';
1011

1112
import {TenantTabsGroups} from '../../../TenantPages';
12-
import {GeneralPagesIds} from '../../DiagnosticsPages';
1313

1414
import {
1515
CONSUMERS_COLUMNS_IDS,
@@ -42,7 +42,7 @@ export const columns: Column<IPreparedConsumerData>[] = [
4242
<InternalLink
4343
to={createHref(routes.tenant, undefined, {
4444
...queryParams,
45-
[TenantTabsGroups.generalTab]: GeneralPagesIds.partitions,
45+
[TenantTabsGroups.generalTab]: TENANT_DIAGNOSTICS_TABS_IDS.partitions,
4646
selectedConsumer: row.name,
4747
})}
4848
>

src/containers/Tenant/Diagnostics/Diagnostics.tsx

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,36 @@ import {useLocation} from 'react-router';
77

88
import {Switch, Tabs} from '@gravity-ui/uikit';
99

10+
import type {EPathType} from '../../../types/api/schema';
11+
12+
import {useTypedSelector} from '../../../utils/hooks';
13+
import routes, {createHref} from '../../../routes';
14+
import type {TenantDiagnosticsTab, TenantGeneralTab} from '../../../store/reducers/tenant/types';
15+
import {enableAutorefresh, disableAutorefresh} from '../../../store/reducers/schema';
16+
import {setTopLevelTab, setDiagnosticsTab} from '../../../store/reducers/tenant/tenant';
17+
import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../store/reducers/tenant/constants';
18+
1019
import {Loader} from '../../../components/Loader';
1120

12-
import {TopQueries} from './TopQueries';
13-
//@ts-ignore
14-
import DetailedOverview from './DetailedOverview/DetailedOverview';
15-
import {TopShards} from './TopShards';
16-
//@ts-ignore
17-
import Storage from '../../Storage/Storage';
18-
//@ts-ignore
19-
import Network from './Network/Network';
20-
//@ts-ignore
21-
import Describe from './Describe/Describe';
22-
//@ts-ignore
23-
import HotKeys from './HotKeys/HotKeys';
24-
//@ts-ignore
2521
import {Heatmap} from '../../Heatmap';
2622
import {Nodes} from '../../Nodes';
27-
//@ts-ignore
23+
import Storage from '../../Storage/Storage';
2824
import {Tablets} from '../../Tablets';
29-
import {Consumers} from './Consumers';
25+
26+
import Describe from './Describe/Describe';
27+
import HotKeys from './HotKeys/HotKeys';
28+
import Network from './Network/Network';
3029
import {Partitions} from './Partitions/Partitions';
30+
import {Consumers} from './Consumers';
31+
import {TopQueries} from './TopQueries';
32+
import {TopShards} from './TopShards';
33+
import DetailedOverview from './DetailedOverview/DetailedOverview';
3134

32-
import routes, {createHref} from '../../../routes';
33-
import type {EPathType} from '../../../types/api/schema';
34-
import {TenantGeneralTabsIds, TenantTabsGroups} from '../TenantPages';
35-
import {GeneralPagesIds, DATABASE_PAGES, getPagesByType} from './DiagnosticsPages';
36-
//@ts-ignore
37-
import {enableAutorefresh, disableAutorefresh} from '../../../store/reducers/schema';
38-
import {setTopLevelTab, setDiagnosticsTab} from '../../../store/reducers/tenant';
3935
import {isDatabaseEntityType} from '../utils/schema';
4036

37+
import {TenantTabsGroups} from '../TenantPages';
38+
import {DATABASE_PAGES, getPagesByType} from './DiagnosticsPages';
39+
4140
import './Diagnostics.scss';
4241

4342
interface DiagnosticsProps {
@@ -51,8 +50,8 @@ const b = cn('kv-tenant-diagnostics');
5150
function Diagnostics(props: DiagnosticsProps) {
5251
const dispatch = useDispatch();
5352
const {currentSchemaPath, autorefresh} = useSelector((state: any) => state.schema);
54-
const {diagnosticsTab = GeneralPagesIds.overview, wasLoaded} = useSelector(
55-
(state: any) => state.tenant,
53+
const {diagnosticsTab = TENANT_DIAGNOSTICS_TABS_IDS.overview, wasLoaded} = useTypedSelector(
54+
(state) => state.tenant,
5655
);
5756

5857
const location = useLocation();
@@ -73,7 +72,7 @@ function Diagnostics(props: DiagnosticsProps) {
7372
return getPagesByType(props.type);
7473
}, [props.type, isDatabase]);
7574

76-
const forwardToDiagnosticTab = (tab: GeneralPagesIds) => {
75+
const forwardToDiagnosticTab = (tab: TenantDiagnosticsTab) => {
7776
dispatch(setDiagnosticsTab(tab));
7877
};
7978
const activeTab = useMemo(() => {
@@ -97,7 +96,7 @@ function Diagnostics(props: DiagnosticsProps) {
9796
}
9897
};
9998

100-
const forwardToGeneralTab = (tab: TenantGeneralTabsIds) => {
99+
const forwardToGeneralTab = (tab: TenantGeneralTab) => {
101100
dispatch(setTopLevelTab(tab));
102101
};
103102

@@ -107,7 +106,7 @@ function Diagnostics(props: DiagnosticsProps) {
107106
const tenantNameString = tenantName as string;
108107

109108
switch (diagnosticsTab) {
110-
case GeneralPagesIds.overview: {
109+
case TENANT_DIAGNOSTICS_TABS_IDS.overview: {
111110
return (
112111
<DetailedOverview
113112
type={type}
@@ -116,7 +115,7 @@ function Diagnostics(props: DiagnosticsProps) {
116115
/>
117116
);
118117
}
119-
case GeneralPagesIds.topQueries: {
118+
case TENANT_DIAGNOSTICS_TABS_IDS.topQueries: {
120119
return (
121120
<TopQueries
122121
path={tenantNameString}
@@ -125,10 +124,10 @@ function Diagnostics(props: DiagnosticsProps) {
125124
/>
126125
);
127126
}
128-
case GeneralPagesIds.topShards: {
127+
case TENANT_DIAGNOSTICS_TABS_IDS.topShards: {
129128
return <TopShards tenantPath={tenantNameString} type={type} />;
130129
}
131-
case GeneralPagesIds.nodes: {
130+
case TENANT_DIAGNOSTICS_TABS_IDS.nodes: {
132131
return (
133132
<Nodes
134133
path={currentSchemaPath}
@@ -137,28 +136,28 @@ function Diagnostics(props: DiagnosticsProps) {
137136
/>
138137
);
139138
}
140-
case GeneralPagesIds.tablets: {
139+
case TENANT_DIAGNOSTICS_TABS_IDS.tablets: {
141140
return <Tablets path={currentSchemaPath} />;
142141
}
143-
case GeneralPagesIds.storage: {
142+
case TENANT_DIAGNOSTICS_TABS_IDS.storage: {
144143
return <Storage tenant={tenantNameString} database={true} />;
145144
}
146-
case GeneralPagesIds.network: {
145+
case TENANT_DIAGNOSTICS_TABS_IDS.network: {
147146
return <Network path={tenantNameString} />;
148147
}
149-
case GeneralPagesIds.describe: {
148+
case TENANT_DIAGNOSTICS_TABS_IDS.describe: {
150149
return <Describe tenant={tenantNameString} type={type} />;
151150
}
152-
case GeneralPagesIds.hotKeys: {
151+
case TENANT_DIAGNOSTICS_TABS_IDS.hotKeys: {
153152
return <HotKeys type={type} />;
154153
}
155-
case GeneralPagesIds.graph: {
154+
case TENANT_DIAGNOSTICS_TABS_IDS.graph: {
156155
return <Heatmap path={currentSchemaPath} />;
157156
}
158-
case GeneralPagesIds.consumers: {
157+
case TENANT_DIAGNOSTICS_TABS_IDS.consumers: {
159158
return <Consumers path={currentSchemaPath} type={type} />;
160159
}
161-
case GeneralPagesIds.partitions: {
160+
case TENANT_DIAGNOSTICS_TABS_IDS.partitions: {
162161
return <Partitions path={currentSchemaPath} />;
163162
}
164163
default: {

src/containers/Tenant/Diagnostics/DiagnosticsPages.ts

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,67 @@
1+
import type {TenantDiagnosticsTab} from '../../../store/reducers/tenant/types';
2+
import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../store/reducers/tenant/constants';
13
import {EPathType} from '../../../types/api/schema';
24

3-
export enum GeneralPagesIds {
4-
'overview' = 'Overview',
5-
'topQueries' = 'topQueries',
6-
'topShards' = 'topShards',
7-
'nodes' = 'Nodes',
8-
'tablets' = 'Tablets',
9-
'storage' = 'Storage',
10-
'network' = 'Network',
11-
'describe' = 'Describe',
12-
'hotKeys' = 'hotKeys',
13-
'graph' = 'graph',
14-
'consumers' = 'consumers',
15-
'partitions' = 'partitions',
16-
}
17-
185
type Page = {
19-
id: GeneralPagesIds;
6+
id: TenantDiagnosticsTab;
207
title: string;
218
};
229

2310
const overview = {
24-
id: GeneralPagesIds.overview,
11+
id: TENANT_DIAGNOSTICS_TABS_IDS.overview,
2512
title: 'Info',
2613
};
2714

2815
const topQueries = {
29-
id: GeneralPagesIds.topQueries,
16+
id: TENANT_DIAGNOSTICS_TABS_IDS.topQueries,
3017
title: 'Top queries',
3118
};
3219

3320
const topShards = {
34-
id: GeneralPagesIds.topShards,
21+
id: TENANT_DIAGNOSTICS_TABS_IDS.topShards,
3522
title: 'Top shards',
3623
};
3724

3825
const nodes = {
39-
id: GeneralPagesIds.nodes,
26+
id: TENANT_DIAGNOSTICS_TABS_IDS.nodes,
4027
title: 'Nodes',
4128
};
4229

4330
const tablets = {
44-
id: GeneralPagesIds.tablets,
31+
id: TENANT_DIAGNOSTICS_TABS_IDS.tablets,
4532
title: 'Tablets',
4633
};
4734
const storage = {
48-
id: GeneralPagesIds.storage,
35+
id: TENANT_DIAGNOSTICS_TABS_IDS.storage,
4936
title: 'Storage',
5037
};
5138
const network = {
52-
id: GeneralPagesIds.network,
39+
id: TENANT_DIAGNOSTICS_TABS_IDS.network,
5340
title: 'Network',
5441
};
5542

5643
const describe = {
57-
id: GeneralPagesIds.describe,
44+
id: TENANT_DIAGNOSTICS_TABS_IDS.describe,
5845
title: 'Describe',
5946
};
6047

6148
const hotKeys = {
62-
id: GeneralPagesIds.hotKeys,
49+
id: TENANT_DIAGNOSTICS_TABS_IDS.hotKeys,
6350
title: 'Hot keys',
6451
};
6552

6653
const graph = {
67-
id: GeneralPagesIds.graph,
54+
id: TENANT_DIAGNOSTICS_TABS_IDS.graph,
6855
title: 'Graph',
6956
};
7057

7158
const consumers = {
72-
id: GeneralPagesIds.consumers,
59+
id: TENANT_DIAGNOSTICS_TABS_IDS.consumers,
7360
title: 'Consumers',
7461
};
7562

7663
const partitions = {
77-
id: GeneralPagesIds.partitions,
64+
id: TENANT_DIAGNOSTICS_TABS_IDS.partitions,
7865
title: 'Partitions',
7966
};
8067

src/containers/Tenant/Diagnostics/TenantOverview/TenantOverview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import InfoViewer from '../../../../components/InfoViewer/InfoViewer';
99
import PoolUsage from '../../../../components/PoolUsage/PoolUsage';
1010
import {Tablet} from '../../../../components/Tablet';
1111

12-
import {getTenantInfo} from '../../../../store/reducers/tenant';
12+
import {getTenantInfo} from '../../../../store/reducers/tenant/tenant';
1313

1414
import {formatCPU} from '../../../../utils';
1515
import {bytesToGB} from '../../../../utils/utils';
@@ -191,7 +191,7 @@ class TenantOverview extends React.Component {
191191
}
192192

193193
function mapStateToProps(state) {
194-
const {tenant = {}, loading, data: {status} = {}} = state.tenant;
194+
const {tenant = {}, loading, error: {status} = {}} = state.tenant;
195195
const {autorefresh} = state.schema;
196196

197197
return {

src/containers/Tenant/Diagnostics/TopQueries/TopQueries.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ import type {KeyValueRow} from '../../../../types/api/query';
2222
import type {EPathType} from '../../../../types/api/schema';
2323
import type {ITopQueriesFilters} from '../../../../types/store/executeTopQueries';
2424
import type {IQueryResult} from '../../../../types/store/query';
25+
import type {TenantGeneralTab} from '../../../../store/reducers/tenant/types';
2526

27+
import {TENANT_GENERAL_TABS_IDS} from '../../../../store/reducers/tenant/constants';
2628
import {formatDateTime, formatNumber} from '../../../../utils';
2729
import {DEFAULT_TABLE_SETTINGS, HOUR_IN_SECONDS} from '../../../../utils/constants';
2830
import {useAutofetcher, useTypedSelector} from '../../../../utils/hooks';
2931
import {prepareQueryError} from '../../../../utils/query';
3032
import routes, {createHref} from '../../../../routes';
3133

3234
import {isColumnEntityType} from '../../utils/schema';
33-
import {TenantGeneralTabsIds, TenantTabsGroups} from '../../TenantPages';
35+
import {TenantTabsGroups} from '../../TenantPages';
3436

3537
import i18n from './i18n';
3638
import './TopQueries.scss';
@@ -86,7 +88,7 @@ const COLUMNS: Column<KeyValueRow>[] = [
8688

8789
interface TopQueriesProps {
8890
path: string;
89-
changeSchemaTab: (tab: TenantGeneralTabsIds) => void;
91+
changeSchemaTab: (tab: TenantGeneralTab) => void;
9092
type?: EPathType;
9193
}
9294

@@ -178,7 +180,7 @@ export const TopQueries = ({path, type}: TopQueriesProps) => {
178180

179181
const queryPath = createHref(routes.tenant, undefined, {
180182
...queryParams,
181-
[TenantTabsGroups.general]: TenantGeneralTabsIds.query,
183+
[TenantTabsGroups.general]: TENANT_GENERAL_TABS_IDS.query,
182184
});
183185

184186
history.push(queryPath);

src/containers/Tenant/ObjectGeneral/ObjectGeneral.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import cn from 'bem-cn-lite';
55
import {useThemeValue} from '@gravity-ui/uikit';
66

77
import type {EPathType} from '../../../types/api/schema';
8+
import {TENANT_GENERAL_TABS_IDS} from '../../../store/reducers/tenant/constants';
89

910
import QueryEditor from '../QueryEditor/QueryEditor';
1011
import Diagnostics from '../Diagnostics/Diagnostics';
1112

12-
import {TenantGeneralTabsIds} from '../TenantPages';
13-
1413
import './ObjectGeneral.scss';
1514

1615
const b = cn('object-general');
@@ -35,7 +34,7 @@ function ObjectGeneral(props: ObjectGeneralProps) {
3534
const renderTabContent = () => {
3635
const {type, additionalTenantInfo, additionalNodesInfo} = props;
3736
switch (generalTab) {
38-
case TenantGeneralTabsIds.query: {
37+
case TENANT_GENERAL_TABS_IDS.query: {
3938
return <QueryEditor path={tenantName as string} theme={theme} type={type} />;
4039
}
4140
default: {

src/containers/Tenant/ObjectSummary/ObjectSummary.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import {
3535
DEFAULT_SIZE_TENANT_SUMMARY_KEY,
3636
} from '../../../utils/constants';
3737
import {
38-
TenantGeneralTabsIds,
3938
TenantInfoTabsIds,
4039
TenantTabsGroups,
4140
TENANT_INFO_TABS,
@@ -48,7 +47,8 @@ import {
4847
PaneVisibilityToggleButtons,
4948
} from '../utils/paneVisibilityToggleHelpers';
5049
import {setShowPreview} from '../../../store/reducers/schema';
51-
import {setTopLevelTab} from '../../../store/reducers/tenant';
50+
import {setTopLevelTab} from '../../../store/reducers/tenant/tenant';
51+
import {TENANT_GENERAL_TABS_IDS} from '../../../store/reducers/tenant/constants';
5252

5353
import './ObjectSummary.scss';
5454

@@ -275,7 +275,7 @@ function ObjectSummary(props: ObjectSummaryProps) {
275275

276276
const onOpenPreview = () => {
277277
dispatch(setShowPreview(true));
278-
dispatch(setTopLevelTab(TenantGeneralTabsIds.query));
278+
dispatch(setTopLevelTab(TENANT_GENERAL_TABS_IDS.query));
279279
};
280280

281281
const renderCommonInfoControls = () => {

0 commit comments

Comments
 (0)