Skip to content

Commit 53a7902

Browse files
authored
feat: support use database id in links (#2812)
1 parent b7e7625 commit 53a7902

File tree

7 files changed

+16
-7
lines changed

7 files changed

+16
-7
lines changed

src/components/TenantNameWrapper/TenantNameWrapper.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {DefinitionList, Flex} from '@gravity-ui/uikit';
33
import {getTenantPath} from '../../containers/Tenant/TenantPages';
44
import type {PreparedTenant} from '../../store/reducers/tenants/types';
55
import type {AdditionalTenantsProps} from '../../types/additionalProps';
6+
import {uiFactory} from '../../uiFactory/uiFactory';
67
import {getDatabaseLinks} from '../../utils/additionalProps';
78
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
89
import {EntityStatus} from '../EntityStatus/EntityStatus';
@@ -63,7 +64,7 @@ export function TenantNameWrapper({tenant, additionalTenantsProps}: TenantNameWr
6364
hasClipboardButton
6465
path={getTenantPath(
6566
{
66-
database: tenant.Name,
67+
database: uiFactory.useDatabaseId ? tenant.Id : tenant.Name,
6768
backend,
6869
},
6970
{withBasename: isExternalLink},

src/containers/Header/breadcrumbs.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
TENANT_PAGE,
2525
TENANT_PAGES_IDS,
2626
} from '../../store/reducers/tenant/constants';
27+
import {uiFactory} from '../../uiFactory/uiFactory';
2728
import {CLUSTER_DEFAULT_TITLE, getTabletLabel} from '../../utils/constants';
2829
import {getClusterPath} from '../Cluster/utils';
2930
import {getDefaultNodePath} from '../Node/NodePages';
@@ -84,12 +85,14 @@ const getClusterBreadcrumbs: GetBreadcrumbs<ClusterBreadcrumbsOptions> = (option
8485
};
8586

8687
const getTenantBreadcrumbs: GetBreadcrumbs<TenantBreadcrumbsOptions> = (options, query = {}) => {
87-
const {tenantName} = options;
88+
const {tenantName, tenantId} = options;
8889

8990
const breadcrumbs = getClusterBreadcrumbs(options, query);
9091

9192
const text = tenantName || headerKeyset('breadcrumbs.tenant');
92-
const link = tenantName ? getTenantPath({...query, database: tenantName}) : undefined;
93+
const link = tenantName
94+
? getTenantPath({...query, database: uiFactory.useDatabaseId ? tenantId : tenantName})
95+
: undefined;
9396

9497
const lastItem = {text, link, icon: <DatabaseIcon />};
9598
breadcrumbs.push(lastItem);

src/containers/Tenant/Tenant.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function Tenant(props: TenantProps) {
5656

5757
const {database, schema} = useTenantQueryParams();
5858

59-
const {controlPlane, name} = useTenantBaseInfo(database ?? '');
59+
const {controlPlane, name, id} = useTenantBaseInfo(database ?? '');
6060

6161
if (!database) {
6262
throw new Error('Tenant name is not defined');
@@ -88,8 +88,8 @@ export function Tenant(props: TenantProps) {
8888

8989
const dispatch = useTypedDispatch();
9090
React.useEffect(() => {
91-
dispatch(setHeaderBreadcrumbs('tenant', {tenantName: databaseName}));
92-
}, [databaseName, dispatch]);
91+
dispatch(setHeaderBreadcrumbs('tenant', {tenantName: databaseName, tenantId: id}));
92+
}, [databaseName, id, dispatch]);
9393

9494
const preloadedData = useTypedSelector((state) =>
9595
selectSchemaObjectData(state, path, database),

src/store/reducers/header/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface ClusterBreadcrumbsOptions extends ClustersBreadcrumbsOptions {
2424

2525
export interface TenantBreadcrumbsOptions extends ClusterBreadcrumbsOptions {
2626
tenantName?: string;
27+
tenantId?: string;
2728
}
2829

2930
export interface StorageGroupBreadcrumbsOptions extends ClusterBreadcrumbsOptions {

src/store/reducers/tenant/tenant.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ export function useTenantBaseInfo(path: string) {
135135
{skip: !path},
136136
);
137137

138-
const {ControlPlane, Name} = currentData || {};
138+
const {ControlPlane, Name, Id} = currentData || {};
139139

140140
return {
141141
controlPlane: ControlPlane,
142142
name: Name,
143+
id: Id,
143144
};
144145
}

src/uiFactory/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export interface UIFactory<H extends string = CommonIssueType> {
4242
};
4343
hasAccess?: boolean;
4444
yaMetricaMap?: Record<string, number>;
45+
46+
useDatabaseId?: boolean;
4547
}
4648

4749
export type HandleCreateDB = (params: {clusterName: string}) => Promise<boolean>;

src/uiFactory/uiFactory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const uiFactoryBase: UIFactory = {
1919
countHealthcheckIssuesByType,
2020
},
2121
hasAccess: true,
22+
useDatabaseId: false,
2223
};
2324

2425
export function configureUIFactory<H extends string>(overrides: Partial<UIFactory<H>>) {

0 commit comments

Comments
 (0)