Skip to content

Commit 3124bdb

Browse files
feat(HotKeys): add help card (#861)
1 parent 496514b commit 3124bdb

File tree

5 files changed

+78
-31
lines changed

5 files changed

+78
-31
lines changed
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
@import '../../../../styles/mixins.scss';
22

33
.ydb-hot-keys {
4-
&__table {
5-
@include freeze-nth-column(1);
6-
}
7-
84
&__primary-key-column {
95
display: flex;
106
align-items: center;
117
gap: 5px;
128
}
9+
10+
&__help-card {
11+
position: sticky;
12+
left: 0;
13+
14+
margin-bottom: 20px;
15+
padding: 20px 40px 20px 20px;
16+
17+
&__close-button {
18+
position: absolute;
19+
top: 5px;
20+
right: 5px;
21+
}
22+
}
1323
}

src/containers/Tenant/Diagnostics/HotKeys/HotKeys.tsx

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React from 'react';
22

3+
import {Xmark} from '@gravity-ui/icons';
34
import DataTable from '@gravity-ui/react-data-table';
45
import 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

78
import {ResponseError} from '../../../../components/Errors/ResponseError';
89
import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable';
@@ -15,8 +16,8 @@ import {
1516
import type {IResponseError} from '../../../../types/api/error';
1617
import type {HotKey} from '../../../../types/api/hotkeys';
1718
import {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

2122
import 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 {
6465
export 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
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
22
"hot-keys-collecting": "Please wait a little while we are collecting hot keys samples...",
3-
"no-data": "No information about hot keys"
3+
"no-data": "No information about hot keys",
4+
5+
"help": "Hot keys contains a list of table primary key values that are accessed most often. Sample is collected upon request to the tab during 5s time interval. Samples column indicates how many requests to the particular key value were registered during collection phase."
46
}

src/services/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
BINARY_DATA_IN_PLAIN_TEXT_DISPLAY,
66
ENABLE_AUTOCOMPLETE,
77
INVERTED_DISKS_KEY,
8+
IS_HOTKEYS_HELP_HIDDDEN_KEY,
89
LANGUAGE_KEY,
910
LAST_USED_QUERY_ACTION_KEY,
1011
PARTITIONS_HIDDEN_COLUMNS_KEY,
@@ -40,6 +41,7 @@ export const DEFAULT_USER_SETTINGS = {
4041
[USE_CLUSTER_BALANCER_AS_BACKEND_KEY]: true,
4142
[ENABLE_AUTOCOMPLETE]: false,
4243
[AUTOCOMPLETE_ON_ENTER]: true,
44+
[IS_HOTKEYS_HELP_HIDDDEN_KEY]: false,
4345
} as const satisfies SettingsObject;
4446

4547
class SettingsManager {

src/utils/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,5 @@ export const USE_CLUSTER_BALANCER_AS_BACKEND_KEY = 'useClusterBalancerAsBacked';
137137
export const ENABLE_AUTOCOMPLETE = 'enableAutocomplete';
138138

139139
export const AUTOCOMPLETE_ON_ENTER = 'autocompleteOnEnter';
140+
141+
export const IS_HOTKEYS_HELP_HIDDDEN_KEY = 'isHotKeysHelpHidden';

0 commit comments

Comments
 (0)