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:
parent
1d7cd2e274
commit
94926b7802
@ -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();
|
|
||||||
});
|
|
||||||
});
|
|
@ -3,29 +3,18 @@ import Add from '@mui/icons-material/Add';
|
|||||||
import { ADMIN } from 'component/providers/AccessProvider/permissions';
|
import { ADMIN } from 'component/providers/AccessProvider/permissions';
|
||||||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useEnvironments } from 'hooks/api/getters/useEnvironments/useEnvironments';
|
|
||||||
|
|
||||||
export const CreateEnvironmentButton = () => {
|
export const CreateEnvironmentButton = () => {
|
||||||
const { uiConfig } = useUiConfig();
|
const { uiConfig } = useUiConfig();
|
||||||
const { environments } = useEnvironments();
|
|
||||||
const environmentLimit = uiConfig.resourceLimits.environments;
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const limitReached = environments.length >= environmentLimit;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ResponsiveButton
|
<ResponsiveButton
|
||||||
tooltipProps={{
|
|
||||||
arrow: true,
|
|
||||||
title: limitReached
|
|
||||||
? `You have reached the limit of environments you can create (${environmentLimit}).`
|
|
||||||
: undefined,
|
|
||||||
}}
|
|
||||||
onClick={() => navigate('/environments/create')}
|
onClick={() => navigate('/environments/create')}
|
||||||
maxWidth='700px'
|
maxWidth='700px'
|
||||||
Icon={Add}
|
Icon={Add}
|
||||||
permission={ADMIN}
|
permission={ADMIN}
|
||||||
disabled={limitReached || !uiConfig.flags.EEA}
|
disabled={!uiConfig.flags.EEA}
|
||||||
>
|
>
|
||||||
New environment
|
New environment
|
||||||
</ResponsiveButton>
|
</ResponsiveButton>
|
||||||
|
Loading…
Reference in New Issue
Block a user