Skip to content

Commit d68adba

Browse files
feat(TabletsTable): add search by id (#1981)
1 parent ad64c8c commit d68adba

File tree

8 files changed

+62
-49
lines changed

8 files changed

+62
-49
lines changed

src/containers/Cluster/Cluster.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@
6161
top: 40px;
6262
}
6363

64-
&__tablets {
65-
.data-table__sticky_moving {
66-
// Place table head right after controls
67-
top: 40px !important;
68-
}
69-
}
70-
7164
.ydb-table-with-controls-layout {
7265
--data-table-sticky-top-offset: 102px;
7366
}

src/containers/Cluster/Cluster.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,7 @@ export function Cluster({
178178
getLocationObjectFromHref(getClusterPath(clusterTabsIds.tablets)).pathname
179179
}
180180
>
181-
<div className={b('tablets')}>
182-
<TabletsTable
183-
loading={infoLoading}
184-
tablets={clusterTablets}
185-
className={b('tablets-table')}
186-
/>
187-
</div>
181+
<TabletsTable loading={infoLoading} tablets={clusterTablets} />
188182
</Route>
189183
<Route
190184
path={

src/containers/Node/Node.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type {PreparedNode} from '../../store/reducers/node/types';
2424
import {cn} from '../../utils/cn';
2525
import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks';
2626
import {PaginatedStorage} from '../Storage/PaginatedStorage';
27-
import {Tablets} from '../Tablets';
27+
import {Tablets} from '../Tablets/Tablets';
2828

2929
import type {NodeTab} from './NodePages';
3030
import {NODE_TABS, getDefaultNodePath, nodePageQueryParams, nodePageTabSchema} from './NodePages';

src/containers/Tablets/Tablets.tsx

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,35 @@
11
import {skipToken} from '@reduxjs/toolkit/query';
22

3-
import {ResponseError} from '../../components/Errors/ResponseError';
43
import {selectTabletsWithFqdn, tabletsApi} from '../../store/reducers/tablets';
54
import type {TabletsApiRequestParams} from '../../types/store/tablets';
6-
import {cn} from '../../utils/cn';
5+
import {valueIsDefined} from '../../utils';
76
import {useAutoRefreshInterval, useTypedSelector} from '../../utils/hooks';
87

98
import {TabletsTable} from './TabletsTable';
109

11-
const b = cn('tablets');
12-
1310
interface TabletsProps {
1411
path?: string;
1512
database?: string;
1613
nodeId?: string | number;
17-
className?: string;
1814
}
1915

20-
export function Tablets({nodeId, path, database, className}: TabletsProps) {
16+
export function Tablets({nodeId, path, database}: TabletsProps) {
2117
const [autoRefreshInterval] = useAutoRefreshInterval();
2218

2319
let params: TabletsApiRequestParams = {};
24-
const node = nodeId === undefined ? undefined : String(nodeId);
25-
if (node !== undefined) {
26-
params = {nodeId: node, database};
20+
if (valueIsDefined(nodeId)) {
21+
params = {nodeId, database};
2722
} else if (path) {
2823
params = {path, database};
2924
}
30-
const {currentData, isFetching, error} = tabletsApi.useGetTabletsInfoQuery(
25+
const {isLoading, error} = tabletsApi.useGetTabletsInfoQuery(
3126
Object.keys(params).length === 0 ? skipToken : params,
3227
{
3328
pollingInterval: autoRefreshInterval,
3429
},
3530
);
3631

37-
const loading = isFetching && currentData === undefined;
3832
const tablets = useTypedSelector((state) => selectTabletsWithFqdn(state, params));
3933

40-
return (
41-
<div className={b(null, className)}>
42-
{error ? <ResponseError error={error} /> : null}
43-
{currentData || loading ? (
44-
<TabletsTable tablets={tablets} database={database} loading={loading} />
45-
) : null}
46-
</div>
47-
);
34+
return <TabletsTable tablets={tablets} database={database} loading={isLoading} error={error} />;
4835
}

src/containers/Tablets/TabletsTable.tsx

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
import React from 'react';
2+
13
import {ArrowRotateLeft} from '@gravity-ui/icons';
24
import type {Column as DataTableColumn} from '@gravity-ui/react-data-table';
35
import {Icon, Text} from '@gravity-ui/uikit';
6+
import {StringParam, useQueryParams} from 'use-query-params';
47

58
import {ButtonWithConfirmDialog} from '../../components/ButtonWithConfirmDialog/ButtonWithConfirmDialog';
9+
import {EntitiesCount} from '../../components/EntitiesCount';
610
import {EntityStatus} from '../../components/EntityStatus/EntityStatus';
11+
import {ResponseError} from '../../components/Errors/ResponseError';
712
import {InternalLink} from '../../components/InternalLink';
813
import {ResizeableDataTable} from '../../components/ResizeableDataTable/ResizeableDataTable';
9-
import {TableSkeleton} from '../../components/TableSkeleton/TableSkeleton';
14+
import {Search} from '../../components/Search/Search';
15+
import {TableWithControlsLayout} from '../../components/TableWithControlsLayout/TableWithControlsLayout';
1016
import {TabletNameWrapper} from '../../components/TabletNameWrapper/TabletNameWrapper';
1117
import {TabletState} from '../../components/TabletState/TabletState';
1218
import {TabletUptime} from '../../components/UptimeViewer/UptimeViewer';
@@ -156,19 +162,51 @@ interface TabletsTableProps {
156162
})[];
157163
className?: string;
158164
loading?: boolean;
165+
error?: unknown;
159166
}
160167

161-
export function TabletsTable({database, tablets, className, loading}: TabletsTableProps) {
162-
if (loading) {
163-
return <TableSkeleton />;
164-
}
168+
export function TabletsTable({database, tablets, loading, error}: TabletsTableProps) {
169+
const [{tabletsSearch}, setQueryParams] = useQueryParams({
170+
tabletsSearch: StringParam,
171+
});
172+
173+
const columns = React.useMemo(() => getColumns({database}), [database]);
174+
175+
const filteredTablets = React.useMemo(() => {
176+
return tablets.filter((tablet) => {
177+
return String(tablet.TabletId).includes(tabletsSearch ?? '');
178+
});
179+
}, [tablets, tabletsSearch]);
180+
181+
const handleSearchQueryChange = (value: string) => {
182+
setQueryParams({tabletsSearch: value || undefined}, 'replaceIn');
183+
};
184+
165185
return (
166-
<ResizeableDataTable
167-
wrapperClassName={className}
168-
columns={getColumns({database})}
169-
data={tablets}
170-
settings={DEFAULT_TABLE_SETTINGS}
171-
emptyDataMessage={i18n('noTabletsData')}
172-
/>
186+
<TableWithControlsLayout>
187+
<TableWithControlsLayout.Controls>
188+
<Search
189+
placeholder={i18n('controls.search-placeholder')}
190+
onChange={handleSearchQueryChange}
191+
value={tabletsSearch ?? ''}
192+
width={238}
193+
/>
194+
<EntitiesCount
195+
label={i18n('controls.entities-count-label')}
196+
loading={loading}
197+
total={tablets.length}
198+
current={filteredTablets.length}
199+
/>
200+
</TableWithControlsLayout.Controls>
201+
{error ? <ResponseError error={error} /> : null}
202+
<TableWithControlsLayout.Table loading={loading}>
203+
<ResizeableDataTable
204+
columns={columns}
205+
data={filteredTablets}
206+
settings={DEFAULT_TABLE_SETTINGS}
207+
emptyDataMessage={i18n('noTabletsData')}
208+
/>
209+
</TableWithControlsLayout.Table>
210+
</TableWithControlsLayout>
173211
);
174212
}

src/containers/Tablets/i18n/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
"Uptime": "Uptime",
1010
"dialog.kill-header": "Restart tablet",
1111
"dialog.kill-text": "The tablet will be restarted. Do you want to proceed?",
12-
"controls.kill-not-allowed": "You don't have enough rights to restart tablet"
12+
"controls.kill-not-allowed": "You don't have enough rights to restart tablet",
13+
"controls.search-placeholder": "Tablet ID",
14+
"controls.entities-count-label": "Tablets"
1315
}

src/containers/Tablets/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/containers/Tenant/Diagnostics/Diagnostics.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {Heatmap} from '../../Heatmap';
1717
import {Nodes} from '../../Nodes/Nodes';
1818
import {Operations} from '../../Operations';
1919
import {PaginatedStorage} from '../../Storage/PaginatedStorage';
20-
import {Tablets} from '../../Tablets';
20+
import {Tablets} from '../../Tablets/Tablets';
2121
import {SchemaViewer} from '../Schema/SchemaViewer/SchemaViewer';
2222
import {TenantTabsGroups, getTenantPath} from '../TenantPages';
2323
import {isDatabaseEntityType} from '../utils/schema';

0 commit comments

Comments
 (0)