Skip to content

Commit 5a4cda1

Browse files
committed
fix: use zod
1 parent 7b7848c commit 5a4cda1

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {RadioButtonOption} from '@gravity-ui/uikit';
44
import {RadioButton} from '@gravity-ui/uikit';
55
import {useHistory, useLocation} from 'react-router-dom';
66
import {StringParam, useQueryParam} from 'use-query-params';
7+
import {z} from 'zod';
78

89
import type {DateRangeValues} from '../../../../components/DateRange';
910
import {DateRange} from '../../../../components/DateRange';
@@ -29,28 +30,28 @@ import './TopQueries.scss';
2930

3031
const b = cn('kv-top-queries');
3132

32-
enum QueryModeIds {
33-
'top',
34-
'running',
35-
}
36-
37-
type QueryModeIdsType = keyof typeof QueryModeIds;
33+
const QueryModeIds = {
34+
top: 'top',
35+
running: 'running',
36+
};
3837

39-
const QUERY_MODE_OPTIONS: RadioButtonOption<QueryModeIdsType>[] = [
38+
const QUERY_MODE_OPTIONS: RadioButtonOption[] = [
4039
{
41-
value: 'top',
40+
value: QueryModeIds.top,
4241
get content() {
4342
return i18n('mode_top');
4443
},
4544
},
4645
{
47-
value: 'running',
46+
value: QueryModeIds.running,
4847
get content() {
4948
return i18n('mode_running');
5049
},
5150
},
5251
];
5352

53+
const queryModeSchema = z.nativeEnum(QueryModeIds).catch(QueryModeIds.top);
54+
5455
interface TopQueriesProps {
5556
tenantName: string;
5657
}
@@ -61,8 +62,7 @@ export const TopQueries = ({tenantName}: TopQueriesProps) => {
6162
const history = useHistory();
6263
const [_queryMode = 'top', setQueryMode] = useQueryParam('queryMode', StringParam);
6364

64-
const queryMode =
65-
_queryMode && Object.keys(QueryModeIds).includes(_queryMode) ? _queryMode : 'top';
65+
const queryMode = queryModeSchema.parse(_queryMode);
6666

6767
const isTopQueries = queryMode === 'top';
6868

0 commit comments

Comments
 (0)