1- // CreateQueueDialog.js
21import React , { useState } from "react" ;
32import {
43 Dialog ,
@@ -7,15 +6,20 @@ import {
76 DialogActions ,
87 TextField ,
98 Box ,
10- MenuItem ,
9+ FormControlLabel ,
10+ Checkbox ,
1111} from "@mui/material" ;
1212import { Button } from "react-bootstrap" ;
1313
1414const CreateQueueDialog = ( { open, onClose, onCreate } ) => {
1515 const [ queueData , setQueueData ] = useState ( {
1616 name : "" ,
17+ namespace : "" ,
1718 weight : 1 ,
18- state : "Open" ,
19+ reclaimable : true ,
20+ guaranteed : { cpu : "" , memory : "" } ,
21+ capability : { cpu : "" , memory : "" } ,
22+ deserved : { cpu : "" , memory : "" } ,
1923 } ) ;
2024
2125 const primaryColor = "#E34C26" ;
@@ -30,26 +34,73 @@ const CreateQueueDialog = ({ open, onClose, onCreate }) => {
3034 } ) ) ;
3135 } ;
3236
37+ const handleResourceChange = ( section , key ) => ( event ) => {
38+ setQueueData ( ( prev ) => ( {
39+ ...prev ,
40+ [ section ] : {
41+ ...prev [ section ] ,
42+ [ key ] : event . target . value ,
43+ } ,
44+ } ) ) ;
45+ } ;
46+
47+ const handleCheckboxChange = ( event ) => {
48+ setQueueData ( ( prev ) => ( {
49+ ...prev ,
50+ reclaimable : event . target . checked ,
51+ } ) ) ;
52+ } ;
53+
3354 const handleSubmit = ( ) => {
3455 if ( ! queueData . name . trim ( ) ) {
3556 alert ( "Queue name is required." ) ;
3657 return ;
3758 }
3859
60+ const specSection = {
61+ weight : queueData . weight ,
62+ reclaimable : queueData . reclaimable ,
63+ guaranteed : { } ,
64+ capability : { } ,
65+ deserved : { } ,
66+ } ;
67+
68+ // Add non-empty fields only
69+ [ "guaranteed" , "capability" , "deserved" ] . forEach ( ( section ) => {
70+ const cpu = queueData [ section ] . cpu . trim ( ) ;
71+ const memory = queueData [ section ] . memory . trim ( ) ;
72+ if ( cpu || memory ) {
73+ specSection [ section ] = { } ;
74+ if ( cpu ) specSection [ section ] . cpu = cpu ;
75+ if ( memory ) specSection [ section ] . memory = memory ;
76+ } else {
77+ delete specSection [ section ] ; // omit empty section
78+ }
79+ } ) ;
80+
3981 const newQueue = {
4082 apiVersion : "scheduling.volcano.sh/v1beta1" ,
4183 kind : "Queue" ,
4284 metadata : {
4385 name : queueData . name . trim ( ) ,
4486 } ,
45- spec : {
46- weight : queueData . weight ,
47- state : queueData . state ,
48- } ,
87+ spec : specSection ,
4988 } ;
5089
90+ if ( queueData . namespace . trim ( ) ) {
91+ newQueue . metadata . namespace = queueData . namespace . trim ( ) ;
92+ }
93+
5194 onCreate ( newQueue ) ;
52- setQueueData ( { name : "" , weight : 1 , state : "Open" } ) ;
95+ setQueueData ( {
96+ name : "" ,
97+ namespace : "" ,
98+ weight : 1 ,
99+ reclaimable : true ,
100+ guaranteed : { cpu : "" , memory : "" } ,
101+ capability : { cpu : "" , memory : "" } ,
102+ deserved : { cpu : "" , memory : "" } ,
103+ } ) ;
53104 onClose ( ) ;
54105 } ;
55106
@@ -97,10 +148,9 @@ const CreateQueueDialog = ({ open, onClose, onCreate }) => {
97148 } }
98149 />
99150 < TextField
100- label = "Weight"
101- type = "number"
102- value = { queueData . weight }
103- onChange = { handleChange ( "weight" ) }
151+ label = "Namespace (optional)"
152+ value = { queueData . namespace }
153+ onChange = { handleChange ( "namespace" ) }
104154 fullWidth
105155 sx = { {
106156 "& .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline" :
@@ -113,10 +163,10 @@ const CreateQueueDialog = ({ open, onClose, onCreate }) => {
113163 } }
114164 />
115165 < TextField
116- select
117- label = "State "
118- value = { queueData . state }
119- onChange = { handleChange ( "state " ) }
166+ label = "Weight"
167+ type = "number "
168+ value = { queueData . weight }
169+ onChange = { handleChange ( "weight " ) }
120170 fullWidth
121171 sx = { {
122172 "& .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline" :
@@ -127,10 +177,73 @@ const CreateQueueDialog = ({ open, onClose, onCreate }) => {
127177 color : primaryColor ,
128178 } ,
129179 } }
130- >
131- < MenuItem value = "Open" > Open</ MenuItem >
132- < MenuItem value = "Closed" > Closed</ MenuItem >
133- </ TextField >
180+ />
181+ < FormControlLabel
182+ control = {
183+ < Checkbox
184+ checked = { queueData . reclaimable }
185+ onChange = { handleCheckboxChange }
186+ sx = { {
187+ color : primaryColor ,
188+ "&.Mui-checked" : {
189+ color : primaryColor ,
190+ } ,
191+ } }
192+ />
193+ }
194+ label = "Reclaimable"
195+ />
196+
197+ { /* Sections for guaranteed, capability, deserved */ }
198+ { [ "guaranteed" , "capability" , "deserved" ] . map ( ( section ) => (
199+ < Box key = { section } >
200+ < Box sx = { { fontWeight : 500 , mb : 1 , color : "#555" } } >
201+ { section . charAt ( 0 ) . toUpperCase ( ) +
202+ section . slice ( 1 ) } { " " }
203+ Resources
204+ </ Box >
205+ < Box sx = { { display : "flex" , gap : 2 } } >
206+ < TextField
207+ label = "CPU"
208+ value = { queueData [ section ] . cpu }
209+ onChange = { handleResourceChange (
210+ section ,
211+ "cpu" ,
212+ ) }
213+ fullWidth
214+ placeholder = "e.g. 1000m"
215+ sx = { {
216+ "& .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline" :
217+ {
218+ borderColor : primaryColor ,
219+ } ,
220+ "& .MuiInputLabel-root.Mui-focused" : {
221+ color : primaryColor ,
222+ } ,
223+ } }
224+ />
225+ < TextField
226+ label = "Memory"
227+ value = { queueData [ section ] . memory }
228+ onChange = { handleResourceChange (
229+ section ,
230+ "memory" ,
231+ ) }
232+ fullWidth
233+ placeholder = "e.g. 1Gi"
234+ sx = { {
235+ "& .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline" :
236+ {
237+ borderColor : primaryColor ,
238+ } ,
239+ "& .MuiInputLabel-root.Mui-focused" : {
240+ color : primaryColor ,
241+ } ,
242+ } }
243+ />
244+ </ Box >
245+ </ Box >
246+ ) ) }
134247 </ Box >
135248 </ DialogContent >
136249 < DialogActions >
0 commit comments