Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4c6a81b

Browse files
committed
Fix only one master environment
1 parent68e39e5 commit4c6a81b

File tree

2 files changed

+93
-35
lines changed

2 files changed

+93
-35
lines changed

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

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,33 @@ const CreateEnvironmentModal: React.FC<CreateEnvironmentModalProps> = ({
2121
})=>{
2222
const[form]=Form.useForm();
2323
const[submitLoading,setSubmitLoading]=useState(false);
24+
const[isMaster,setIsMaster]=useState(false);
2425

2526
// Redux selectors to check for existing master environment
2627
consthasMasterEnvironment=useSelector(selectHasMasterEnvironment);
2728
constmasterEnvironment=useSelector(selectMasterEnvironment);
2829

30+
consthandleMasterChange=(checked:boolean)=>{
31+
// Only allow enabling master if no master environment exists
32+
if(checked&&hasMasterEnvironment){
33+
return;// Do nothing if trying to enable master when one already exists
34+
}
35+
setIsMaster(checked);
36+
};
37+
2938
consthandleSubmit=async()=>{
3039
try{
3140
constvalues=awaitform.validateFields();
3241
setSubmitLoading(true);
3342

34-
awaitonSave(values);
35-
form.resetFields();// Reset form after successful creation
43+
constsubmitData={
44+
...values,
45+
isMaster
46+
};
47+
48+
awaitonSave(submitData);
49+
form.resetFields();
50+
setIsMaster(false);// Reset master state
3651
onClose();
3752
}catch(error){
3853
if(errorinstanceofError){
@@ -44,7 +59,8 @@ const CreateEnvironmentModal: React.FC<CreateEnvironmentModalProps> = ({
4459
};
4560

4661
consthandleCancel=()=>{
47-
form.resetFields();// Reset form when canceling
62+
form.resetFields();
63+
setIsMaster(false);// Reset master state
4864
onClose();
4965
};
5066

@@ -74,8 +90,7 @@ const CreateEnvironmentModal: React.FC<CreateEnvironmentModalProps> = ({
7490
layout="vertical"
7591
name="create_environment_form"
7692
initialValues={{
77-
environmentType:"DEV",
78-
isMaster:false
93+
environmentType:"DEV"
7994
}}
8095
>
8196
<Form.Item
@@ -152,28 +167,30 @@ const CreateEnvironmentModal: React.FC<CreateEnvironmentModalProps> = ({
152167
/>
153168
</Form.Item>
154169

155-
<Form.Item
156-
name="isMaster"
157-
label="Master Environment"
158-
valuePropName="checked"
159-
>
160-
<Tooltip
161-
title={hasMasterEnvironment ?`${masterEnvironment?.environmentName||'Unknown'} is already the Master environment` :""}
162-
>
163-
<Switchdisabled={hasMasterEnvironment}/>
164-
</Tooltip>
170+
<Form.Itemlabel="Master Environment">
171+
<divstyle={{display:'flex',alignItems:'center',gap:'12px'}}>
172+
<Tooltip
173+
title={
174+
hasMasterEnvironment
175+
?`${masterEnvironment?.environmentName} is already the Master environment`
176+
:''
177+
}
178+
>
179+
<Switch
180+
checked={isMaster}
181+
onChange={handleMasterChange}
182+
disabled={hasMasterEnvironment}
183+
184+
/>
185+
</Tooltip>
186+
{isMaster&&(
187+
<spanstyle={{color:'#52c41a',fontSize:'12px'}}>
188+
Will be Master
189+
</span>
190+
)}
191+
</div>
165192
</Form.Item>
166193

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-
177194
<Alert
178195
message="License Information"
179196
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/pages/setting/environments/components/EditEnvironmentModal.tsx‎

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
importReact,{useState,useEffect}from'react';
2-
import{Modal,Form,Input,Select,Switch,Button}from'antd';
2+
import{Modal,Form,Input,Select,Switch,Button,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;
@@ -21,31 +23,52 @@ const EditEnvironmentModal: React.FC<EditEnvironmentModalProps> = ({
2123
})=>{
2224
const[form]=Form.useForm();
2325
const[submitLoading,setSubmitLoading]=useState(false);
26+
const[isMaster,setIsMaster]=useState(false);
27+
28+
// Redux selectors to check for existing master environment
29+
consthasMasterEnvironment=useSelector(selectHasMasterEnvironment);
30+
constmasterEnvironment=useSelector(selectMasterEnvironment);
31+
32+
// Check if another environment is master (not this one)
33+
consthasOtherMaster=hasMasterEnvironment&&masterEnvironment?.environmentId!==environment?.environmentId;
2434

2535
// Initialize form with environment data when it changes
2636
useEffect(()=>{
2737
if(environment){
38+
setIsMaster(environment.isMaster);
2839
form.setFieldsValue({
2940
environmentName:environment.environmentName||'',
3041
environmentDescription:environment.environmentDescription||'',
3142
environmentType:environment.environmentType,
3243
environmentApiServiceUrl:environment.environmentApiServiceUrl||'',
3344
environmentFrontendUrl:environment.environmentFrontendUrl||'',
3445
environmentNodeServiceUrl:environment.environmentNodeServiceUrl||'',
35-
environmentApikey:environment.environmentApikey||'',
36-
isMaster:environment.isMaster
46+
environmentApikey:environment.environmentApikey||''
3747
});
3848
}
3949
},[environment,form]);
4050

51+
consthandleMasterChange=(checked:boolean)=>{
52+
// Only allow enabling master if no other environment is master
53+
if(checked&&hasOtherMaster){
54+
return;// Do nothing if trying to enable master when another exists
55+
}
56+
setIsMaster(checked);
57+
};
58+
4159
consthandleSubmit=async()=>{
4260
if(!environment)return;
4361

4462
try{
4563
constvalues=awaitform.validateFields();
4664
setSubmitLoading(true);
4765

48-
awaitonSave(values);// Call with only the data parameter
66+
constsubmitData={
67+
...values,
68+
isMaster
69+
};
70+
71+
awaitonSave(submitData);
4972
onClose();
5073
}catch(error){
5174
if(errorinstanceofError){
@@ -144,13 +167,31 @@ const EditEnvironmentModal: React.FC<EditEnvironmentModalProps> = ({
144167
/>
145168
</Form.Item>
146169

147-
<Form.Item
148-
name="isMaster"
149-
label="Master Environment"
150-
valuePropName="checked"
151-
>
152-
<Switch/>
170+
<Form.Itemlabel="Master Environment">
171+
<divstyle={{display:'flex',alignItems:'center',gap:'12px'}}>
172+
<Tooltip
173+
title={
174+
hasOtherMaster&&!isMaster
175+
?`${masterEnvironment?.environmentName} is already the Master environment`
176+
:''
177+
}
178+
>
179+
<Switch
180+
checked={isMaster}
181+
onChange={handleMasterChange}
182+
disabled={hasOtherMaster&&!isMaster}
183+
184+
/>
185+
</Tooltip>
186+
{isMaster&&(
187+
<spanstyle={{color:'#faad14',fontSize:'12px'}}>
188+
Currently Master
189+
</span>
190+
)}
191+
</div>
153192
</Form.Item>
193+
194+
154195
</Form>
155196
</Modal>
156197
);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp