diff --git a/frontend/src/component/project/ProjectEnvironment/ProjectEnvironment.tsx b/frontend/src/component/project/ProjectEnvironment/ProjectEnvironment.tsx index b86b5c23d4..7af0f66680 100644 --- a/frontend/src/component/project/ProjectEnvironment/ProjectEnvironment.tsx +++ b/frontend/src/component/project/ProjectEnvironment/ProjectEnvironment.tsx @@ -148,8 +148,26 @@ const ProjectEnvironmentList = () => { } }; - const envIsDisabled = (projectName: string) => { - return isOss() && projectName === 'default'; + const envIsDisabled = (env: IProjectEnvironment) => { + return ( + (isOss() && env.name === 'default') || + (env.projectVisible && onlyOneEnvEnabled()) + ); + }; + + const onlyOneEnvEnabled = (): boolean => { + return ( + projectEnvironments.filter((env) => env.projectVisible).length === 1 + ); + }; + + const buildToolTip = (env: IProjectEnvironment): string => { + if (env.projectVisible && onlyOneEnvEnabled()) { + return 'Cannot disable, at least one environment must be visible in the project'; + } + return env.projectVisible + ? 'Hide environment and disable feature flags' + : 'Make it visible'; }; const COLUMNS = useMemo( @@ -182,13 +200,9 @@ const ProjectEnvironmentList = () => { Cell: ({ row: { original } }: any) => ( { expect(created).toMatchObject(allEnabledEnvs); }); - test('an empty list throws an error', async () => { - // You shouldn't be allowed to pass an empty list via the API. - // This test checks what happens in the event that an empty - // list manages to sneak in. - await expect(createProjectWithEnvs([])).rejects.toThrow(BadDataError); - }); - test('it only enables the envs it is asked to enable', async () => { const selectedEnvs = ['development', 'production']; const created = await createProjectWithEnvs(selectedEnvs); diff --git a/src/lib/features/project/project-service.ts b/src/lib/features/project/project-service.ts index 106866e4c7..fef6517a20 100644 --- a/src/lib/features/project/project-service.ts +++ b/src/lib/features/project/project-service.ts @@ -315,12 +315,6 @@ export default class ProjectService { async validateProjectEnvironments(environments: string[] | undefined) { if (environments) { - if (environments.length === 0) { - throw new BadDataError( - 'A project must always have at least one environment.', - ); - } - await this.validateEnvironmentsExist(environments); } } @@ -383,7 +377,7 @@ export default class ProjectService { await this.projectStore.create(data); - const envsToEnable = newProject.environments?.length + const envsToEnable = newProject.environments ? newProject.environments : ( await this.environmentStore.getAll({