From 94926b78021a8ba065b971b5cb011ae87f074f68 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Fri, 5 Jul 2024 13:11:00 +0200 Subject: [PATCH] chore: don't prevent users from entering the env form when they're at the limit (#7549) This change reverts the changes related to the button in particular that were introduced in #7500. The button is now always enabled, and the actual resource warning and creation blocking happens in the form, courtesy of #7548. --- .../CreateEnvironmentButton.test.tsx | 55 ------------------- .../CreateEnvironmentButton.tsx | 13 +---- 2 files changed, 1 insertion(+), 67 deletions(-) delete mode 100644 frontend/src/component/environments/CreateEnvironmentButton/CreateEnvironmentButton.test.tsx diff --git a/frontend/src/component/environments/CreateEnvironmentButton/CreateEnvironmentButton.test.tsx b/frontend/src/component/environments/CreateEnvironmentButton/CreateEnvironmentButton.test.tsx deleted file mode 100644 index 998500931ad6..000000000000 --- a/frontend/src/component/environments/CreateEnvironmentButton/CreateEnvironmentButton.test.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import { screen, waitFor } from '@testing-library/react'; -import { render } from 'utils/testRenderer'; -import { testServerRoute, testServerSetup } from 'utils/testServer'; -import { CreateEnvironmentButton } from './CreateEnvironmentButton'; -import { ADMIN } from 'component/providers/AccessProvider/permissions'; - -const server = testServerSetup(); - -const setupApi = ({ - environmentCount, - environmentLimit, -}: { environmentCount: number; environmentLimit: number }) => { - testServerRoute(server, '/api/admin/ui-config', { - flags: { - resourceLimits: true, - EEA: true, - }, - resourceLimits: { - environments: environmentLimit, - }, - }); - - testServerRoute(server, '/api/admin/environments', { - environments: Array.from({ length: environmentCount }).map((_, i) => ({ - name: `environment-${i}`, - type: 'production', - enabled: i % 2 === 0, - })), - }); -}; - -test('should allow you to create environments when there are fewer environments than the limit', async () => { - setupApi({ environmentLimit: 5, environmentCount: 2 }); - - render(, { - permissions: [{ permission: ADMIN }], - }); - - await waitFor(async () => { - const button = await screen.findByRole('button'); - expect(button).not.toBeDisabled(); - }); -}); - -test('should not allow you to create environments when you have reached the limit', async () => { - setupApi({ environmentLimit: 5, environmentCount: 5 }); - render(, { - permissions: [{ permission: ADMIN }], - }); - - await waitFor(async () => { - const button = await screen.findByRole('button'); - expect(button).toBeDisabled(); - }); -}); diff --git a/frontend/src/component/environments/CreateEnvironmentButton/CreateEnvironmentButton.tsx b/frontend/src/component/environments/CreateEnvironmentButton/CreateEnvironmentButton.tsx index ec65a12113d5..186f568f468c 100644 --- a/frontend/src/component/environments/CreateEnvironmentButton/CreateEnvironmentButton.tsx +++ b/frontend/src/component/environments/CreateEnvironmentButton/CreateEnvironmentButton.tsx @@ -3,29 +3,18 @@ import Add from '@mui/icons-material/Add'; import { ADMIN } from 'component/providers/AccessProvider/permissions'; import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import { useNavigate } from 'react-router-dom'; -import { useEnvironments } from 'hooks/api/getters/useEnvironments/useEnvironments'; export const CreateEnvironmentButton = () => { const { uiConfig } = useUiConfig(); - const { environments } = useEnvironments(); - const environmentLimit = uiConfig.resourceLimits.environments; const navigate = useNavigate(); - const limitReached = environments.length >= environmentLimit; - return ( navigate('/environments/create')} maxWidth='700px' Icon={Add} permission={ADMIN} - disabled={limitReached || !uiConfig.flags.EEA} + disabled={!uiConfig.flags.EEA} > New environment