Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/components/TenantNameWrapper/TenantNameWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {DefinitionList, Flex} from '@gravity-ui/uikit';

import {getTenantPath} from '../../routes';
import {useClusterBaseInfo} from '../../store/reducers/cluster/cluster';
import type {PreparedTenant} from '../../store/reducers/tenants/types';
import type {AdditionalTenantsProps} from '../../types/additionalProps';
import {uiFactory} from '../../uiFactory/uiFactory';
import {getDatabaseLinks} from '../../utils/additionalProps';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {canShowTenantMonitoring} from '../../utils/monitoringVisibility';
import {EntityStatus} from '../EntityStatus/EntityStatus';
import {LinkWithIcon} from '../LinkWithIcon/LinkWithIcon';

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

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

const infoPopoverContent =
links.length > 0 && isUserAllowedToMakeChanges ? (
filteredLinks.length > 0 && isUserAllowedToMakeChanges ? (
<DefinitionList responsive>
<DefinitionList.Item name={i18n('field_links')}>
<Flex gap={2} wrap="wrap">
{links.map(({title, url}) => (
{filteredLinks.map(({title, url}) => (
<LinkWithIcon key={title} title={title} url={url} />
))}
</Flex>
Expand Down
12 changes: 11 additions & 1 deletion src/containers/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
useIsUserAllowedToMakeChanges,
useIsViewerUser,
} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {canShowTenantMonitoring} from '../../utils/monitoringVisibility';
import {isAccessError} from '../../utils/response';

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

// Show Monitoring only when:
// - ControlPlane exists AND has a non-empty id
// - OR ControlPlane is absent, but cluster-level monitoring meta exists
const controlPlane = databaseData?.ControlPlane;
const canShowMonitoring = canShowTenantMonitoring(controlPlane, monitoring);
const monitoringLinkUrl =
monitoring && uiFactory.getMonitoringLink && databaseData?.Name && databaseData?.Type
canShowMonitoring &&
monitoring &&
uiFactory.getMonitoringLink &&
databaseData?.Name &&
databaseData?.Type
? uiFactory.getMonitoringLink({
monitoring,
clusterName,
Expand Down
5 changes: 4 additions & 1 deletion src/containers/Tenant/Diagnostics/Diagnostics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {
useConfigAvailable,
useTopicDataAvailable,
} from '../../../store/reducers/capabilities/hooks';
import {useClusterBaseInfo} from '../../../store/reducers/cluster/cluster';
import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../store/reducers/tenant/constants';
import {setDiagnosticsTab, useTenantBaseInfo} from '../../../store/reducers/tenant/tenant';
import type {AdditionalTenantsProps} from '../../../types/additionalProps';
import {uiFactory} from '../../../uiFactory/uiFactory';
import {cn} from '../../../utils/cn';
import {useScrollPosition, useTypedDispatch, useTypedSelector} from '../../../utils/hooks';
import {useIsViewerUser} from '../../../utils/hooks/useIsUserAllowedToMakeChanges';
import {canShowTenantMonitoringTab} from '../../../utils/monitoringVisibility';
import {Configs} from '../../Configs/Configs';
import {Heatmap} from '../../Heatmap';
import {Nodes} from '../../Nodes/Nodes';
Expand Down Expand Up @@ -61,6 +63,7 @@ function Diagnostics({additionalTenantProps}: DiagnosticsProps) {
const {controlPlane, databaseType} = useTenantBaseInfo(
isDatabaseEntityType(type) ? database : '',
);
const {monitoring: clusterMonitoring} = useClusterBaseInfo();

const hasConfigs = useConfigAvailable();
const hasTopicData = useTopicDataAvailable();
Expand All @@ -71,7 +74,7 @@ function Diagnostics({additionalTenantProps}: DiagnosticsProps) {
hasBackups: typeof uiFactory.renderBackups === 'function' && Boolean(controlPlane),
hasConfigs: isViewerUser && hasConfigs,
hasAccess: uiFactory.hasAccess,
hasMonitoring: typeof uiFactory.renderMonitoring === 'function',
hasMonitoring: canShowTenantMonitoringTab(controlPlane, clusterMonitoring),
databaseType,
});
let activeTab = pages.find((el) => el.id === diagnosticsTab);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {EntityStatus} from '../../../../components/EntityStatus/EntityStatus';
import {LoaderWrapper} from '../../../../components/LoaderWrapper/LoaderWrapper';
import {QueriesActivityBar} from '../../../../components/QueriesActivityBar/QueriesActivityBar';
import {useDatabasesAvailable} from '../../../../store/reducers/capabilities/hooks';
import {useClusterBaseInfo} from '../../../../store/reducers/cluster/cluster';
import {overviewApi} from '../../../../store/reducers/overview/overview';
import {
TENANT_DIAGNOSTICS_TABS_IDS,
Expand All @@ -18,11 +19,11 @@ import {
} from '../../../../store/reducers/tenant/tenant';
import {calculateTenantMetrics} from '../../../../store/reducers/tenants/utils';
import type {AdditionalTenantsProps} from '../../../../types/additionalProps';
import {uiFactory} from '../../../../uiFactory/uiFactory';
import {getInfoTabLinks} from '../../../../utils/additionalProps';
import {TENANT_DEFAULT_TITLE} from '../../../../utils/constants';
import {useAutoRefreshInterval, useTypedDispatch, useTypedSelector} from '../../../../utils/hooks';
import {useClusterNameFromQuery} from '../../../../utils/hooks/useDatabaseFromQuery';
import {canShowTenantMonitoringTab} from '../../../../utils/monitoringVisibility';
import {mapDatabaseTypeToDBName} from '../../utils/schema';

import {HealthcheckPreview} from './Healthcheck/HealthcheckPreview';
Expand Down Expand Up @@ -188,7 +189,11 @@ export function TenantOverview({
};

const links = getInfoTabLinks(additionalTenantProps, Name, Type);
const monitoringTabAvailable = Boolean(uiFactory.renderMonitoring);
const {monitoring: clusterMonitoring} = useClusterBaseInfo();
const monitoringTabAvailable = canShowTenantMonitoringTab(
tenant?.ControlPlane,
clusterMonitoring,
);

const handleOpenMonitoring = () => {
dispatch(setTenantPage(TENANT_PAGES_IDS.diagnostics));
Expand Down
15 changes: 11 additions & 4 deletions src/containers/Tenant/ObjectSummary/SchemaTree/SchemaTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ import {
useCreateDirectoryFeatureAvailable,
useTopicDataAvailable,
} from '../../../../store/reducers/capabilities/hooks';
import {useClusterBaseInfo} from '../../../../store/reducers/cluster/cluster';
import {selectIsDirty, selectUserInput} from '../../../../store/reducers/query/query';
import {schemaApi} from '../../../../store/reducers/schema/schema';
import {streamingQueriesApi} from '../../../../store/reducers/streamingQuery/streamingQuery';
import {tableSchemaDataApi} from '../../../../store/reducers/tableSchemaData';
import {useTenantBaseInfo} from '../../../../store/reducers/tenant/tenant';
import type {EPathType, TEvDescribeSchemeResult} from '../../../../types/api/schema';
import {uiFactory} from '../../../../uiFactory/uiFactory';
import {valueIsDefined} from '../../../../utils';
import {useTypedDispatch, useTypedSelector} from '../../../../utils/hooks';
import {getConfirmation} from '../../../../utils/hooks/withConfirmation/useChangeInputWithConfirmation';
import {canShowTenantMonitoringTab} from '../../../../utils/monitoringVisibility';
import {getSchemaControls} from '../../utils/controls';
import {
isChildlessPathType,
Expand Down Expand Up @@ -139,7 +141,10 @@ export function SchemaTree(props: SchemaTreeProps) {
setCreateDirectoryOpen(true);
};

const {monitoring: clusterMonitoring} = useClusterBaseInfo();
const {controlPlane} = useTenantBaseInfo(database);
const getTreeNodeActions = React.useMemo(() => {
const hasMonitoring = canShowTenantMonitoringTab(controlPlane, clusterMonitoring);
return getActions(
dispatch,
{
Expand All @@ -151,7 +156,7 @@ export function SchemaTree(props: SchemaTreeProps) {
getConnectToDBDialog,
schemaData: actionsSchemaData,
isSchemaDataLoading: isActionsDataFetching,
hasMonitoring: typeof uiFactory.renderMonitoring === 'function',
hasMonitoring,
streamingQueryData: streamingSysData,
isStreamingQueryTextLoading: isStreamingInfoFetching,
},
Expand All @@ -167,9 +172,11 @@ export function SchemaTree(props: SchemaTreeProps) {
isDirty,
isStreamingInfoFetching,
onActivePathUpdate,
databaseFullPath,
database,
streamingSysData,
database,
databaseFullPath,
controlPlane,
clusterMonitoring,
]);

return (
Expand Down
33 changes: 33 additions & 0 deletions src/utils/monitoringVisibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type {MetaBaseClusterInfo} from '../types/api/meta';
import type {ControlPlane} from '../types/api/tenant';
import {uiFactory} from '../uiFactory/uiFactory';

/**
* Centralized check for whether Monitoring should be shown for a database.
* Rule:
* - If ControlPlane exists, require a non-empty id.
* - If ControlPlane does not exist, fallback to cluster monitoring meta presence.
*/
export function canShowTenantMonitoring(
controlPlane?: ControlPlane,
clusterMonitoring?: MetaBaseClusterInfo['solomon'],
): boolean {
if (controlPlane) {
return Boolean(controlPlane.id);
}
return Boolean(clusterMonitoring);
}

/**
* Unified visibility check for the Monitoring tab/button.
* Combines UI factory capability and tenant/cluster monitoring availability.
*/
export function canShowTenantMonitoringTab(
controlPlane?: ControlPlane,
clusterMonitoring?: MetaBaseClusterInfo['solomon'],
): boolean {
return (
Boolean(uiFactory.renderMonitoring) &&
canShowTenantMonitoring(controlPlane, clusterMonitoring)
);
}
Loading