Skip to content

Commit 259695a

Browse files
refactor(TenantOverviewTableLayout): pass table as child (#2001)
1 parent b139eb5 commit 259695a

File tree

11 files changed

+117
-97
lines changed

11 files changed

+117
-97
lines changed

src/containers/Storage/StorageGroups/columns/columns.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,21 +265,7 @@ const getDisksColumn = (data?: GetStorageColumnsData): StorageGroupsColumn => ({
265265
});
266266

267267
export const getStorageTopGroupsColumns: StorageColumnsGetter = () => {
268-
const columns = [
269-
groupIdColumn,
270-
typeColumn,
271-
erasureColumn,
272-
usageColumn,
273-
usedColumn,
274-
limitColumn,
275-
];
276-
277-
return columns.map((column) => {
278-
return {
279-
...column,
280-
sortable: false,
281-
};
282-
});
268+
return [groupIdColumn, typeColumn, erasureColumn, usageColumn, usedColumn, limitColumn];
283269
};
284270

285271
export const getStorageGroupsColumns: StorageColumnsGetter = (data) => {

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {Column} from '@gravity-ui/react-data-table';
22

3+
import {ResizeableDataTable} from '../../../../../components/ResizeableDataTable/ResizeableDataTable';
34
import {
45
getHostColumn,
56
getNodeIdColumn,
@@ -15,7 +16,10 @@ import type {NodesPreparedEntity} from '../../../../../store/reducers/nodes/type
1516
import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../../../store/reducers/tenant/constants';
1617
import type {AdditionalNodesProps} from '../../../../../types/additionalProps';
1718
import type {NodesRequiredField} from '../../../../../types/api/nodes';
18-
import {TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../../utils/constants';
19+
import {
20+
TENANT_OVERVIEW_TABLES_LIMIT,
21+
TENANT_OVERVIEW_TABLES_SETTINGS,
22+
} from '../../../../../utils/constants';
1923
import {useAutoRefreshInterval, useSearchQuery} from '../../../../../utils/hooks';
2024
import {getRequiredDataFields} from '../../../../../utils/tableUtils/getRequiredDataFields';
2125
import {TenantTabsGroups, getTenantPath} from '../../../TenantPages';
@@ -34,15 +38,10 @@ function getTopNodesByCpuColumns(
3438
hostColumn,
3539
];
3640

37-
const preparedColumns = columns.map((column) => ({
38-
...column,
39-
sortable: false,
40-
}));
41-
42-
const columnsIds = preparedColumns.map((column) => column.name);
41+
const columnsIds = columns.map((column) => column.name);
4342
const dataFieldsRequired = getRequiredDataFields(columnsIds, NODES_COLUMNS_TO_DATA_FIELDS);
4443

45-
return [preparedColumns, dataFieldsRequired];
44+
return [columns, dataFieldsRequired];
4645
}
4746

4847
interface TopNodesByCpuProps {
@@ -86,13 +85,18 @@ export function TopNodesByCpu({tenantName, additionalNodesProps}: TopNodesByCpuP
8685

8786
return (
8887
<TenantOverviewTableLayout
89-
columnsWidthLSKey={NODES_COLUMNS_WIDTH_LS_KEY}
90-
data={topNodes}
91-
columns={columns}
9288
title={title}
9389
loading={loading}
9490
error={error}
95-
emptyDataMessage={i18n('top-nodes.empty-data')}
96-
/>
91+
withData={Boolean(currentData)}
92+
>
93+
<ResizeableDataTable
94+
columnsWidthLSKey={NODES_COLUMNS_WIDTH_LS_KEY}
95+
data={topNodes}
96+
columns={columns}
97+
emptyDataMessage={i18n('top-nodes.empty-data')}
98+
settings={TENANT_OVERVIEW_TABLES_SETTINGS}
99+
/>
100+
</TenantOverviewTableLayout>
97101
);
98102
}

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {Column} from '@gravity-ui/react-data-table';
22

3+
import {ResizeableDataTable} from '../../../../../components/ResizeableDataTable/ResizeableDataTable';
34
import {
45
getHostColumn,
56
getLoadColumn,
@@ -16,7 +17,10 @@ import type {NodesPreparedEntity} from '../../../../../store/reducers/nodes/type
1617
import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../../../store/reducers/tenant/constants';
1718
import type {AdditionalNodesProps} from '../../../../../types/additionalProps';
1819
import type {NodesRequiredField} from '../../../../../types/api/nodes';
19-
import {TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../../utils/constants';
20+
import {
21+
TENANT_OVERVIEW_TABLES_LIMIT,
22+
TENANT_OVERVIEW_TABLES_SETTINGS,
23+
} from '../../../../../utils/constants';
2024
import {useAutoRefreshInterval, useSearchQuery} from '../../../../../utils/hooks';
2125
import {getRequiredDataFields} from '../../../../../utils/tableUtils/getRequiredDataFields';
2226
import {TenantTabsGroups, getTenantPath} from '../../../TenantPages';
@@ -39,15 +43,10 @@ function getTopNodesByLoadColumns(
3943
getVersionColumn<NodesPreparedEntity>(),
4044
];
4145

42-
const preparedColumns = columns.map((column) => ({
43-
...column,
44-
sortable: false,
45-
}));
46-
47-
const columnsIds = preparedColumns.map((column) => column.name);
46+
const columnsIds = columns.map((column) => column.name);
4847
const dataFieldsRequired = getRequiredDataFields(columnsIds, NODES_COLUMNS_TO_DATA_FIELDS);
4948

50-
return [preparedColumns, dataFieldsRequired];
49+
return [columns, dataFieldsRequired];
5150
}
5251

5352
interface TopNodesByLoadProps {
@@ -91,13 +90,18 @@ export function TopNodesByLoad({tenantName, additionalNodesProps}: TopNodesByLoa
9190

9291
return (
9392
<TenantOverviewTableLayout
94-
columnsWidthLSKey={NODES_COLUMNS_WIDTH_LS_KEY}
95-
data={topNodes}
96-
columns={columns}
9793
title={title}
9894
loading={loading}
9995
error={error}
100-
emptyDataMessage={i18n('top-nodes.empty-data')}
101-
/>
96+
withData={Boolean(currentData)}
97+
>
98+
<ResizeableDataTable
99+
columnsWidthLSKey={NODES_COLUMNS_WIDTH_LS_KEY}
100+
data={topNodes}
101+
columns={columns}
102+
emptyDataMessage={i18n('top-nodes.empty-data')}
103+
settings={TENANT_OVERVIEW_TABLES_SETTINGS}
104+
/>
105+
</TenantOverviewTableLayout>
102106
);
103107
}

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22

33
import {useHistory, useLocation} from 'react-router-dom';
44

5+
import {ResizeableDataTable} from '../../../../../components/ResizeableDataTable/ResizeableDataTable';
56
import {parseQuery} from '../../../../../routes';
67
import {
78
setTopQueriesFilters,
@@ -14,6 +15,7 @@ import {
1415
TENANT_PAGES_IDS,
1516
TENANT_QUERY_TABS_ID,
1617
} from '../../../../../store/reducers/tenant/constants';
18+
import {TENANT_OVERVIEW_TABLES_SETTINGS} from '../../../../../utils/constants';
1719
import {useAutoRefreshInterval, useTypedDispatch} from '../../../../../utils/hooks';
1820
import {useChangeInputWithConfirmation} from '../../../../../utils/hooks/withConfirmation/useChangeInputWithConfirmation';
1921
import {parseQueryErrorToString} from '../../../../../utils/query';
@@ -85,14 +87,19 @@ export function TopQueries({tenantName}: TopQueriesProps) {
8587

8688
return (
8789
<TenantOverviewTableLayout
88-
columnsWidthLSKey={TOP_QUERIES_COLUMNS_WIDTH_LS_KEY}
89-
data={data || []}
90-
columns={columns}
91-
onRowClick={handleRowClick}
9290
title={title}
9391
loading={loading}
9492
error={parseQueryErrorToString(error)}
95-
rowClassName={() => b('top-queries-row')}
96-
/>
93+
withData={Boolean(currentData)}
94+
>
95+
<ResizeableDataTable
96+
columnsWidthLSKey={TOP_QUERIES_COLUMNS_WIDTH_LS_KEY}
97+
data={data}
98+
columns={columns}
99+
onRowClick={handleRowClick}
100+
rowClassName={() => b('top-queries-row')}
101+
settings={TENANT_OVERVIEW_TABLES_SETTINGS}
102+
/>
103+
</TenantOverviewTableLayout>
97104
);
98105
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import {useLocation} from 'react-router-dom';
22

3+
import {ResizeableDataTable} from '../../../../../components/ResizeableDataTable/ResizeableDataTable';
34
import {parseQuery} from '../../../../../routes';
45
import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../../../store/reducers/tenant/constants';
56
import {topShardsApi} from '../../../../../store/reducers/tenantOverview/topShards/tenantOverviewTopShards';
7+
import {TENANT_OVERVIEW_TABLES_SETTINGS} from '../../../../../utils/constants';
68
import {useAutoRefreshInterval} from '../../../../../utils/hooks';
79
import {parseQueryErrorToString} from '../../../../../utils/query';
810
import {TenantTabsGroups, getTenantPath} from '../../../TenantPages';
@@ -45,12 +47,17 @@ export const TopShards = ({tenantName, path}: TopShardsProps) => {
4547

4648
return (
4749
<TenantOverviewTableLayout
48-
columnsWidthLSKey={TOP_SHARDS_COLUMNS_WIDTH_LS_KEY}
49-
data={data || []}
50-
columns={columns}
5150
title={title}
5251
loading={loading}
5352
error={parseQueryErrorToString(error)}
54-
/>
53+
withData={Boolean(currentData)}
54+
>
55+
<ResizeableDataTable
56+
columnsWidthLSKey={TOP_SHARDS_COLUMNS_WIDTH_LS_KEY}
57+
data={data}
58+
columns={columns}
59+
settings={TENANT_OVERVIEW_TABLES_SETTINGS}
60+
/>
61+
</TenantOverviewTableLayout>
5562
);
5663
};

src/containers/Tenant/Diagnostics/TenantOverview/TenantMemory/TopNodesByMemory.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {Column} from '@gravity-ui/react-data-table';
22

3+
import {ResizeableDataTable} from '../../../../../components/ResizeableDataTable/ResizeableDataTable';
34
import {
45
getHostColumn,
56
getLoadColumn,
@@ -19,7 +20,10 @@ import type {NodesPreparedEntity} from '../../../../../store/reducers/nodes/type
1920
import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../../../store/reducers/tenant/constants';
2021
import type {AdditionalNodesProps} from '../../../../../types/additionalProps';
2122
import type {NodesRequiredField} from '../../../../../types/api/nodes';
22-
import {TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../../utils/constants';
23+
import {
24+
TENANT_OVERVIEW_TABLES_LIMIT,
25+
TENANT_OVERVIEW_TABLES_SETTINGS,
26+
} from '../../../../../utils/constants';
2327
import {useAutoRefreshInterval, useSearchQuery} from '../../../../../utils/hooks';
2428
import {getRequiredDataFields} from '../../../../../utils/tableUtils/getRequiredDataFields';
2529
import {TenantTabsGroups, getTenantPath} from '../../../TenantPages';
@@ -40,15 +44,10 @@ function getTopNodesByMemoryColumns(
4044
getTabletsColumn<NodesPreparedEntity>(params),
4145
];
4246

43-
const preparedColumns = columns.map((column) => ({
44-
...column,
45-
sortable: false,
46-
}));
47-
48-
const columnsIds = preparedColumns.map((column) => column.name);
47+
const columnsIds = columns.map((column) => column.name);
4948
const dataFieldsRequired = getRequiredDataFields(columnsIds, NODES_COLUMNS_TO_DATA_FIELDS);
5049

51-
return [preparedColumns, dataFieldsRequired];
50+
return [columns, dataFieldsRequired];
5251
}
5352

5453
interface TopNodesByMemoryProps {
@@ -92,13 +91,18 @@ export function TopNodesByMemory({tenantName, additionalNodesProps}: TopNodesByM
9291

9392
return (
9493
<TenantOverviewTableLayout
95-
columnsWidthLSKey={NODES_COLUMNS_WIDTH_LS_KEY}
96-
data={topNodes}
97-
columns={columns}
9894
title={title}
9995
loading={loading}
10096
error={error}
101-
emptyDataMessage={i18n('top-nodes.empty-data')}
102-
/>
97+
withData={Boolean(currentData)}
98+
>
99+
<ResizeableDataTable
100+
columnsWidthLSKey={NODES_COLUMNS_WIDTH_LS_KEY}
101+
data={topNodes}
102+
columns={columns}
103+
emptyDataMessage={i18n('top-nodes.empty-data')}
104+
settings={TENANT_OVERVIEW_TABLES_SETTINGS}
105+
/>
106+
</TenantOverviewTableLayout>
103107
);
104108
}

src/containers/Tenant/Diagnostics/TenantOverview/TenantOverviewTableLayout.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
11
import React from 'react';
22

3+
import type {NoStrictEntityMods} from '@bem-react/classname';
4+
35
import {ResponseError} from '../../../../components/Errors/ResponseError';
4-
import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable';
5-
import type {ResizeableDataTableProps} from '../../../../components/ResizeableDataTable/ResizeableDataTable';
66
import {TableSkeleton} from '../../../../components/TableSkeleton/TableSkeleton';
7-
import {
8-
TENANT_OVERVIEW_TABLES_LIMIT,
9-
TENANT_OVERVIEW_TABLES_SETTINGS,
10-
} from '../../../../utils/constants';
7+
import {TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../utils/constants';
118

129
import {b} from './utils';
1310

14-
interface TenantOverviewTableLayoutProps<T> extends ResizeableDataTableProps<T> {
11+
interface TenantOverviewTableLayoutProps {
1512
title: React.ReactNode;
1613
loading?: boolean;
1714
error?: unknown;
18-
tableClassNameModifiers?: {
19-
[name: string]: string | boolean | undefined;
20-
};
15+
tableClassNameModifiers?: NoStrictEntityMods;
16+
withData?: boolean;
17+
children?: React.ReactNode;
2118
}
2219

23-
export function TenantOverviewTableLayout<T>({
20+
export function TenantOverviewTableLayout({
2421
title,
2522
error,
2623
loading,
2724
tableClassNameModifiers = {},
28-
...props
29-
}: TenantOverviewTableLayoutProps<T>) {
25+
withData,
26+
children,
27+
}: TenantOverviewTableLayoutProps) {
3028
const renderContent = () => {
31-
if (error && props.data.length === 0) {
29+
if (error && !withData) {
3230
return null;
3331
}
3432

3533
if (loading) {
3634
return <TableSkeleton rows={TENANT_OVERVIEW_TABLES_LIMIT} />;
3735
}
3836

39-
return <ResizeableDataTable settings={TENANT_OVERVIEW_TABLES_SETTINGS} {...props} />;
37+
return children;
4038
};
4139
return (
4240
<React.Fragment>

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import {ResizeableDataTable} from '../../../../../components/ResizeableDataTable/ResizeableDataTable';
12
import {
23
useCapabilitiesLoaded,
34
useStorageGroupsHandlerAvailable,
45
} from '../../../../../store/reducers/capabilities/hooks';
56
import {storageApi} from '../../../../../store/reducers/storage/storage';
67
import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../../../store/reducers/tenant/constants';
78
import type {GroupsRequiredField} from '../../../../../types/api/storage';
8-
import {TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../../utils/constants';
9+
import {
10+
TENANT_OVERVIEW_TABLES_LIMIT,
11+
TENANT_OVERVIEW_TABLES_SETTINGS,
12+
} from '../../../../../utils/constants';
913
import {useAutoRefreshInterval, useSearchQuery} from '../../../../../utils/hooks';
1014
import {getRequiredDataFields} from '../../../../../utils/tableUtils/getRequiredDataFields';
1115
import {getStorageTopGroupsColumns} from '../../../../Storage/StorageGroups/columns/columns';
@@ -71,12 +75,17 @@ export function TopGroups({tenant}: TopGroupsProps) {
7175

7276
return (
7377
<TenantOverviewTableLayout
74-
columnsWidthLSKey={STORAGE_GROUPS_COLUMNS_WIDTH_LS_KEY}
75-
data={groups}
76-
columns={columns}
7778
title={title}
7879
loading={loading || !capabilitiesLoaded}
7980
error={error}
80-
/>
81+
withData={Boolean(currentData)}
82+
>
83+
<ResizeableDataTable
84+
columnsWidthLSKey={STORAGE_GROUPS_COLUMNS_WIDTH_LS_KEY}
85+
data={groups}
86+
columns={columns}
87+
settings={TENANT_OVERVIEW_TABLES_SETTINGS}
88+
/>
89+
</TenantOverviewTableLayout>
8190
);
8291
}

0 commit comments

Comments
 (0)