Skip to content

Commit 68e39e5

Browse files
committed
Only 1 master environment can be created
1 parent ae24fed commit 68e39e5

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

client/packages/lowcoder/src/pages/setting/environments/components/CreateEnvironmentModal.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React, { useState } from 'react';
2-
import { Modal, Form, Input, Select, Switch, Button, Alert } from 'antd';
2+
import { Modal, Form, Input, Select, Switch, Button, Alert, Tooltip } from 'antd';
3+
import { useSelector } from 'react-redux';
4+
import { selectMasterEnvironment, selectHasMasterEnvironment } from 'redux/selectors/enterpriseSelectors';
35
import { Environment } from '../types/environment.types';
46

57
const { Option } = Select;
@@ -20,6 +22,10 @@ const CreateEnvironmentModal: React.FC<CreateEnvironmentModalProps> = ({
2022
const [form] = Form.useForm();
2123
const [submitLoading, setSubmitLoading] = useState(false);
2224

25+
// Redux selectors to check for existing master environment
26+
const hasMasterEnvironment = useSelector(selectHasMasterEnvironment);
27+
const masterEnvironment = useSelector(selectMasterEnvironment);
28+
2329
const handleSubmit = async () => {
2430
try {
2531
const values = await form.validateFields();
@@ -151,9 +157,23 @@ const CreateEnvironmentModal: React.FC<CreateEnvironmentModalProps> = ({
151157
label="Master Environment"
152158
valuePropName="checked"
153159
>
154-
<Switch />
160+
<Tooltip
161+
title={hasMasterEnvironment ? `${masterEnvironment?.environmentName || 'Unknown'} is already the Master environment` : ""}
162+
>
163+
<Switch disabled={hasMasterEnvironment} />
164+
</Tooltip>
155165
</Form.Item>
156166

167+
{hasMasterEnvironment && (
168+
<Alert
169+
message="Master Environment Already Exists"
170+
description={`The environment "${masterEnvironment?.environmentName || 'Unknown'}" is already set as the Master environment. Only one Master environment is allowed.`}
171+
type="warning"
172+
showIcon
173+
style={{ marginBottom: '16px' }}
174+
/>
175+
)}
176+
157177
<Alert
158178
message="License Information"
159179
description="After creating the environment, the system will automatically check the license status. Make sure the API service URL and API key are correctly configured for license validation."

client/packages/lowcoder/src/redux/selectors/enterpriseSelectors.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,13 @@ export const selectLicensedEnvironments = (state: AppState) => {
4646
return environments.filter(env => env.isLicensed !== false);
4747
};
4848

49+
export const selectMasterEnvironment = (state: AppState) => {
50+
const environments = state.ui.enterprise?.environments ?? [];
51+
return environments.find(env => env.isMaster) ?? null;
52+
};
53+
54+
export const selectHasMasterEnvironment = (state: AppState) => {
55+
const environments = state.ui.enterprise?.environments ?? [];
56+
return environments.some(env => env.isMaster);
57+
};
58+

0 commit comments

Comments
 (0)