Skip to content

Commit d917bfa

Browse files
committed
edit functioanlity in form of FORM
Signed-off-by: Shrutim1505 <shrutimurthy2103@gmail.com>
1 parent d6b2a23 commit d917bfa

File tree

1 file changed

+62
-15
lines changed

1 file changed

+62
-15
lines changed

frontend/src/components/queues/QueueTable/EditQueueDialog.jsx

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,31 @@ const RenderFields = ({ data, onChange, path = [] }) => {
2525

2626
if (Array.isArray(value)) {
2727
return (
28-
<Box key={currentPath.join(".")} sx={{ mb: 2, pl: 2, borderLeft: "2px solid #ccc" }}>
28+
<Box
29+
key={currentPath.join(".")}
30+
sx={{ mb: 2, pl: 2, borderLeft: "2px solid #ccc" }}
31+
>
2932
<Typography variant="subtitle2">{key} (Array)</Typography>
3033
{value.map((item, index) => {
3134
const itemPath = [...currentPath, index];
3235
if (typeof item === "object" && item !== null) {
3336
return (
34-
<Box key={itemPath.join(".")} sx={{ pl: 2, mb: 1, borderLeft: "1px dashed #999" }}>
35-
<Typography variant="caption">Item {index}</Typography>
36-
<RenderFields data={item} onChange={onChange} path={itemPath} />
37+
<Box
38+
key={itemPath.join(".")}
39+
sx={{
40+
pl: 2,
41+
mb: 1,
42+
borderLeft: "1px dashed #999",
43+
}}
44+
>
45+
<Typography variant="caption">
46+
Item {index}
47+
</Typography>
48+
<RenderFields
49+
data={item}
50+
onChange={onChange}
51+
path={itemPath}
52+
/>
3753
</Box>
3854
);
3955
} else {
@@ -44,7 +60,9 @@ const RenderFields = ({ data, onChange, path = [] }) => {
4460
value={item}
4561
fullWidth
4662
margin="dense"
47-
onChange={(e) => onChange(itemPath, e.target.value)}
63+
onChange={(e) =>
64+
onChange(itemPath, e.target.value)
65+
}
4866
/>
4967
);
5068
}
@@ -55,9 +73,16 @@ const RenderFields = ({ data, onChange, path = [] }) => {
5573

5674
if (typeof value === "object" && value !== null) {
5775
return (
58-
<Box key={currentPath.join(".")} sx={{ mb: 2, pl: 2, borderLeft: "2px solid #ccc" }}>
76+
<Box
77+
key={currentPath.join(".")}
78+
sx={{ mb: 2, pl: 2, borderLeft: "2px solid #ccc" }}
79+
>
5980
<Typography variant="subtitle2">{key}</Typography>
60-
<RenderFields data={value} onChange={onChange} path={currentPath} />
81+
<RenderFields
82+
data={value}
83+
onChange={onChange}
84+
path={currentPath}
85+
/>
6186
</Box>
6287
);
6388
}
@@ -75,7 +100,6 @@ const RenderFields = ({ data, onChange, path = [] }) => {
75100
});
76101
};
77102

78-
79103
const updateNestedValue = (obj, path, value) => {
80104
const lastKey = path.pop();
81105
const nested = path.reduce((acc, key) => (acc[key] = acc[key] || {}), obj);
@@ -114,12 +138,15 @@ const EditQueueDialog = ({ open, queue, onClose, onSave }) => {
114138
};
115139

116140
const handleNestedChange = (path, value) => {
117-
setFormState((prev) => updateNestedValue({ ...prev }, [...path], value));
141+
setFormState((prev) =>
142+
updateNestedValue({ ...prev }, [...path], value),
143+
);
118144
};
119145

120146
const handleSave = () => {
121147
try {
122-
const updated = editMode === "yaml" ? yaml.load(editorValue) : formState;
148+
const updated =
149+
editMode === "yaml" ? yaml.load(editorValue) : formState;
123150
onSave(updated);
124151
onClose();
125152
} catch (error) {
@@ -130,9 +157,19 @@ const EditQueueDialog = ({ open, queue, onClose, onSave }) => {
130157

131158
return (
132159
<Dialog open={open} onClose={onClose} maxWidth="md" fullWidth>
133-
<DialogTitle sx={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
160+
<DialogTitle
161+
sx={{
162+
display: "flex",
163+
justifyContent: "space-between",
164+
alignItems: "center",
165+
}}
166+
>
134167
Edit Queue
135-
<ToggleButtonGroup value={editMode} exclusive onChange={handleModeChange}>
168+
<ToggleButtonGroup
169+
value={editMode}
170+
exclusive
171+
onChange={handleModeChange}
172+
>
136173
<ToggleButton value="yaml">YAML</ToggleButton>
137174
<ToggleButton value="form">Form</ToggleButton>
138175
</ToggleButtonGroup>
@@ -145,11 +182,17 @@ const EditQueueDialog = ({ open, queue, onClose, onSave }) => {
145182
language="yaml"
146183
value={editorValue}
147184
onChange={(v) => setEditorValue(v || "")}
148-
options={{ minimap: { enabled: false }, automaticLayout: true }}
185+
options={{
186+
minimap: { enabled: false },
187+
automaticLayout: true,
188+
}}
149189
/>
150190
) : (
151191
<Box sx={{ mt: 2 }}>
152-
<RenderFields data={formState} onChange={handleNestedChange} />
192+
<RenderFields
193+
data={formState}
194+
onChange={handleNestedChange}
195+
/>
153196
</Box>
154197
)}
155198
</DialogContent>
@@ -158,7 +201,11 @@ const EditQueueDialog = ({ open, queue, onClose, onSave }) => {
158201
<Button onClick={onClose} color="primary" variant="contained">
159202
Cancel
160203
</Button>
161-
<Button onClick={handleSave} color="primary" variant="contained">
204+
<Button
205+
onClick={handleSave}
206+
color="primary"
207+
variant="contained"
208+
>
162209
Update
163210
</Button>
164211
</DialogActions>

0 commit comments

Comments
 (0)