-
Notifications
You must be signed in to change notification settings - Fork 17
feat(Diagnostics): display tablets as table #852
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| import {ArrowsRotateRight} from '@gravity-ui/icons'; | ||
| import type {Column as DataTableColumn} from '@gravity-ui/react-data-table'; | ||
| import {Icon, Label, Text} from '@gravity-ui/uikit'; | ||
| import {skipToken} from '@reduxjs/toolkit/query'; | ||
|
|
||
| import {ButtonWithConfirmDialog} from '../../../../components/ButtonWithConfirmDialog/ButtonWithConfirmDialog'; | ||
| import {EntityStatus} from '../../../../components/EntityStatus/EntityStatus'; | ||
| import {ResponseError} from '../../../../components/Errors/ResponseError'; | ||
| import {InternalLink} from '../../../../components/InternalLink'; | ||
| import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable'; | ||
| import {TableSkeleton} from '../../../../components/TableSkeleton/TableSkeleton'; | ||
| import routes, {createHref} from '../../../../routes'; | ||
| import {selectTabletsWithFqdn, tabletsApi} from '../../../../store/reducers/tablets'; | ||
| import {ETabletState} from '../../../../types/api/tablet'; | ||
| import type {TTabletStateInfo} from '../../../../types/api/tablet'; | ||
| import type {TabletsApiRequestParams} from '../../../../types/store/tablets'; | ||
| import {cn} from '../../../../utils/cn'; | ||
| import {DEFAULT_TABLE_SETTINGS} from '../../../../utils/constants'; | ||
| import {calcUptime} from '../../../../utils/dataFormatters/dataFormatters'; | ||
| import {useTypedDispatch, useTypedSelector} from '../../../../utils/hooks'; | ||
| import {mapTabletStateToLabelTheme} from '../../../../utils/tablet'; | ||
| import {getDefaultNodePath} from '../../../Node/NodePages'; | ||
|
|
||
| import i18n from './i18n'; | ||
|
|
||
| const b = cn('tablets-table'); | ||
|
|
||
| const columns: DataTableColumn<TTabletStateInfo & {fqdn?: string}>[] = [ | ||
| { | ||
| name: 'Type', | ||
| get header() { | ||
| return i18n('Type'); | ||
| }, | ||
| render: ({row}) => { | ||
| return ( | ||
| <span> | ||
| {row.Type} {row.Leader ? <Text color="secondary">leader</Text> : ''} | ||
| </span> | ||
| ); | ||
| }, | ||
| }, | ||
| { | ||
| name: 'TabletId', | ||
| get header() { | ||
| return i18n('Tablet'); | ||
| }, | ||
| render: ({row}) => { | ||
| const tabletPath = | ||
| row.TabletId && | ||
| createHref(routes.tablet, {id: row.TabletId}, {nodeId: row.NodeId, type: row.Type}); | ||
|
|
||
| return <InternalLink to={tabletPath}>{row.TabletId}</InternalLink>; | ||
| }, | ||
| }, | ||
| { | ||
| name: 'State', | ||
| get header() { | ||
| return i18n('State'); | ||
| }, | ||
| render: ({row}) => { | ||
| return <Label theme={mapTabletStateToLabelTheme(row.State)}>{row.State}</Label>; | ||
| }, | ||
| }, | ||
| { | ||
| name: 'NodeId', | ||
| get header() { | ||
| return i18n('Node ID'); | ||
| }, | ||
| render: ({row}) => { | ||
| const nodePath = row.NodeId === undefined ? undefined : getDefaultNodePath(row.NodeId); | ||
| return <InternalLink to={nodePath}>{row.NodeId}</InternalLink>; | ||
| }, | ||
| align: 'right', | ||
| }, | ||
| { | ||
| name: 'FQDN', | ||
| get header() { | ||
| return i18n('Node FQDN'); | ||
| }, | ||
| render: ({row}) => { | ||
| if (!row.fqdn) { | ||
| return <span>—</span>; | ||
| } | ||
| return <EntityStatus name={row.fqdn} showStatus={false} hasClipboardButton />; | ||
| }, | ||
| }, | ||
| { | ||
| name: 'Generation', | ||
| get header() { | ||
| return i18n('Generation'); | ||
| }, | ||
| align: 'right', | ||
| }, | ||
| { | ||
| name: 'Uptime', | ||
| get header() { | ||
| return i18n('Uptime'); | ||
| }, | ||
| render: ({row}) => { | ||
| return calcUptime(row.ChangeTime); | ||
| }, | ||
| sortAccessor: (row) => -Number(row.ChangeTime), | ||
artemmufazalov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| align: 'right', | ||
| }, | ||
| { | ||
| name: 'Actions', | ||
| sortable: false, | ||
| resizeable: false, | ||
| header: '', | ||
| render: ({row}) => { | ||
| return <TabletActions {...row} />; | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| function TabletActions(tablet: TTabletStateInfo) { | ||
| const isDisabledRestart = tablet.State === ETabletState.Stopped; | ||
| const dispatch = useTypedDispatch(); | ||
| return ( | ||
| <ButtonWithConfirmDialog | ||
| buttonView="outlined" | ||
| dialogContent={i18n('dialog.kill')} | ||
| onConfirmAction={() => { | ||
| return window.api.killTablet(tablet.TabletId); | ||
| }} | ||
| onConfirmActionSuccess={() => { | ||
| dispatch(tabletsApi.util.invalidateTags(['All'])); | ||
| }} | ||
| buttonDisabled={isDisabledRestart} | ||
| > | ||
| <Icon data={ArrowsRotateRight} /> | ||
| </ButtonWithConfirmDialog> | ||
| ); | ||
| } | ||
|
|
||
| interface TabletsProps { | ||
| path?: string; | ||
| className?: string; | ||
| } | ||
|
|
||
| export function Tablets({path, className}: TabletsProps) { | ||
| const {autorefresh} = useTypedSelector((state) => state.schema); | ||
|
|
||
| let params: TabletsApiRequestParams | typeof skipToken = skipToken; | ||
| if (path) { | ||
| params = {path}; | ||
| } | ||
| const {currentData, isFetching, error} = tabletsApi.useGetTabletsInfoQuery(params, { | ||
| pollingInterval: autorefresh, | ||
| }); | ||
|
|
||
| const loading = isFetching && currentData === undefined; | ||
| const tablets = useTypedSelector((state) => selectTabletsWithFqdn(state, path || '')); | ||
|
|
||
| if (loading) { | ||
| return <TableSkeleton />; | ||
| } | ||
| if (error) { | ||
| return <ResponseError error={error} />; | ||
| } | ||
|
|
||
| return ( | ||
| <div className={b(null, className)}> | ||
| <ResizeableDataTable | ||
| columns={columns} | ||
| data={tablets} | ||
| settings={DEFAULT_TABLE_SETTINGS} | ||
| emptyDataMessage={i18n('noTabletsData')} | ||
| /> | ||
| </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,11 @@ | ||
| { | ||
| "noTabletsData": "No tablets data", | ||
| "Type": "Type", | ||
| "Tablet": "Tablet", | ||
| "State": "State", | ||
| "Node ID": "Node ID", | ||
| "Node FQDN": "Node FQDN", | ||
| "Generation": "Generation", | ||
| "Uptime": "Uptime", | ||
| "dialog.kill": "The tablet will be restarted. Do you want to proceed?" | ||
| } |
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,7 @@ | ||
| import {registerKeysets} from '../../../../../utils/i18n'; | ||
|
|
||
| import en from './en.json'; | ||
|
|
||
| const COMPONENT = 'ydb-tablets-table'; | ||
|
|
||
| export default registerKeysets(COMPONENT, {en}); |
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
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.
Why you define header property this way and not just
header: i18n('Type')?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.
Theoretically, i18n should be called inside components/actions.