1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00

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.
This commit is contained in:
Thomas Heartman 2024-07-05 13:11:00 +02:00 committed by GitHub
parent 1d7cd2e274
commit 94926b7802
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 1 additions and 67 deletions

View File

@ -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(<CreateEnvironmentButton />, {
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(<CreateEnvironmentButton />, {
permissions: [{ permission: ADMIN }],
});
await waitFor(async () => {
const button = await screen.findByRole('button');
expect(button).toBeDisabled();
});
});

View File

@ -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 (
<ResponsiveButton
tooltipProps={{
arrow: true,
title: limitReached
? `You have reached the limit of environments you can create (${environmentLimit}).`
: undefined,
}}
onClick={() => navigate('/environments/create')}
maxWidth='700px'
Icon={Add}
permission={ADMIN}
disabled={limitReached || !uiConfig.flags.EEA}
disabled={!uiConfig.flags.EEA}
>
New environment
</ResponsiveButton>