11import React from 'react' ;
22
3+ import { Xmark } from '@gravity-ui/icons' ;
34import DataTable from '@gravity-ui/react-data-table' ;
45import type { Column } from '@gravity-ui/react-data-table' ;
5- import { Icon } from '@gravity-ui/uikit' ;
6+ import { Button , Card , Icon } from '@gravity-ui/uikit' ;
67
78import { ResponseError } from '../../../../components/Errors/ResponseError' ;
89import { ResizeableDataTable } from '../../../../components/ResizeableDataTable/ResizeableDataTable' ;
@@ -15,8 +16,8 @@ import {
1516import type { IResponseError } from '../../../../types/api/error' ;
1617import type { HotKey } from '../../../../types/api/hotkeys' ;
1718import { cn } from '../../../../utils/cn' ;
18- import { DEFAULT_TABLE_SETTINGS } from '../../../../utils/constants' ;
19- import { useTypedDispatch , useTypedSelector } from '../../../../utils/hooks' ;
19+ import { DEFAULT_TABLE_SETTINGS , IS_HOTKEYS_HELP_HIDDDEN_KEY } from '../../../../utils/constants' ;
20+ import { useSetting , useTypedDispatch , useTypedSelector } from '../../../../utils/hooks' ;
2021
2122import i18n from './i18n' ;
2223
@@ -46,14 +47,14 @@ const getHotKeysColumns = (keyColumnsIds: string[] = []): Column<HotKey>[] => {
4647 } ) ) ;
4748
4849 return [
50+ ...keysColumns ,
4951 {
5052 name : tableColumnsIds . accessSample ,
5153 header : 'Samples' ,
5254 render : ( { row} ) => row . accessSample ,
5355 align : DataTable . RIGHT ,
5456 sortable : false ,
5557 } ,
56- ...keysColumns ,
5758 ] ;
5859} ;
5960
@@ -64,6 +65,8 @@ interface HotKeysProps {
6465export function HotKeys ( { path} : HotKeysProps ) {
6566 const dispatch = useTypedDispatch ( ) ;
6667
68+ const [ helpHidden , setHelpHidden ] = useSetting ( IS_HOTKEYS_HELP_HIDDDEN_KEY ) ;
69+
6770 const collectSamplesTimerRef = React . useRef < ReturnType < typeof setTimeout > > ( ) ;
6871
6972 const { loading, wasLoaded, data, error} = useTypedSelector ( ( state ) => state . hotKeys ) ;
@@ -118,29 +121,57 @@ export function HotKeys({path}: HotKeysProps) {
118121 fetchData ( ) ;
119122 } , [ dispatch , path ] ) ;
120123
121- // It takes a while to collect hot keys. Display explicit status message, while collecting
122- if ( ( loading && ! wasLoaded ) || schemaLoading ) {
123- return < div > { i18n ( 'hot-keys-collecting' ) } </ div > ;
124- }
125-
126- if ( error ) {
127- return < ResponseError error = { error } /> ;
128- }
129-
130- if ( ! data ) {
131- return < div > { i18n ( 'no-data' ) } </ div > ;
132- }
124+ const renderContent = ( ) => {
125+ // It takes a while to collect hot keys. Display explicit status message, while collecting
126+ if ( ( loading && ! wasLoaded ) || schemaLoading ) {
127+ return < div > { i18n ( 'hot-keys-collecting' ) } </ div > ;
128+ }
129+
130+ if ( error ) {
131+ return < ResponseError error = { error } /> ;
132+ }
133+
134+ if ( ! data ) {
135+ return < div > { i18n ( 'no-data' ) } </ div > ;
136+ }
137+
138+ return (
139+ < ResizeableDataTable
140+ wrapperClassName = { b ( 'table' ) }
141+ columns = { tableColumns }
142+ data = { data }
143+ settings = { DEFAULT_TABLE_SETTINGS }
144+ initialSortOrder = { {
145+ columnId : tableColumnsIds . accessSample ,
146+ order : DataTable . DESCENDING ,
147+ } }
148+ />
149+ ) ;
150+ } ;
151+
152+ const renderHelpCard = ( ) => {
153+ if ( helpHidden ) {
154+ return null ;
155+ }
156+
157+ return (
158+ < Card theme = "info" view = "filled" type = "container" className = { b ( 'help-card' ) } >
159+ { i18n ( 'help' ) }
160+ < Button
161+ className = { b ( 'help-card__close-button' ) }
162+ view = "flat"
163+ onClick = { ( ) => setHelpHidden ( true ) }
164+ >
165+ < Icon data = { Xmark } size = { 18 } />
166+ </ Button >
167+ </ Card >
168+ ) ;
169+ } ;
133170
134171 return (
135- < ResizeableDataTable
136- wrapperClassName = { b ( 'table' ) }
137- columns = { tableColumns }
138- data = { data }
139- settings = { DEFAULT_TABLE_SETTINGS }
140- initialSortOrder = { {
141- columnId : tableColumnsIds . accessSample ,
142- order : DataTable . DESCENDING ,
143- } }
144- />
172+ < React . Fragment >
173+ { renderHelpCard ( ) }
174+ { renderContent ( ) }
175+ </ React . Fragment >
145176 ) ;
146177}
0 commit comments