diff --git a/ui/apps/pmm/src/pages/settings/Settings.test.tsx b/ui/apps/pmm/src/pages/settings/Settings.test.tsx index 32b5a2b836c..92e079fec1d 100644 --- a/ui/apps/pmm/src/pages/settings/Settings.test.tsx +++ b/ui/apps/pmm/src/pages/settings/Settings.test.tsx @@ -4,9 +4,14 @@ import { Settings } from './Settings'; import { TestWrapper } from 'utils/testWrapper'; import { wrapWithQueryProvider } from 'utils/testUtils'; import * as settingsApi from 'api/settings'; +import * as haApi from 'api/ha'; import type { Settings as SettingsType } from 'types/settings.types'; vi.mock('api/settings'); +vi.mock('api/ha', () => ({ + getHAStatus: vi.fn(), + getHANodes: vi.fn(), +})); vi.mock('./components/metrics-resolution/MetricsResolutionForm', () => ({ MetricsResolutionForm: () => null, })); @@ -18,6 +23,7 @@ vi.mock('./components/ssh-key/SshKeyForm', () => ({ })); const getSettingsMock = vi.mocked(settingsApi.getSettings); +const getHAStatusMock = vi.mocked(haApi.getHAStatus); const mockSettings = {} as SettingsType; const renderWithRoute = (initialPath: string) => @@ -34,6 +40,7 @@ const renderWithRoute = (initialPath: string) => describe('Settings', () => { beforeEach(() => { getSettingsMock.mockImplementation(() => new Promise(() => {})); + getHAStatusMock.mockResolvedValue({ status: 'Disabled' }); }); it('shows loading state when settings are not yet loaded', () => { @@ -86,5 +93,13 @@ describe('Settings', () => { ) ); }); + + it('hides ssh tab when HA is enabled', async () => { + getHAStatusMock.mockResolvedValue({ status: 'Enabled' }); + renderWithRoute('/settings/metrics-resolution'); + await waitFor(() => + expect(screen.queryByTestId('settings-tab-ssh')).not.toBeInTheDocument() + ); + }); }); }); diff --git a/ui/apps/pmm/src/pages/settings/Settings.tsx b/ui/apps/pmm/src/pages/settings/Settings.tsx index 2632aba112f..12eeb554fc6 100644 --- a/ui/apps/pmm/src/pages/settings/Settings.tsx +++ b/ui/apps/pmm/src/pages/settings/Settings.tsx @@ -11,9 +11,10 @@ import { MetricsResolutionForm } from './components/metrics-resolution/MetricsRe import { AdvancedSettingsForm } from './components/advanced/AdvancedSettingsForm'; import { Messages } from './Settings.messages'; import { TabValue } from './Settings.types'; -import { useNavigate, useParams } from 'react-router-dom'; +import { Navigate, useNavigate, useParams } from 'react-router-dom'; import { OrgRole } from 'types/user.types'; import { useUser } from 'contexts/user'; +import { useHAStatus } from 'hooks/api/useHA'; export const Settings: FC = () => { const { user } = useUser(); @@ -25,9 +26,10 @@ export const Settings: FC = () => { } = useSettings({ enabled: !!user && user.isPMMAdmin, }); + const { data: haStatus, isLoading: isHAStatusLoading } = useHAStatus(); const navigate = useNavigate(); - if (isLoading || (isEnabled && !settings)) { + if (isLoading || isHAStatusLoading || (isEnabled && !settings)) { return ( @@ -39,6 +41,10 @@ export const Settings: FC = () => { const setTab = (value: TabValue) => navigate(`/settings/${value}`); + if (haStatus?.status === 'Enabled' && tab === 'ssh-key') { + return ; + } + return ( { value="advanced-settings" label={Messages.tabs.advanced} /> - + {haStatus?.status === 'Disabled' && ( + + )}