Skip to content

Commit 88d731f

Browse files
authored
fix: monitoring show conditions (#3080)
1 parent 2a05ad5 commit 88d731f

File tree

6 files changed

+75
-10
lines changed

6 files changed

+75
-10
lines changed

src/components/TenantNameWrapper/TenantNameWrapper.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import {DefinitionList, Flex} from '@gravity-ui/uikit';
22

33
import {getTenantPath} from '../../routes';
4+
import {useClusterBaseInfo} from '../../store/reducers/cluster/cluster';
45
import type {PreparedTenant} from '../../store/reducers/tenants/types';
56
import type {AdditionalTenantsProps} from '../../types/additionalProps';
67
import {uiFactory} from '../../uiFactory/uiFactory';
78
import {getDatabaseLinks} from '../../utils/additionalProps';
89
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
10+
import {canShowTenantMonitoring} from '../../utils/monitoringVisibility';
911
import {EntityStatus} from '../EntityStatus/EntityStatus';
1012
import {LinkWithIcon} from '../LinkWithIcon/LinkWithIcon';
1113

@@ -40,13 +42,18 @@ export function TenantNameWrapper({tenant, additionalTenantsProps}: TenantNameWr
4042
const isExternalLink = Boolean(backend);
4143

4244
const links = getDatabaseLinks(additionalTenantsProps, tenant?.Name, tenant?.Type);
45+
const {monitoring: clusterMonitoring} = useClusterBaseInfo();
46+
const showMonitoring = canShowTenantMonitoring(tenant?.ControlPlane, clusterMonitoring);
47+
const filteredLinks = showMonitoring
48+
? links
49+
: links.filter(({title}) => title !== i18n('field_monitoring-link'));
4350

4451
const infoPopoverContent =
45-
links.length > 0 && isUserAllowedToMakeChanges ? (
52+
filteredLinks.length > 0 && isUserAllowedToMakeChanges ? (
4653
<DefinitionList responsive>
4754
<DefinitionList.Item name={i18n('field_links')}>
4855
<Flex gap={2} wrap="wrap">
49-
{links.map(({title, url}) => (
56+
{filteredLinks.map(({title, url}) => (
5057
<LinkWithIcon key={title} title={title} url={url} />
5158
))}
5259
</Flex>

src/containers/Header/Header.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
useIsUserAllowedToMakeChanges,
4040
useIsViewerUser,
4141
} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
42+
import {canShowTenantMonitoring} from '../../utils/monitoringVisibility';
4243
import {isAccessError} from '../../utils/response';
4344

4445
import {getBreadcrumbs} from './breadcrumbs';
@@ -92,8 +93,17 @@ function Header() {
9293
const {currentData: databaseData, isLoading: isDatabaseDataLoading} =
9394
tenantApi.useGetTenantInfoQuery(params);
9495

96+
// Show Monitoring only when:
97+
// - ControlPlane exists AND has a non-empty id
98+
// - OR ControlPlane is absent, but cluster-level monitoring meta exists
99+
const controlPlane = databaseData?.ControlPlane;
100+
const canShowMonitoring = canShowTenantMonitoring(controlPlane, monitoring);
95101
const monitoringLinkUrl =
96-
monitoring && uiFactory.getMonitoringLink && databaseData?.Name && databaseData?.Type
102+
canShowMonitoring &&
103+
monitoring &&
104+
uiFactory.getMonitoringLink &&
105+
databaseData?.Name &&
106+
databaseData?.Type
97107
? uiFactory.getMonitoringLink({
98108
monitoring,
99109
clusterName,

src/containers/Tenant/Diagnostics/Diagnostics.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import {
99
useConfigAvailable,
1010
useTopicDataAvailable,
1111
} from '../../../store/reducers/capabilities/hooks';
12+
import {useClusterBaseInfo} from '../../../store/reducers/cluster/cluster';
1213
import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../store/reducers/tenant/constants';
1314
import {setDiagnosticsTab, useTenantBaseInfo} from '../../../store/reducers/tenant/tenant';
1415
import type {AdditionalTenantsProps} from '../../../types/additionalProps';
1516
import {uiFactory} from '../../../uiFactory/uiFactory';
1617
import {cn} from '../../../utils/cn';
1718
import {useScrollPosition, useTypedDispatch, useTypedSelector} from '../../../utils/hooks';
1819
import {useIsViewerUser} from '../../../utils/hooks/useIsUserAllowedToMakeChanges';
20+
import {canShowTenantMonitoringTab} from '../../../utils/monitoringVisibility';
1921
import {Configs} from '../../Configs/Configs';
2022
import {Heatmap} from '../../Heatmap';
2123
import {Nodes} from '../../Nodes/Nodes';
@@ -61,6 +63,7 @@ function Diagnostics({additionalTenantProps}: DiagnosticsProps) {
6163
const {controlPlane, databaseType} = useTenantBaseInfo(
6264
isDatabaseEntityType(type) ? database : '',
6365
);
66+
const {monitoring: clusterMonitoring} = useClusterBaseInfo();
6467

6568
const hasConfigs = useConfigAvailable();
6669
const hasTopicData = useTopicDataAvailable();
@@ -71,7 +74,7 @@ function Diagnostics({additionalTenantProps}: DiagnosticsProps) {
7174
hasBackups: typeof uiFactory.renderBackups === 'function' && Boolean(controlPlane),
7275
hasConfigs: isViewerUser && hasConfigs,
7376
hasAccess: uiFactory.hasAccess,
74-
hasMonitoring: typeof uiFactory.renderMonitoring === 'function',
77+
hasMonitoring: canShowTenantMonitoringTab(controlPlane, clusterMonitoring),
7578
databaseType,
7679
});
7780
let activeTab = pages.find((el) => el.id === diagnosticsTab);

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {EntityStatus} from '../../../../components/EntityStatus/EntityStatus';
55
import {LoaderWrapper} from '../../../../components/LoaderWrapper/LoaderWrapper';
66
import {QueriesActivityBar} from '../../../../components/QueriesActivityBar/QueriesActivityBar';
77
import {useDatabasesAvailable} from '../../../../store/reducers/capabilities/hooks';
8+
import {useClusterBaseInfo} from '../../../../store/reducers/cluster/cluster';
89
import {overviewApi} from '../../../../store/reducers/overview/overview';
910
import {
1011
TENANT_DIAGNOSTICS_TABS_IDS,
@@ -18,11 +19,11 @@ import {
1819
} from '../../../../store/reducers/tenant/tenant';
1920
import {calculateTenantMetrics} from '../../../../store/reducers/tenants/utils';
2021
import type {AdditionalTenantsProps} from '../../../../types/additionalProps';
21-
import {uiFactory} from '../../../../uiFactory/uiFactory';
2222
import {getInfoTabLinks} from '../../../../utils/additionalProps';
2323
import {TENANT_DEFAULT_TITLE} from '../../../../utils/constants';
2424
import {useAutoRefreshInterval, useTypedDispatch, useTypedSelector} from '../../../../utils/hooks';
2525
import {useClusterNameFromQuery} from '../../../../utils/hooks/useDatabaseFromQuery';
26+
import {canShowTenantMonitoringTab} from '../../../../utils/monitoringVisibility';
2627
import {mapDatabaseTypeToDBName} from '../../utils/schema';
2728

2829
import {HealthcheckPreview} from './Healthcheck/HealthcheckPreview';
@@ -188,7 +189,11 @@ export function TenantOverview({
188189
};
189190

190191
const links = getInfoTabLinks(additionalTenantProps, Name, Type);
191-
const monitoringTabAvailable = Boolean(uiFactory.renderMonitoring);
192+
const {monitoring: clusterMonitoring} = useClusterBaseInfo();
193+
const monitoringTabAvailable = canShowTenantMonitoringTab(
194+
tenant?.ControlPlane,
195+
clusterMonitoring,
196+
);
192197

193198
const handleOpenMonitoring = () => {
194199
dispatch(setTenantPage(TENANT_PAGES_IDS.diagnostics));

src/containers/Tenant/ObjectSummary/SchemaTree/SchemaTree.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ import {
1010
useCreateDirectoryFeatureAvailable,
1111
useTopicDataAvailable,
1212
} from '../../../../store/reducers/capabilities/hooks';
13+
import {useClusterBaseInfo} from '../../../../store/reducers/cluster/cluster';
1314
import {selectIsDirty, selectUserInput} from '../../../../store/reducers/query/query';
1415
import {schemaApi} from '../../../../store/reducers/schema/schema';
1516
import {streamingQueriesApi} from '../../../../store/reducers/streamingQuery/streamingQuery';
1617
import {tableSchemaDataApi} from '../../../../store/reducers/tableSchemaData';
18+
import {useTenantBaseInfo} from '../../../../store/reducers/tenant/tenant';
1719
import type {EPathType, TEvDescribeSchemeResult} from '../../../../types/api/schema';
18-
import {uiFactory} from '../../../../uiFactory/uiFactory';
1920
import {valueIsDefined} from '../../../../utils';
2021
import {useTypedDispatch, useTypedSelector} from '../../../../utils/hooks';
2122
import {getConfirmation} from '../../../../utils/hooks/withConfirmation/useChangeInputWithConfirmation';
23+
import {canShowTenantMonitoringTab} from '../../../../utils/monitoringVisibility';
2224
import {getSchemaControls} from '../../utils/controls';
2325
import {
2426
isChildlessPathType,
@@ -139,7 +141,10 @@ export function SchemaTree(props: SchemaTreeProps) {
139141
setCreateDirectoryOpen(true);
140142
};
141143

144+
const {monitoring: clusterMonitoring} = useClusterBaseInfo();
145+
const {controlPlane} = useTenantBaseInfo(database);
142146
const getTreeNodeActions = React.useMemo(() => {
147+
const hasMonitoring = canShowTenantMonitoringTab(controlPlane, clusterMonitoring);
143148
return getActions(
144149
dispatch,
145150
{
@@ -151,7 +156,7 @@ export function SchemaTree(props: SchemaTreeProps) {
151156
getConnectToDBDialog,
152157
schemaData: actionsSchemaData,
153158
isSchemaDataLoading: isActionsDataFetching,
154-
hasMonitoring: typeof uiFactory.renderMonitoring === 'function',
159+
hasMonitoring,
155160
streamingQueryData: streamingSysData,
156161
isStreamingQueryTextLoading: isStreamingInfoFetching,
157162
},
@@ -167,9 +172,11 @@ export function SchemaTree(props: SchemaTreeProps) {
167172
isDirty,
168173
isStreamingInfoFetching,
169174
onActivePathUpdate,
170-
databaseFullPath,
171-
database,
172175
streamingSysData,
176+
database,
177+
databaseFullPath,
178+
controlPlane,
179+
clusterMonitoring,
173180
]);
174181

175182
return (

src/utils/monitoringVisibility.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type {MetaBaseClusterInfo} from '../types/api/meta';
2+
import type {ControlPlane} from '../types/api/tenant';
3+
import {uiFactory} from '../uiFactory/uiFactory';
4+
5+
/**
6+
* Centralized check for whether Monitoring should be shown for a database.
7+
* Rule:
8+
* - If ControlPlane exists, require a non-empty id.
9+
* - If ControlPlane does not exist, fallback to cluster monitoring meta presence.
10+
*/
11+
export function canShowTenantMonitoring(
12+
controlPlane?: ControlPlane,
13+
clusterMonitoring?: MetaBaseClusterInfo['solomon'],
14+
): boolean {
15+
if (controlPlane) {
16+
return Boolean(controlPlane.id);
17+
}
18+
return Boolean(clusterMonitoring);
19+
}
20+
21+
/**
22+
* Unified visibility check for the Monitoring tab/button.
23+
* Combines UI factory capability and tenant/cluster monitoring availability.
24+
*/
25+
export function canShowTenantMonitoringTab(
26+
controlPlane?: ControlPlane,
27+
clusterMonitoring?: MetaBaseClusterInfo['solomon'],
28+
): boolean {
29+
return (
30+
Boolean(uiFactory.renderMonitoring) &&
31+
canShowTenantMonitoring(controlPlane, clusterMonitoring)
32+
);
33+
}

0 commit comments

Comments
 (0)