@@ -4,6 +4,7 @@ import type {RadioButtonOption} from '@gravity-ui/uikit';
44import { RadioButton } from '@gravity-ui/uikit' ;
55import { useHistory , useLocation } from 'react-router-dom' ;
66import { StringParam , useQueryParam } from 'use-query-params' ;
7+ import { z } from 'zod' ;
78
89import type { DateRangeValues } from '../../../../components/DateRange' ;
910import { DateRange } from '../../../../components/DateRange' ;
@@ -29,28 +30,28 @@ import './TopQueries.scss';
2930
3031const 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+
5455interface 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