1
1
import React from 'react' ;
2
2
3
+ import { Drawer , DrawerItem } from '@gravity-ui/navigation' ;
3
4
import type { RadioButtonOption } from '@gravity-ui/uikit' ;
4
5
import { RadioButton } from '@gravity-ui/uikit' ;
5
6
import { useHistory , useLocation } from 'react-router-dom' ;
@@ -16,10 +17,13 @@ import {
16
17
TENANT_PAGES_IDS ,
17
18
TENANT_QUERY_TABS_ID ,
18
19
} from '../../../../store/reducers/tenant/constants' ;
20
+ import type { KeyValueRow } from '../../../../types/api/query' ;
21
+ import { cn } from '../../../../utils/cn' ;
19
22
import { useTypedDispatch } from '../../../../utils/hooks' ;
20
23
import { useChangeInputWithConfirmation } from '../../../../utils/hooks/withConfirmation/useChangeInputWithConfirmation' ;
21
24
import { TenantTabsGroups , getTenantPath } from '../../TenantPages' ;
22
25
26
+ import { QueryDetails } from './QueryDetails' ;
23
27
import { RunningQueriesData } from './RunningQueriesData' ;
24
28
import { TopQueriesData } from './TopQueriesData' ;
25
29
import { TimeFrameIds } from './constants' ;
@@ -54,6 +58,9 @@ interface TopQueriesProps {
54
58
tenantName : string ;
55
59
}
56
60
61
+ const DRAWER_WIDTH_KEY = 'kv-top-queries-drawer-width' ;
62
+ const b = cn ( 'kv-top-queries' ) ;
63
+
57
64
export const TopQueries = ( { tenantName} : TopQueriesProps ) => {
58
65
const dispatch = useTypedDispatch ( ) ;
59
66
const location = useLocation ( ) ;
@@ -66,6 +73,13 @@ export const TopQueries = ({tenantName}: TopQueriesProps) => {
66
73
67
74
const isTopQueries = queryMode === QueryModeIds . top ;
68
75
76
+ const [ selectedRow , setSelectedRow ] = React . useState < KeyValueRow | null > ( null ) ;
77
+ const [ isDrawerVisible , setIsDrawerVisible ] = React . useState ( false ) ;
78
+ const [ drawerWidth , setDrawerWidth ] = React . useState ( ( ) => {
79
+ const savedWidth = localStorage . getItem ( DRAWER_WIDTH_KEY ) ;
80
+ return savedWidth ? Number ( savedWidth ) : 400 ;
81
+ } ) ;
82
+
69
83
const applyRowClick = React . useCallback (
70
84
( input : string ) => {
71
85
dispatch ( changeUserInput ( { input} ) ) ;
@@ -104,22 +118,65 @@ export const TopQueries = ({tenantName}: TopQueriesProps) => {
104
118
) ;
105
119
} , [ queryMode , setQueryMode ] ) ;
106
120
107
- return isTopQueries ? (
108
- < TopQueriesData
109
- tenantName = { tenantName }
110
- timeFrame = { timeFrame }
111
- renderQueryModeControl = { renderQueryModeControl }
112
- onRowClick = { onRowClick }
113
- handleTimeFrameChange = { handleTimeFrameChange }
114
- handleDateRangeChange = { handleDateRangeChange }
115
- handleTextSearchUpdate = { handleTextSearchUpdate }
116
- />
117
- ) : (
118
- < RunningQueriesData
119
- tenantName = { tenantName }
120
- renderQueryModeControl = { renderQueryModeControl }
121
- onRowClick = { onRowClick }
122
- handleTextSearchUpdate = { handleTextSearchUpdate }
123
- />
121
+ const handleRowClick = ( row : KeyValueRow ) => {
122
+ setSelectedRow ( row ) ;
123
+ setIsDrawerVisible ( true ) ;
124
+ } ;
125
+
126
+ const handleOpenInEditor = ( ) => {
127
+ if ( selectedRow ) {
128
+ onRowClick ( selectedRow . QueryText as string ) ;
129
+ }
130
+ } ;
131
+
132
+ const handleCloseDetails = ( ) => {
133
+ setIsDrawerVisible ( false ) ;
134
+ } ;
135
+
136
+ const handleResizeDrawer = ( width : number ) => {
137
+ setDrawerWidth ( width ) ;
138
+ localStorage . setItem ( DRAWER_WIDTH_KEY , width . toString ( ) ) ;
139
+ } ;
140
+
141
+ return (
142
+ < React . Fragment >
143
+ { isTopQueries ? (
144
+ < TopQueriesData
145
+ tenantName = { tenantName }
146
+ timeFrame = { timeFrame }
147
+ renderQueryModeControl = { renderQueryModeControl }
148
+ handleRowClick = { handleRowClick }
149
+ handleTimeFrameChange = { handleTimeFrameChange }
150
+ handleDateRangeChange = { handleDateRangeChange }
151
+ handleTextSearchUpdate = { handleTextSearchUpdate }
152
+ />
153
+ ) : (
154
+ < RunningQueriesData
155
+ tenantName = { tenantName }
156
+ renderQueryModeControl = { renderQueryModeControl }
157
+ handleRowClick = { handleRowClick }
158
+ handleTextSearchUpdate = { handleTextSearchUpdate }
159
+ />
160
+ ) }
161
+ < Drawer onEscape = { handleCloseDetails } onVeilClick = { handleCloseDetails } hideVeil >
162
+ < DrawerItem
163
+ id = "query-details"
164
+ visible = { isDrawerVisible }
165
+ resizable
166
+ width = { drawerWidth }
167
+ onResize = { handleResizeDrawer }
168
+ direction = "right"
169
+ className = { b ( 'drawer-item' ) }
170
+ >
171
+ { selectedRow && (
172
+ < QueryDetails
173
+ row = { selectedRow }
174
+ onClose = { handleCloseDetails }
175
+ onOpenInEditor = { handleOpenInEditor }
176
+ />
177
+ ) }
178
+ </ DrawerItem >
179
+ </ Drawer >
180
+ </ React . Fragment >
124
181
) ;
125
182
} ;
0 commit comments