Skip to content

Commit 7e7b3e3

Browse files
fix: pass database to capabilities query (#1551)
1 parent 7811347 commit 7e7b3e3

File tree

26 files changed

+145
-89
lines changed

26 files changed

+145
-89
lines changed

src/components/NodeHostWrapper/NodeHostWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const NodeHostWrapper = ({node, getNodeRef, database}: NodeHostWrapperPro
3737

3838
const nodePath = isNodeAvailable
3939
? getDefaultNodePath(node.NodeId, {
40-
tenantName: database ?? node.TenantName,
40+
database: database ?? node.TenantName,
4141
})
4242
: undefined;
4343

src/components/Tablet/Tablet.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ const b = cn('tablet');
1313

1414
interface TabletProps {
1515
tablet?: TTabletStateInfo;
16-
tenantName?: string;
16+
database?: string;
1717
}
1818

19-
export const Tablet = ({tablet = {}, tenantName}: TabletProps) => {
20-
const {TabletId: id, NodeId, Type} = tablet;
19+
export const Tablet = ({tablet = {}, database}: TabletProps) => {
20+
const {TabletId: id} = tablet;
2121
const status = tablet.Overall?.toLowerCase();
2222

23-
const tabletPath = id && getTabletPagePath(id, {nodeId: NodeId, tenantName, type: Type});
23+
const tabletPath = id && getTabletPagePath(id, {database});
2424

2525
return (
2626
<ContentWithPopup

src/components/TabletNameWrapper/TabletNameWrapper.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ interface TabletNameWrapperProps {
1818
export function TabletNameWrapper({tabletId, database}: TabletNameWrapperProps) {
1919
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
2020

21-
const tabletPath = getTabletPagePath(tabletId, {
22-
tenantName: database,
23-
});
21+
const tabletPath = getTabletPagePath(tabletId, {database});
2422

2523
return (
2624
<CellWithPopover

src/components/TabletsStatistic/TabletsStatistic.tsx

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {Link} from 'react-router-dom';
22

3-
import {TABLETS} from '../../containers/Node/NodePages';
4-
import routes, {createHref} from '../../routes';
3+
import {TABLETS, getDefaultNodePath} from '../../containers/Node/NodePages';
54
import type {TTabletStateInfo} from '../../types/api/tablet';
65
import {cn} from '../../utils/cn';
76
import {getTabletLabel} from '../../utils/constants';
@@ -26,35 +25,18 @@ const prepareTablets = (tablets: TTabletStateInfo[]) => {
2625

2726
interface TabletsStatisticProps {
2827
tablets: TTabletStateInfo[];
29-
tenantName: string | undefined;
28+
database: string | undefined;
3029
nodeId: string | number;
31-
backend?: string;
3230
}
3331

34-
export const TabletsStatistic = ({
35-
tablets = [],
36-
tenantName,
37-
nodeId,
38-
backend,
39-
}: TabletsStatisticProps) => {
32+
export const TabletsStatistic = ({tablets = [], database, nodeId}: TabletsStatisticProps) => {
4033
const renderTabletInfo = (item: ReturnType<typeof prepareTablets>[number], index: number) => {
41-
const tabletsPath = createHref(
42-
routes.node,
43-
{id: nodeId, activeTab: TABLETS},
44-
{
45-
tenantName,
46-
backend,
47-
},
48-
);
34+
const tabletsPath = getDefaultNodePath(nodeId, {database}, TABLETS);
4935

5036
const label = `${item.label}: ${item.count}`;
5137
const className = b('tablet', {state: item.state?.toLowerCase()});
5238

53-
return backend ? (
54-
<a href={tabletsPath} key={index} className={className}>
55-
{label}
56-
</a>
57-
) : (
39+
return (
5840
<Link to={tabletsPath} key={index} className={className}>
5941
{label}
6042
</Link>

src/components/TenantNameWrapper/TenantNameWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function TenantNameWrapper({tenant, additionalTenantsProps}: TenantNameWr
6666
status={tenant.Overall}
6767
hasClipboardButton
6868
path={getTenantPath({
69-
name: tenant.Name,
69+
database: tenant.Name,
7070
backend,
7171
})}
7272
/>

src/components/nodesColumns/columns.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export function getTabletsColumn<
230230
render: ({row}) => {
231231
return row.Tablets ? (
232232
<TabletsStatistic
233-
tenantName={database ?? row.TenantName}
233+
database={database ?? row.TenantName}
234234
nodeId={row.NodeId}
235235
tablets={row.Tablets}
236236
/>

src/containers/App/Content.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {SlotComponent} from '../../components/slots/types';
1212
import routes from '../../routes';
1313
import type {RootState} from '../../store';
1414
import {authenticationApi} from '../../store/reducers/authentication/authentication';
15-
import {capabilitiesApi} from '../../store/reducers/capabilities/capabilities';
15+
import {useCapabilitiesQuery} from '../../store/reducers/capabilities/hooks';
1616
import {nodesListApi} from '../../store/reducers/nodesList';
1717
import {cn} from '../../utils/cn';
1818
import {lazyComponent} from '../../utils/lazyComponent';
@@ -200,7 +200,7 @@ function GetNodesList() {
200200
}
201201

202202
function GetCapabilities() {
203-
capabilitiesApi.useGetClusterCapabilitiesQuery(undefined);
203+
useCapabilitiesQuery();
204204
return null;
205205
}
206206

src/containers/Header/breadcrumbs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const getTenantBreadcrumbs: GetBreadcrumbs<TenantBreadcrumbsOptions> = (options,
6767
const breadcrumbs = getClusterBreadcrumbs(options, query);
6868

6969
const text = tenantName ? prepareTenantName(tenantName) : headerKeyset('breadcrumbs.tenant');
70-
const link = tenantName ? getTenantPath({...query, name: tenantName}) : undefined;
70+
const link = tenantName ? getTenantPath({...query, database: tenantName}) : undefined;
7171

7272
const lastItem = {text, link, icon: <DatabaseIcon />};
7373
breadcrumbs.push(lastItem);
@@ -92,7 +92,7 @@ const getNodeBreadcrumbs: GetBreadcrumbs<NodeBreadcrumbsOptions> = (options, que
9292
const lastItem = {
9393
text,
9494
link: nodeId
95-
? getDefaultNodePath(nodeId, {tenantName, ...query}, nodeActiveTab)
95+
? getDefaultNodePath(nodeId, {database: tenantName, ...query}, nodeActiveTab)
9696
: undefined,
9797
icon: getNodeIcon(nodeRole),
9898
};

src/containers/Node/Node.tsx

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

33
import {Tabs} from '@gravity-ui/uikit';
44
import {Helmet} from 'react-helmet-async';
5-
import {Link, useLocation, useRouteMatch} from 'react-router-dom';
5+
import {Link, useRouteMatch} from 'react-router-dom';
6+
import {useQueryParams} from 'use-query-params';
67

78
import {AutoRefreshControl} from '../../components/AutoRefreshControl/AutoRefreshControl';
89
import {BasicNodeViewer} from '../../components/BasicNodeViewer';
910
import {ResponseError} from '../../components/Errors/ResponseError';
1011
import {FullNodeViewer} from '../../components/FullNodeViewer/FullNodeViewer';
1112
import {Loader} from '../../components/Loader';
12-
import routes, {createHref, parseQuery} from '../../routes';
13+
import routes from '../../routes';
1314
import {
1415
useCapabilitiesLoaded,
1516
useDiskPagesAvailable,
@@ -22,7 +23,16 @@ import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks';
2223
import {StorageWrapper} from '../Storage/StorageWrapper';
2324
import {Tablets} from '../Tablets';
2425

25-
import {NODE_PAGES, OVERVIEW, STORAGE, STRUCTURE, TABLETS} from './NodePages';
26+
import type {NodeTab} from './NodePages';
27+
import {
28+
NODE_PAGES,
29+
OVERVIEW,
30+
STORAGE,
31+
STRUCTURE,
32+
TABLETS,
33+
getDefaultNodePath,
34+
nodePageQueryParams,
35+
} from './NodePages';
2636
import NodeStructure from './NodeStructure/NodeStructure';
2737

2838
import './Node.scss';
@@ -40,13 +50,12 @@ export function Node(props: NodeProps) {
4050
const container = React.useRef<HTMLDivElement>(null);
4151

4252
const dispatch = useTypedDispatch();
43-
const location = useLocation();
4453

4554
const match =
4655
useRouteMatch<{id: string; activeTab: string}>(routes.node) ?? Object.create(null);
4756

4857
const {id: nodeId, activeTab} = match.params;
49-
const {tenantName: tenantNameFromQuery} = parseQuery(location);
58+
const [{database: tenantNameFromQuery}] = useQueryParams(nodePageQueryParams);
5059

5160
const [autoRefreshInterval] = useAutoRefreshInterval();
5261
const {currentData, isFetching, error} = nodeApi.useGetNodeInfoQuery(
@@ -109,7 +118,13 @@ export function Node(props: NodeProps) {
109118
activeTab={activeTabVerified.id}
110119
wrapTo={({id}, tabNode) => (
111120
<Link
112-
to={createHref(routes.node, {id: nodeId, activeTab: id}, {tenantName})}
121+
to={getDefaultNodePath(
122+
nodeId,
123+
{
124+
database: tenantName,
125+
},
126+
id as NodeTab,
127+
)}
113128
key={id}
114129
className={b('tab')}
115130
>

src/containers/Node/NodePages.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import type {Query} from '../../routes';
1+
import {StringParam} from 'use-query-params';
2+
3+
import type {QueryParamsTypeFromQueryObject} from '../../routes';
24
import routes, {createHref} from '../../routes';
35

46
export const STORAGE = 'storage';
@@ -27,9 +29,15 @@ export const NODE_PAGES = [
2729
},
2830
];
2931

32+
export const nodePageQueryParams = {
33+
database: StringParam,
34+
};
35+
36+
type NodePageQuery = QueryParamsTypeFromQueryObject<typeof nodePageQueryParams>;
37+
3038
export function getDefaultNodePath(
3139
nodeId: string | number,
32-
query: Query = {},
40+
query: NodePageQuery = {},
3341
activeTab: NodeTab = OVERVIEW,
3442
) {
3543
return createHref(

0 commit comments

Comments
 (0)