Skip to content
Open
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
15 changes: 15 additions & 0 deletions ui/apps/pmm/src/pages/settings/Settings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}));
Expand All @@ -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) =>
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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()
);
});
});
});
22 changes: 15 additions & 7 deletions ui/apps/pmm/src/pages/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)) {
Comment thread
matejkubinec marked this conversation as resolved.
return (
<Page title={Messages.title}>
<Stack alignItems="center" py={4}>
Expand All @@ -39,6 +41,10 @@ export const Settings: FC = () => {

const setTab = (value: TabValue) => navigate(`/settings/${value}`);

if (haStatus?.status === 'Enabled' && tab === 'ssh-key') {
return <Navigate to="/settings" replace />;
}

return (
<Page
title={Messages.title}
Expand All @@ -65,11 +71,13 @@ export const Settings: FC = () => {
value="advanced-settings"
label={Messages.tabs.advanced}
/>
<Tab
data-testid="settings-tab-ssh"
value="ssh-key"
label={Messages.tabs.ssh}
/>
{haStatus?.status === 'Disabled' && (
<Tab
data-testid="settings-tab-ssh"
value="ssh-key"
label={Messages.tabs.ssh}
/>
)}
</Tabs>

<Box sx={{ flex: 1 }} data-testid="settings-tab-content">
Expand Down
Loading