Skip to content

Commit e9b918f

Browse files
authored
feat: add top tables links (#564)
1 parent 6caea3d commit e9b918f

File tree

5 files changed

+49
-58
lines changed

5 files changed

+49
-58
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type {Location} from 'history';
2+
3+
import {Link, type LinkProps} from '@gravity-ui/uikit';
4+
5+
import {parseQuery} from '../../routes';
6+
import {getTenantPath} from '../../containers/Tenant/TenantPages';
7+
8+
interface LinkToSchemaObjectProps extends LinkProps {
9+
path: string;
10+
location: Location;
11+
}
12+
13+
export function LinkToSchemaObject({path, location, ...props}: LinkToSchemaObjectProps) {
14+
const queryParams = parseQuery(location);
15+
16+
return <Link view="normal" href={getTenantPath({...queryParams, schema: path})} {...props} />;
17+
}

src/containers/Tenant/Diagnostics/TenantOverview/TenantCpu/TopShards.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {useDispatch} from 'react-redux';
2+
import {useLocation} from 'react-router';
23

3-
import {getSchema, setCurrentSchemaPath} from '../../../../../store/reducers/schema/schema';
44
import {useAutofetcher, useTypedSelector} from '../../../../../utils/hooks';
55
import {
66
sendTenantOverviewTopShardsQuery,
@@ -15,6 +15,7 @@ interface TopShardsProps {
1515

1616
export const TopShards = ({path}: TopShardsProps) => {
1717
const dispatch = useDispatch();
18+
const location = useLocation();
1819

1920
const {autorefresh, currentSchemaPath} = useTypedSelector((state) => state.schema);
2021

@@ -36,15 +37,7 @@ export const TopShards = ({path}: TopShardsProps) => {
3637
autorefresh,
3738
);
3839

39-
const onSchemaClick = (schemaPath: string) => {
40-
return () => {
41-
dispatch(setCurrentSchemaPath(schemaPath));
42-
dispatch(getSchema({path: schemaPath}));
43-
history.go(0);
44-
};
45-
};
46-
47-
const columns = getTopShardsColumns(onSchemaClick, path);
40+
const columns = getTopShardsColumns(path, location);
4841

4942
return (
5043
<TenantOverviewTableLayout

src/containers/Tenant/Diagnostics/TenantOverview/TenantStorage/TopTables.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {useDispatch} from 'react-redux';
2+
import {useLocation} from 'react-router';
23
import cn from 'bem-cn-lite';
34

45
import DataTable, {Column} from '@gravity-ui/react-data-table';
@@ -17,6 +18,7 @@ import type {KeyValueRow} from '../../../../../types/api/query';
1718
import {formatBytes, getSizeWithSignificantDigits} from '../../../../../utils/bytesParsers';
1819
import {TableSkeleton} from '../../../../../components/TableSkeleton/TableSkeleton';
1920
import {ResponseError} from '../../../../../components/Errors/ResponseError';
21+
import {LinkToSchemaObject} from '../../../../../components/LinkToSchemaObject/LinkToSchemaObject';
2022

2123
import './TenantStorage.scss';
2224

@@ -28,6 +30,7 @@ interface TopTablesProps {
2830

2931
export function TopTables({path}: TopTablesProps) {
3032
const dispatch = useDispatch();
33+
const location = useLocation();
3134

3235
const {autorefresh} = useTypedSelector((state) => state.schema);
3336

@@ -67,13 +70,18 @@ export function TopTables({path}: TopTablesProps) {
6770
{
6871
name: 'Path',
6972
sortable: false,
70-
render: ({row}) => (
71-
<div className={b('cell-with-popover-wrapper')}>
72-
<Popover className={b('cell-with-popover')} content={row.Path}>
73-
{row.Path}
74-
</Popover>
75-
</div>
76-
),
73+
render: ({row}) =>
74+
row.Path ? (
75+
<LinkToSchemaObject
76+
className={b('cell-with-popover-wrapper')}
77+
path={String(row.Path)}
78+
location={location}
79+
>
80+
<Popover className={b('cell-with-popover')} content={row.Path}>
81+
{row.Path}
82+
</Popover>
83+
</LinkToSchemaObject>
84+
) : null,
7785
},
7886
];
7987

src/containers/Tenant/Diagnostics/TopShards/TopShards.tsx

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import {useState, useContext, useEffect, useMemo} from 'react';
1+
import {useState, useEffect, useMemo} from 'react';
22
import {useDispatch} from 'react-redux';
33
import cn from 'bem-cn-lite';
4+
import {useLocation} from 'react-router';
45

56
import DataTable, {Column, Settings, SortOrder} from '@gravity-ui/react-data-table';
67
import {Loader} from '@gravity-ui/uikit';
78

8-
import HistoryContext from '../../../../contexts/HistoryContext';
9-
109
import {
1110
sendShardQuery,
1211
setShardsState,
1312
setShardsQueryFilters,
1413
} from '../../../../store/reducers/shardsWorkload/shardsWorkload';
15-
import {setCurrentSchemaPath, getSchema} from '../../../../store/reducers/schema/schema';
1614
import {
1715
EShardsWorkloadMode,
1816
type IShardsWorkloadFilters,
@@ -26,7 +24,6 @@ import {DEFAULT_TABLE_SETTINGS, HOUR_IN_SECONDS} from '../../../../utils/constan
2624
import {useAutofetcher, useTypedSelector} from '../../../../utils/hooks';
2725
import {prepareQueryError} from '../../../../utils/query';
2826
import {isSortableTopShardsProperty} from '../../../../utils/diagnostics';
29-
3027
import {isColumnEntityType} from '../../utils/schema';
3128

3229
import {Filters} from './Filters';
@@ -99,6 +96,7 @@ interface TopShardsProps {
9996

10097
export const TopShards = ({tenantPath, type}: TopShardsProps) => {
10198
const dispatch = useDispatch();
99+
const location = useLocation();
102100

103101
const {autorefresh, currentSchemaPath} = useTypedSelector((state) => state.schema);
104102

@@ -153,8 +151,6 @@ export const TopShards = ({tenantPath, type}: TopShardsProps) => {
153151
);
154152
}, [dispatch, currentSchemaPath, tenantPath, filters]);
155153

156-
const history = useContext(HistoryContext);
157-
158154
const onSort = (newSortOrder?: SortOrder | SortOrder[]) => {
159155
// omit information about sort order to disable ASC order, only DESC makes sense for top shards
160156
// use a string (and not the DataTable default format) to prevent reference change,
@@ -184,18 +180,7 @@ export const TopShards = ({tenantPath, type}: TopShardsProps) => {
184180
};
185181

186182
const tableColumns = useMemo(() => {
187-
const onSchemaClick = (schemaPath: string) => {
188-
return () => {
189-
dispatch(setCurrentSchemaPath(schemaPath));
190-
dispatch(getSchema({path: schemaPath}));
191-
history.go(0);
192-
};
193-
};
194-
195-
const rawColumns: Column<KeyValueRow>[] = getShardsWorkloadColumns(
196-
onSchemaClick,
197-
tenantPath,
198-
);
183+
const rawColumns: Column<KeyValueRow>[] = getShardsWorkloadColumns(tenantPath, location);
199184

200185
const columns: Column<KeyValueRow>[] = rawColumns.map((column) => ({
201186
...column,
@@ -220,7 +205,7 @@ export const TopShards = ({tenantPath, type}: TopShardsProps) => {
220205
}
221206

222207
return columns;
223-
}, [dispatch, filters.mode, history, tenantPath]);
208+
}, [filters.mode, tenantPath, location]);
224209

225210
const renderLoader = () => {
226211
return (

src/containers/Tenant/Diagnostics/TopShards/getTopShardsColumns.tsx

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import cn from 'bem-cn-lite';
1+
import type {Location} from 'history';
22

33
import DataTable, {type Column} from '@gravity-ui/react-data-table';
44

@@ -10,10 +10,7 @@ import {InternalLink} from '../../../../components/InternalLink';
1010
import routes, {createHref} from '../../../../routes';
1111
import {getDefaultNodePath} from '../../../Node/NodePages';
1212
import {UsageLabel} from '../../../../components/UsageLabel/UsageLabel';
13-
14-
import './TopShards.scss';
15-
16-
const b = cn('yc-link');
13+
import {LinkToSchemaObject} from '../../../../components/LinkToSchemaObject/LinkToSchemaObject';
1714

1815
const TOP_SHARDS_COLUMNS_IDS = {
1916
TabletId: 'TabletId',
@@ -43,18 +40,15 @@ function prepareCPUWorkloadValue(value: string | number) {
4340
return `${roundToPrecision(Number(value) * 100, 2)}%`;
4441
}
4542

46-
const getPathColumn = (
47-
onSchemaClick: (schemaPath: string) => () => void,
48-
tenantPath: string,
49-
): Column<KeyValueRow> => ({
43+
const getPathColumn = (schemaPath: string, location: Location): Column<KeyValueRow> => ({
5044
name: TOP_SHARDS_COLUMNS_IDS.Path,
5145
header: tableColumnsNames[TOP_SHARDS_COLUMNS_IDS.Path],
5246
render: ({row}) => {
5347
// row.Path - relative schema path
5448
return (
55-
<span onClick={onSchemaClick(tenantPath + row.Path)} className={b({view: 'normal'})}>
49+
<LinkToSchemaObject path={schemaPath + row.Path} location={location}>
5650
{row.Path}
57-
</span>
51+
</LinkToSchemaObject>
5852
);
5953
},
6054
sortable: false,
@@ -128,12 +122,9 @@ const inFlightTxCountColumn: Column<KeyValueRow> = {
128122
align: DataTable.RIGHT,
129123
};
130124

131-
export const getShardsWorkloadColumns = (
132-
onSchemaClick: (schemaPath: string) => () => void,
133-
tenantPath: string,
134-
) => {
125+
export const getShardsWorkloadColumns = (schemaPath: string, location: Location) => {
135126
return [
136-
getPathColumn(onSchemaClick, tenantPath),
127+
getPathColumn(schemaPath, location),
137128
cpuCoresColumn,
138129
dataSizeColumn,
139130
tabletIdColumn,
@@ -142,9 +133,6 @@ export const getShardsWorkloadColumns = (
142133
];
143134
};
144135

145-
export const getTopShardsColumns = (
146-
onSchemaClick: (schemaPath: string) => () => void,
147-
tenantPath: string,
148-
) => {
149-
return [tabletIdColumn, getPathColumn(onSchemaClick, tenantPath), topShardsCpuCoresColumn];
136+
export const getTopShardsColumns = (schemaPath: string, location: Location) => {
137+
return [tabletIdColumn, getPathColumn(schemaPath, location), topShardsCpuCoresColumn];
150138
};

0 commit comments

Comments
 (0)