-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat: add ShardsTable to componentsRegistry #1993
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 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 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 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,41 @@ | ||
import React from 'react'; | ||
|
||
import type {KeyValueRow} from '../../types/api/query'; | ||
import type {ResizeableDataTableProps} from '../ResizeableDataTable/ResizeableDataTable'; | ||
import {ResizeableDataTable} from '../ResizeableDataTable/ResizeableDataTable'; | ||
|
||
import {shardsColumnIdToGetColumn} from './columns'; | ||
import type {TopShardsColumnId} from './constants'; | ||
import {TOP_SHARDS_COLUMNS_WIDTH_LS_KEY, isSortableTopShardsColumn} from './constants'; | ||
|
||
export interface ShardsTableProps | ||
extends Omit<ResizeableDataTableProps<KeyValueRow>, 'columnsWidthLSKey' | 'columns'> { | ||
columnsIds: TopShardsColumnId[]; | ||
database: string; | ||
schemaPath?: string; | ||
} | ||
|
||
export function ShardsTable({columnsIds, schemaPath, database, ...props}: ShardsTableProps) { | ||
const columns = React.useMemo( | ||
() => | ||
columnsIds | ||
.filter((id) => id in shardsColumnIdToGetColumn) | ||
.map((id) => { | ||
const column = shardsColumnIdToGetColumn[id]({database, schemaPath}); | ||
|
||
return { | ||
...column, | ||
sortable: isSortableTopShardsColumn(column.name), | ||
}; | ||
}), | ||
[columnsIds, database, schemaPath], | ||
); | ||
|
||
return ( | ||
<ResizeableDataTable | ||
{...props} | ||
columnsWidthLSKey={TOP_SHARDS_COLUMNS_WIDTH_LS_KEY} | ||
columns={columns} | ||
/> | ||
); | ||
} |
This file contains 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,113 @@ | ||
import DataTable from '@gravity-ui/react-data-table'; | ||
|
||
import {getDefaultNodePath} from '../../containers/Node/NodePages'; | ||
import {EMPTY_DATA_PLACEHOLDER} from '../../utils/constants'; | ||
import {formatNumber, roundToPrecision} from '../../utils/dataFormatters/dataFormatters'; | ||
import {getUsageSeverity} from '../../utils/generateEvaluator'; | ||
import {InternalLink} from '../InternalLink'; | ||
import {LinkToSchemaObject} from '../LinkToSchemaObject/LinkToSchemaObject'; | ||
import {TabletNameWrapper} from '../TabletNameWrapper/TabletNameWrapper'; | ||
import {UsageLabel} from '../UsageLabel/UsageLabel'; | ||
|
||
import type {TopShardsColumnId} from './constants'; | ||
import {TOP_SHARDS_COLUMNS_IDS, TOP_SHARDS_COLUMNS_TITLES} from './constants'; | ||
import type {GetShardsColumn} from './types'; | ||
import {prepareDateTimeValue} from './utils'; | ||
|
||
export const getPathColumn: GetShardsColumn = ({schemaPath = ''}) => { | ||
return { | ||
name: TOP_SHARDS_COLUMNS_IDS.Path, | ||
header: TOP_SHARDS_COLUMNS_TITLES.Path, | ||
render: ({row}) => { | ||
// row.Path - relative schema path | ||
return <LinkToSchemaObject path={schemaPath + row.Path}>{row.Path}</LinkToSchemaObject>; | ||
}, | ||
width: 300, | ||
}; | ||
}; | ||
export const getDataSizeColumn: GetShardsColumn = () => { | ||
return { | ||
name: TOP_SHARDS_COLUMNS_IDS.DataSize, | ||
header: TOP_SHARDS_COLUMNS_TITLES.DataSize, | ||
render: ({row}) => { | ||
return formatNumber(row.DataSize); | ||
}, | ||
align: DataTable.RIGHT, | ||
}; | ||
}; | ||
export const getTabletIdColumn: GetShardsColumn = () => { | ||
return { | ||
name: TOP_SHARDS_COLUMNS_IDS.TabletId, | ||
header: TOP_SHARDS_COLUMNS_TITLES.TabletId, | ||
render: ({row}) => { | ||
if (!row.TabletId) { | ||
return EMPTY_DATA_PLACEHOLDER; | ||
} | ||
return <TabletNameWrapper tabletId={row.TabletId} />; | ||
}, | ||
width: 220, | ||
}; | ||
}; | ||
export const getNodeIdColumn: GetShardsColumn = () => { | ||
return { | ||
name: TOP_SHARDS_COLUMNS_IDS.NodeId, | ||
header: TOP_SHARDS_COLUMNS_TITLES.NodeId, | ||
render: ({row}) => { | ||
if (!row.NodeId) { | ||
return EMPTY_DATA_PLACEHOLDER; | ||
} | ||
return <InternalLink to={getDefaultNodePath(row.NodeId)}>{row.NodeId}</InternalLink>; | ||
}, | ||
align: DataTable.RIGHT, | ||
}; | ||
}; | ||
export const getCpuCoresColumn: GetShardsColumn = () => { | ||
return { | ||
name: TOP_SHARDS_COLUMNS_IDS.CPUCores, | ||
header: TOP_SHARDS_COLUMNS_TITLES.CPUCores, | ||
render: ({row}) => { | ||
const usage = Number(row.CPUCores) * 100 || 0; | ||
return ( | ||
<UsageLabel value={roundToPrecision(usage, 2)} theme={getUsageSeverity(usage)} /> | ||
); | ||
}, | ||
align: DataTable.RIGHT, | ||
width: 110, | ||
resizeMinWidth: 110, | ||
}; | ||
}; | ||
export const getInFlightTxCountColumn: GetShardsColumn = () => { | ||
return { | ||
name: TOP_SHARDS_COLUMNS_IDS.InFlightTxCount, | ||
header: TOP_SHARDS_COLUMNS_TITLES.InFlightTxCount, | ||
render: ({row}) => formatNumber(row.InFlightTxCount), | ||
align: DataTable.RIGHT, | ||
}; | ||
}; | ||
export const getPeakTimeColumn: GetShardsColumn = () => { | ||
return { | ||
name: TOP_SHARDS_COLUMNS_IDS.PeakTime, | ||
render: ({row}) => { | ||
return prepareDateTimeValue(row.PeakTime); | ||
}, | ||
}; | ||
}; | ||
export const getIntervalEndColumn: GetShardsColumn = () => { | ||
return { | ||
name: TOP_SHARDS_COLUMNS_IDS.IntervalEnd, | ||
render: ({row}) => { | ||
return prepareDateTimeValue(row.IntervalEnd); | ||
}, | ||
}; | ||
}; | ||
|
||
export const shardsColumnIdToGetColumn: Record<TopShardsColumnId, GetShardsColumn> = { | ||
[TOP_SHARDS_COLUMNS_IDS.Path]: getPathColumn, | ||
[TOP_SHARDS_COLUMNS_IDS.DataSize]: getDataSizeColumn, | ||
[TOP_SHARDS_COLUMNS_IDS.TabletId]: getTabletIdColumn, | ||
[TOP_SHARDS_COLUMNS_IDS.NodeId]: getNodeIdColumn, | ||
[TOP_SHARDS_COLUMNS_IDS.CPUCores]: getCpuCoresColumn, | ||
[TOP_SHARDS_COLUMNS_IDS.InFlightTxCount]: getInFlightTxCountColumn, | ||
[TOP_SHARDS_COLUMNS_IDS.PeakTime]: getPeakTimeColumn, | ||
[TOP_SHARDS_COLUMNS_IDS.IntervalEnd]: getIntervalEndColumn, | ||
}; |
This file contains 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
File renamed without changes.
This file contains 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-shards-table'; | ||
|
||
export default registerKeysets(COMPONENT, {en}); |
This file contains 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 type {Column} from '@gravity-ui/react-data-table'; | ||
|
||
import type {KeyValueRow} from '../../types/api/query'; | ||
|
||
export type ShardsColumn = Column<KeyValueRow>; | ||
|
||
export type GetShardsColumn = (params: {database: string; schemaPath?: string}) => ShardsColumn; |
This file contains 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,10 @@ | ||
import type {CellValue} from '../../types/api/query'; | ||
import {EMPTY_DATA_PLACEHOLDER} from '../../utils/constants'; | ||
import {formatDateTime} from '../../utils/dataFormatters/dataFormatters'; | ||
|
||
export function prepareDateTimeValue(value: CellValue) { | ||
if (!value) { | ||
return EMPTY_DATA_PLACEHOLDER; | ||
} | ||
return formatDateTime(new Date(value).getTime()); | ||
} |
This file contains 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 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
Oops, something went wrong.
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.
maybe add this prop in previous map cycle?