Skip to content

Commit 5f2fa44

Browse files
fix: pass database to capabilities query
1 parent e2f7a25 commit 5f2fa44

File tree

16 files changed

+95
-43
lines changed

16 files changed

+95
-43
lines changed

src/components/Tablet/Tablet.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ interface TabletProps {
1717
}
1818

1919
export const Tablet = ({tablet = {}, tenantName}: TabletProps) => {
20-
const {TabletId: id, NodeId, Type} = tablet;
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: tenantName});
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/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/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: 5 additions & 5 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, {createHref} from '../../routes';
1314
import {
1415
useCapabilitiesLoaded,
1516
useDiskPagesAvailable,
@@ -22,7 +23,7 @@ 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 {NODE_PAGES, OVERVIEW, STORAGE, STRUCTURE, TABLETS, nodePageQueryParams} from './NodePages';
2627
import NodeStructure from './NodeStructure/NodeStructure';
2728

2829
import './Node.scss';
@@ -40,13 +41,12 @@ export function Node(props: NodeProps) {
4041
const container = React.useRef<HTMLDivElement>(null);
4142

4243
const dispatch = useTypedDispatch();
43-
const location = useLocation();
4444

4545
const match =
4646
useRouteMatch<{id: string; activeTab: string}>(routes.node) ?? Object.create(null);
4747

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

5151
const [autoRefreshInterval] = useAutoRefreshInterval();
5252
const {currentData, isFetching, error} = nodeApi.useGetNodeInfoQuery(

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(

src/containers/Tablet/Tablet.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {Flex, Tabs} from '@gravity-ui/uikit';
44
import {skipToken} from '@reduxjs/toolkit/query';
55
import {Helmet} from 'react-helmet-async';
66
import {useParams} from 'react-router-dom';
7-
import {StringParam, useQueryParams} from 'use-query-params';
7+
import {useQueryParams} from 'use-query-params';
88
import {z} from 'zod';
99

1010
import {EmptyStateWrapper} from '../../components/EmptyState';
@@ -13,7 +13,7 @@ import {ResponseError} from '../../components/Errors/ResponseError';
1313
import {InternalLink} from '../../components/InternalLink';
1414
import {LoaderWrapper} from '../../components/LoaderWrapper/LoaderWrapper';
1515
import {PageMetaWithAutorefresh} from '../../components/PageMeta/PageMeta';
16-
import {getTabletPagePath} from '../../routes';
16+
import {getTabletPagePath, tabletPageQueryParams} from '../../routes';
1717
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
1818
import {setHeaderBreadcrumbs} from '../../store/reducers/header/header';
1919
import {tabletApi} from '../../store/reducers/tablet';
@@ -58,19 +58,13 @@ const TABLET_PAGE_TABS = [
5858

5959
const tabletTabSchema = z.nativeEnum(TABLET_TABS_IDS).catch(TABLET_TABS_IDS.history);
6060

61-
const tabletQueryParams = {
62-
tenantName: StringParam,
63-
clusterName: StringParam,
64-
activeTab: StringParam,
65-
};
66-
6761
export function Tablet() {
6862
const dispatch = useTypedDispatch();
6963

7064
const {id} = useParams<{id: string}>();
7165

72-
const [{tenantName: queryDatabase, clusterName: queryClusterName}] =
73-
useQueryParams(tabletQueryParams);
66+
const [{database: queryDatabase, clusterName: queryClusterName}] =
67+
useQueryParams(tabletPageQueryParams);
7468

7569
const [autoRefreshInterval] = useAutoRefreshInterval();
7670
const {currentData, isFetching, error} = tabletApi.useGetTabletQuery(
@@ -168,7 +162,7 @@ function TabletTabs({
168162
hiveId?: string;
169163
history: ITabletPreparedHistoryItem[];
170164
}) {
171-
const [{activeTab, ...restParams}, setParams] = useQueryParams(tabletQueryParams);
165+
const [{activeTab, ...restParams}, setParams] = useQueryParams(tabletPageQueryParams);
172166
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
173167

174168
const noAdvancedInfo = !isUserAllowedToMakeChanges || !hasHive(hiveId);

src/containers/Tenant/Diagnostics/Diagnostics.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function Diagnostics(props: DiagnosticsProps) {
5555
);
5656

5757
const [queryParams] = useQueryParams({
58-
name: StringParam,
58+
database: StringParam,
5959
schema: StringParam,
6060
backend: StringParam,
6161
clusterName: StringParam,

src/containers/Tenant/Tenant.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,21 @@ export function Tenant(props: TenantProps) {
4848
getTenantSummaryState,
4949
);
5050

51-
const [{name: tenantName, schema}] = useQueryParams({name: StringParam, schema: StringParam});
51+
// TODO: name is used together with database to keep old links valid
52+
// Remove it after some time - 1-2 weeks
53+
const [{database, name, schema}, setQuery] = useQueryParams({
54+
database: StringParam,
55+
name: StringParam,
56+
schema: StringParam,
57+
});
58+
59+
React.useEffect(() => {
60+
if (name && !database) {
61+
setQuery({database: name, name: undefined}, 'replaceIn');
62+
}
63+
}, [database, name, setQuery]);
64+
65+
const tenantName = database ?? name;
5266

5367
if (!tenantName) {
5468
throw new Error('Tenant name is not defined');

0 commit comments

Comments
 (0)