Skip to content

Commit 6cb6e80

Browse files
committed
fix: review fixes
1 parent 867a6cc commit 6cb6e80

File tree

4 files changed

+25
-42
lines changed

4 files changed

+25
-42
lines changed

src/containers/Tenant/Diagnostics/TenantOverview/TenantCpu/useTenantCpuQueryParams.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {StringParam, useQueryParams} from 'use-query-params';
22

33
import {
4-
TENANT_CPU_NODES_MODE_IDS,
5-
TENANT_CPU_TABS_IDS,
6-
} from '../../../../../store/reducers/tenant/constants';
4+
tenantCpuTabSchema,
5+
tenantNodesModeSchema,
6+
} from '../../../../../store/reducers/tenant/types';
77
import type {TenantCpuTab, TenantNodesMode} from '../../../../../store/reducers/tenant/types';
88

99
export function useTenantCpuQueryParams() {
@@ -12,27 +12,8 @@ export function useTenantCpuQueryParams() {
1212
nodesMode: StringParam,
1313
});
1414

15-
// Parse and validate cpuTab with fallback to nodes
16-
const cpuTab: TenantCpuTab = (() => {
17-
if (!queryParams.cpuTab) {
18-
return TENANT_CPU_TABS_IDS.nodes;
19-
}
20-
const validTabs = Object.values(TENANT_CPU_TABS_IDS) as string[];
21-
return validTabs.includes(queryParams.cpuTab)
22-
? (queryParams.cpuTab as TenantCpuTab)
23-
: TENANT_CPU_TABS_IDS.nodes;
24-
})();
25-
26-
// Parse and validate nodesMode with fallback to load
27-
const nodesMode: TenantNodesMode = (() => {
28-
if (!queryParams.nodesMode) {
29-
return TENANT_CPU_NODES_MODE_IDS.load;
30-
}
31-
const validModes = Object.values(TENANT_CPU_NODES_MODE_IDS) as string[];
32-
return validModes.includes(queryParams.nodesMode)
33-
? (queryParams.nodesMode as TenantNodesMode)
34-
: TENANT_CPU_NODES_MODE_IDS.load;
35-
})();
15+
const cpuTab: TenantCpuTab = tenantCpuTabSchema.parse(queryParams.cpuTab);
16+
const nodesMode: TenantNodesMode = tenantNodesModeSchema.parse(queryParams.nodesMode);
3617

3718
const handleCpuTabChange = (value: TenantCpuTab) => {
3819
setQueryParams({cpuTab: value}, 'replaceIn');

src/containers/Tenant/Diagnostics/TenantOverview/TenantStorage/ProgressWrapper.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ export function ProgressWrapper({
4242
const clampedFillWidth = Math.min(fillWidth, MAX_PERCENTAGE);
4343

4444
const [valueText, capacityText] = React.useMemo(() => {
45-
if (formatValues) {
46-
return formatValues(Number(value), Number(capacity));
47-
}
48-
return [value, capacity];
45+
return formatValues(Number(value), Number(capacity));
4946
}, [formatValues, value, capacity]);
5047

5148
const displayText = React.useMemo(() => {

src/containers/Tenant/Diagnostics/TenantOverview/TenantStorage/useTenantStorageQueryParams.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
import {StringParam, useQueryParams} from 'use-query-params';
22

3-
import {TENANT_STORAGE_TABS_IDS} from '../../../../../store/reducers/tenant/constants';
3+
import {tenantStorageTabSchema} from '../../../../../store/reducers/tenant/types';
44
import type {TenantStorageTab} from '../../../../../store/reducers/tenant/types';
55

66
export function useTenantStorageQueryParams() {
77
const [queryParams, setQueryParams] = useQueryParams({
88
storageTab: StringParam,
99
});
1010

11-
// Parse and validate storageTab with fallback to tables
12-
const storageTab: TenantStorageTab = (() => {
13-
if (!queryParams.storageTab) {
14-
return TENANT_STORAGE_TABS_IDS.tables;
15-
}
16-
const validTabs = Object.values(TENANT_STORAGE_TABS_IDS) as string[];
17-
return validTabs.includes(queryParams.storageTab)
18-
? (queryParams.storageTab as TenantStorageTab)
19-
: TENANT_STORAGE_TABS_IDS.tables;
20-
})();
11+
const storageTab: TenantStorageTab = tenantStorageTabSchema.parse(queryParams.storageTab);
2112

2213
const handleStorageTabChange = (value: TenantStorageTab) => {
2314
setQueryParams({storageTab: value}, 'replaceIn');

src/store/reducers/tenant/types.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,34 @@ import {z} from 'zod';
22

33
import type {ValueOf} from '../../../types/common';
44

5-
import {TENANT_PAGES_IDS} from './constants';
6-
import type {
5+
import {
76
TENANT_CPU_NODES_MODE_IDS,
87
TENANT_CPU_TABS_IDS,
8+
TENANT_PAGES_IDS,
9+
TENANT_STORAGE_TABS_IDS,
10+
} from './constants';
11+
import type {
912
TENANT_DIAGNOSTICS_TABS_IDS,
1013
TENANT_METRICS_TABS_IDS,
1114
TENANT_QUERY_TABS_ID,
12-
TENANT_STORAGE_TABS_IDS,
1315
TENANT_SUMMARY_TABS_IDS,
1416
} from './constants';
1517

1618
export const tenantPageSchema = z.nativeEnum(TENANT_PAGES_IDS);
1719
export type TenantPage = z.infer<typeof tenantPageSchema>;
1820

21+
export const tenantStorageTabSchema = z
22+
.nativeEnum(TENANT_STORAGE_TABS_IDS)
23+
.catch(TENANT_STORAGE_TABS_IDS.tables);
24+
25+
export const tenantCpuTabSchema = z
26+
.nativeEnum(TENANT_CPU_TABS_IDS)
27+
.catch(TENANT_CPU_TABS_IDS.nodes);
28+
29+
export const tenantNodesModeSchema = z
30+
.nativeEnum(TENANT_CPU_NODES_MODE_IDS)
31+
.catch(TENANT_CPU_NODES_MODE_IDS.load);
32+
1933
export type TenantQueryTab = ValueOf<typeof TENANT_QUERY_TABS_ID>;
2034
export type TenantDiagnosticsTab = ValueOf<typeof TENANT_DIAGNOSTICS_TABS_IDS>;
2135
export type TenantSummaryTab = ValueOf<typeof TENANT_SUMMARY_TABS_IDS>;

0 commit comments

Comments
 (0)