-
Notifications
You must be signed in to change notification settings - Fork 17
feat(HotKeys): revive #722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| import {useEffect, useMemo, useRef} from 'react'; | ||
| import {useDispatch} from 'react-redux'; | ||
| import DataTable, {type Column} from '@gravity-ui/react-data-table'; | ||
|
|
||
| import type {HotKey} from '../../../../types/api/hotkeys'; | ||
| import type {IResponseError} from '../../../../types/api/error'; | ||
| import {Icon} from '../../../../components/Icon'; | ||
| import {ResponseError} from '../../../../components/Errors/ResponseError'; | ||
| import {useTypedSelector} from '../../../../utils/hooks'; | ||
| import {cn} from '../../../../utils/cn'; | ||
| import {DEFAULT_TABLE_SETTINGS} from '../../../../utils/constants'; | ||
| import { | ||
| setHotKeysData, | ||
| setHotKeysDataWasNotLoaded, | ||
| setHotKeysError, | ||
| setHotKeysLoading, | ||
| } from '../../../../store/reducers/hotKeys/hotKeys'; | ||
|
|
||
| import './HotKeys.scss'; | ||
| import i18n from './i18n'; | ||
|
|
||
| const b = cn('ydb-hot-keys'); | ||
|
|
||
| const tableColumnsIds = { | ||
| accessSample: 'accessSample', | ||
| keyValues: 'keyValues', | ||
| } as const; | ||
|
|
||
| const getHotKeysColumns = (keyColumnsIds: string[] = []): Column<HotKey>[] => { | ||
| const keysColumns: Column<HotKey>[] = keyColumnsIds.map((col, index) => ({ | ||
| name: col, | ||
| header: ( | ||
| <div className={b('primary-key-column')}> | ||
| <Icon name="key" viewBox="0 0 12 7" width={12} height={7} /> | ||
| {col} | ||
| </div> | ||
| ), | ||
| render: ({row}) => row.keyValues[index], | ||
| align: DataTable.RIGHT, | ||
| sortable: false, | ||
| })); | ||
|
|
||
| return [ | ||
| { | ||
| name: tableColumnsIds.accessSample, | ||
| header: 'Samples', | ||
| render: ({row}) => row.accessSample, | ||
| align: DataTable.RIGHT, | ||
| sortable: false, | ||
| }, | ||
| ...keysColumns, | ||
| ]; | ||
| }; | ||
|
|
||
| interface HotKeysProps { | ||
| path: string; | ||
| } | ||
|
|
||
| export function HotKeys({path}: HotKeysProps) { | ||
| const dispatch = useDispatch(); | ||
|
|
||
| const collectSamplesTimerRef = useRef<ReturnType<typeof setTimeout>>(); | ||
|
|
||
| const {loading, wasLoaded, data, error} = useTypedSelector((state) => state.hotKeys); | ||
| const {loading: schemaLoading, data: schemaData} = useTypedSelector((state) => state.schema); | ||
|
|
||
| const keyColumnsIds = schemaData[path]?.PathDescription?.Table?.KeyColumnNames; | ||
|
|
||
| const tableColumns = useMemo(() => { | ||
| return getHotKeysColumns(keyColumnsIds); | ||
| }, [keyColumnsIds]); | ||
|
|
||
| useEffect(() => { | ||
| const fetchHotkeys = async (enableSampling: boolean) => { | ||
| // Set hotkeys error, but not data, since data is set conditionally | ||
| try { | ||
| const response = await window.api.getHotKeys(path, enableSampling); | ||
| return response; | ||
| } catch (err) { | ||
| dispatch(setHotKeysError(err as IResponseError)); | ||
| return undefined; | ||
| } | ||
| }; | ||
|
|
||
| const fetchData = async () => { | ||
| // If there is previous pending request for samples, cancel it | ||
| if (collectSamplesTimerRef.current !== undefined) { | ||
| window.clearInterval(collectSamplesTimerRef.current); | ||
| } | ||
|
|
||
| dispatch(setHotKeysDataWasNotLoaded()); | ||
| dispatch(setHotKeysLoading()); | ||
|
|
||
| // Send request that will trigger hot keys sampling (enable_sampling = true) | ||
| const initialResponse = await fetchHotkeys(true); | ||
|
|
||
| // If there are hotkeys in the initial request (hotkeys was collected before) | ||
| // we could just use colleted samples (collected hotkeys are stored only for 30 seconds) | ||
| if (initialResponse && initialResponse.hotkeys) { | ||
| dispatch(setHotKeysData(initialResponse)); | ||
| } else if (initialResponse) { | ||
| // Else wait for 5 seconds, while hot keys are being collected | ||
| // And request these samples (enable_sampling = false) | ||
| const timer = setTimeout(async () => { | ||
| const responseWithSamples = await fetchHotkeys(false); | ||
| if (responseWithSamples) { | ||
| dispatch(setHotKeysData(responseWithSamples)); | ||
| } | ||
| }, 5000); | ||
| collectSamplesTimerRef.current = timer; | ||
| } | ||
| }; | ||
| fetchData(); | ||
| }, [dispatch, path]); | ||
|
|
||
| // It takes a while to collect hot keys. Display explicit status message, while collecting | ||
| if ((loading && !wasLoaded) || schemaLoading) { | ||
| return <div>{i18n('hot-keys-collecting')}</div>; | ||
| } | ||
|
|
||
| if (error) { | ||
| return <ResponseError error={error} />; | ||
| } | ||
|
|
||
| if (!data) { | ||
| return <div>{i18n('no-data')}</div>; | ||
| } | ||
|
|
||
| return ( | ||
| <div className={b('table-content')}> | ||
| <DataTable | ||
| columns={tableColumns} | ||
| data={data} | ||
| settings={DEFAULT_TABLE_SETTINGS} | ||
| theme="yandex-cloud" | ||
| initialSortOrder={{ | ||
| columnId: tableColumnsIds.accessSample, | ||
| order: DataTable.DESCENDING, | ||
| }} | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "hot-keys-collecting": "Please wait a little while we are collecting hot keys samples...", | ||
| "no-data": "No information about hot keys" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import {i18n, Lang} from '../../../../../utils/i18n'; | ||
|
|
||
| import en from './en.json'; | ||
|
|
||
| const COMPONENT = 'ydb-hot-keys'; | ||
|
|
||
| i18n.registerKeyset(Lang.En, COMPONENT, en); | ||
|
|
||
| export default i18n.keyset(COMPONENT); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although there is no autorefresh for hotkeys tab, I made separate actions to keep flow similar to other components