mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-24 01:18:01 +02:00
chore: flip UI and backend validation for project env disabling (#9395)
This commit is contained in:
parent
596577a1b7
commit
f3ede7681f
@ -148,8 +148,26 @@ const ProjectEnvironmentList = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const envIsDisabled = (projectName: string) => {
|
const envIsDisabled = (env: IProjectEnvironment) => {
|
||||||
return isOss() && projectName === 'default';
|
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(
|
const COLUMNS = useMemo(
|
||||||
@ -182,13 +200,9 @@ const ProjectEnvironmentList = () => {
|
|||||||
Cell: ({ row: { original } }: any) => (
|
Cell: ({ row: { original } }: any) => (
|
||||||
<ActionCell>
|
<ActionCell>
|
||||||
<PermissionSwitch
|
<PermissionSwitch
|
||||||
tooltip={
|
tooltip={buildToolTip(original)}
|
||||||
original.projectVisible
|
|
||||||
? 'Hide environment and disable feature flags'
|
|
||||||
: 'Make it visible'
|
|
||||||
}
|
|
||||||
size='medium'
|
size='medium'
|
||||||
disabled={envIsDisabled(original.name)}
|
disabled={envIsDisabled(original)}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
permission={UPDATE_PROJECT}
|
permission={UPDATE_PROJECT}
|
||||||
checked={original.projectVisible}
|
checked={original.projectVisible}
|
||||||
|
@ -2853,13 +2853,6 @@ describe('create project with environments', () => {
|
|||||||
expect(created).toMatchObject(allEnabledEnvs);
|
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 () => {
|
test('it only enables the envs it is asked to enable', async () => {
|
||||||
const selectedEnvs = ['development', 'production'];
|
const selectedEnvs = ['development', 'production'];
|
||||||
const created = await createProjectWithEnvs(selectedEnvs);
|
const created = await createProjectWithEnvs(selectedEnvs);
|
||||||
|
@ -315,12 +315,6 @@ export default class ProjectService {
|
|||||||
|
|
||||||
async validateProjectEnvironments(environments: string[] | undefined) {
|
async validateProjectEnvironments(environments: string[] | undefined) {
|
||||||
if (environments) {
|
if (environments) {
|
||||||
if (environments.length === 0) {
|
|
||||||
throw new BadDataError(
|
|
||||||
'A project must always have at least one environment.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.validateEnvironmentsExist(environments);
|
await this.validateEnvironmentsExist(environments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -383,7 +377,7 @@ export default class ProjectService {
|
|||||||
|
|
||||||
await this.projectStore.create(data);
|
await this.projectStore.create(data);
|
||||||
|
|
||||||
const envsToEnable = newProject.environments?.length
|
const envsToEnable = newProject.environments
|
||||||
? newProject.environments
|
? newProject.environments
|
||||||
: (
|
: (
|
||||||
await this.environmentStore.getAll({
|
await this.environmentStore.getAll({
|
||||||
|
Loading…
Reference in New Issue
Block a user