-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddvirtualmachinedialog
More file actions
480 lines (441 loc) · 13.6 KB
/
Copy pathAddvirtualmachinedialog
File metadata and controls
480 lines (441 loc) · 13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
import React, { useState, useEffect } from "react";
import { makeStyles } from "@mui/styles";
import Dialog from "@mui/material/Dialog";
import { Input } from "../../../../components/genericComponents/Input";
import MasterEnvDropdown from "../../../../components/genericComponents/MasterEnvDropdown";
import GenerateURL from "../../../../util/APIUrlProvider";
import properties from "../../../../properties/properties";
import InvokeApi, { PostData } from "../../../../util/apiInvoker";
import { useCustomSnackbar } from "../../../../contexts/SnackbarContext";
import {VALIDATION_TYPE_REQUIRED,ValidateDataSet,} from "../../../../util/Validator";
import { showErrorHandlerUpdated } from "../../../../util/util";
import Button from "../../../../components/genericComponents/Button";
import style from "react-syntax-highlighter/dist/esm/styles/hljs/a11y-dark";
const AddVirtualMachineDialog = ({ open = true, handleSuccess, handleClose }) => {
const classes = useStyles();
const { showSnackbar } = useCustomSnackbar();
const [isOpen, setIsOpen] = useState(open);
const localStorageKey = "vm_group_creation_info_flag";
const hideInfoSection = JSON.parse(localStorage.getItem(localStorageKey));
const [state, setState] = useState({
showLeftPanel: true,
isLoading: false,
dontShowAgain: false,
data: {},
error: {},
master_envs_list: [],
selectedMasterEnv: [],
env_data_loading: false,
});
useEffect(() => {
setIsOpen(open);
}, [open]);
useEffect(() => {
if (open) {
setState((prev) => ({
...prev,
showLeftPanel: !hideInfoSection,
isLoading: false,
dontShowAgain: !!hideInfoSection,
data: {},
error: {},
selectedMasterEnv: [],
}));
}
}, [open, hideInfoSection]);
useEffect(() => {
if (open) {
fetchMasterEnvList();
}
}, [open]);
useEffect(() => {
if (state.data.environment_master_type) {
const filteredEnvs = state.master_envs_list.filter((item) =>
state.data.environment_master_type.includes(item.order)
);
setState((prev) => ({
...prev,
selectedMasterEnv: filteredEnvs,
}));
}
}, [state.master_envs_list, state.data.environment_master_type]);
function fetchMasterEnvList() {
var requestInfo = {
endPoint: GenerateURL({}, properties.api.master_envs),
httpMethod: "GET",
httpHeaders: { "Content-Type": "application/json" },
};
InvokeApi(
requestInfo,
fetchMasterEnvListDataSuccess,
fetchMasterEnvListDataFailed
);
setState((prev) => ({
...prev,
env_data_loading: true,
}));
}
function fetchMasterEnvListDataSuccess(data) {
setState((prev) => ({
...prev,
master_envs_list: data.map((item) => ({
tabName: item.name,
order: item.id,
})),
env_data_loading: false,
}));
}
function fetchMasterEnvListDataFailed(error) {
setState((prev) => ({
...prev,
error: error,
env_data_loading: false,
}));
}
const updateMasterEnv = (master_env_order) => {
let filter_current_env = state.master_envs_list.find(
(item) => item.order === master_env_order
);
if (filter_current_env) {
setState((prev) => {
const isAlreadySelected = prev.selectedMasterEnv.some(
(env) => env.order === master_env_order
);
if (!isAlreadySelected) {
return {
...prev,
selectedMasterEnv: [...prev.selectedMasterEnv, filter_current_env],
error: {},
};
}
return prev;
});
}
};
const removeMasterEnv = (order) => {
setState((prev) => ({
...prev,
selectedMasterEnv: prev.selectedMasterEnv.filter(
(env) => env.order !== order
),
}));
};
const updateSelectedMasterEnv = (data) => {
console.log(data, "updateSelectedMasterEnv");
};
const onChangeHandler = (e) => {
const { name, value } = e.target;
setState((prev) => ({
...prev,
data: {
...prev.data,
[name]: value,
},
error: {
...prev.error,
[name]: "",
},
}));
};
const handleSave = () => {
var validations = {
virtual_group_name: [VALIDATION_TYPE_REQUIRED],
selectedMasterEnv: [VALIDATION_TYPE_REQUIRED],
};
if (state.selectedMasterEnv && state.selectedMasterEnv.length > 0) {
validations.selectedMasterEnv = validations.selectedMasterEnv.filter(
(validation) => validation !== VALIDATION_TYPE_REQUIRED
);
}
var result = ValidateDataSet(state.data, validations);
if (result.valid) {
var post_data = {
virtual_group_name: state.data.virtual_group_name,
environment_master_type: state.selectedMasterEnv.map(
(item) => item.order
),
};
var temp_url = GenerateURL({}, properties.api.create_vm_group);
setState((prev) => ({ ...prev, isLoading: true }));
showSnackbar("info", "Creating VM Group...");
PostData(temp_url, post_data, saveSuccess, saveFail);
} else {
let error_msg = showErrorHandlerUpdated({ ...result.error });
showSnackbar("error", "Unable to create VM group.", error_msg);
setState((prev) => ({
...prev,
error: result.error,
isLoading: false,
}));
}
};
function saveSuccess(response) {
showSnackbar("success", "VM group created.", "Please continue with add vm");
setState((prev) => ({
...prev,
isLoading: false,
}));
if (handleSuccess) handleSuccess(response);
closeDialog();
}
function saveFail(response) {
let error_msg = showErrorHandlerUpdated(response);
showSnackbar("error", "Unable to create VM group.", error_msg);
setState((prev) => ({
...prev,
isLoading: false,
error: {
...prev.error,
...response,
},
}));
}
const handleCloseLeftStrip = () => {
if (state.dontShowAgain) {
// localStorage.setItem(localStorageKey, JSON.stringify(true));
}
setState((prev) => ({
...prev,
showLeftPanel: false,
}));
};
const handleDontShowCheckbox = (e) => {
const value = e?.target?.type === "checkbox" ? e.target.checked : e;
setState((prev) => ({ ...prev, dontShowAgain: value }));
};
const closeDialog = () => {
setState((prev) => ({
...prev,
data: {},
error: {},
selectedMasterEnv: [],
}));
setIsOpen(false);
if (handleClose) handleClose();
};
return (
<Dialog
fullWidth={true}
maxWidth={"md"}
open={isOpen}
onClose={closeDialog}
className={`${classes.root} dialog-align-corner`}
aria-labelledby="max-width-dialog-title"
>
<div
className="d-grid ml-auto dialog-sub-component"
style={{
gridTemplateColumns: state.showLeftPanel
? "396px 650px"
: "0px 650px",
}}
>
{!hideInfoSection && (
<div
className={
state.showLeftPanel
? "left-panel-dialog bg-white position-relative"
: "left-panel-dialog-down"
}
>
<div
className={
"d-flex align-center space-between left-panel-header pd-10"
}
style={{ padding: "9px 20px" }}
>
<p>INFORMATION</p>
<button
className="btn btn-icon-only"
onClick={handleCloseLeftStrip}
>
<span className="ri-close-line color-icon-secondary"></span>
</button>
</div>
<div className="pd-10" style={{ padding: "16px 20px" }}>
<p className="font-16 font-weight-600 color-primary mb-10">
What is Virtual Machine?
</p>
<p
className="font-12 color-icon-secondary"
style={{ color: "#404040" }}
>
In Buildpiper, for a monolithic application, we need to onboard
the infrastructure required for deployment for the monolithic
applications. This infrastructure is nothing but of VMs (virtual
machines). Thus a virtual machine (VM) is a software-based unit
of a LDC - Local data centre which runs an operating system and
applications just like a physical computer but relies on
virtualization technology to operate.
</p>
</div>
<div
className="checkbox-only-divi"
style={{ padding: "10px 20px" }}
>
<Input
style={{}}
type="simple-checkbox"
name="dont_show_again"
label="Don't show this again"
data={{ dont_show_again: state.dontShowAgain }}
value={state.dontShowAgain}
error={state.error}
onChangeHandler={handleDontShowCheckbox}
/>
</div>
</div>
)}
<div className="right-panel-dialog bg-white">
<div
className="font-18 font-weight-600 color-white d-flex align-center space-between"
style={{ backgroundColor: "#0086ff", padding: "13px 20px" }}
>
<p>Add Virtual Machine Group</p>
<button
className="btn float-cancel-button "
style={
hideInfoSection || !state.showLeftPanel
? {
position: "absolute",
top: "0px",
left: "-55px",
zIndex: 1000,
}
: {
position: "absolute",
top: "0px",
left: "-450px",
zIndex: 1000,
}
}
onClick={closeDialog}
>
<span className="ri-close-line "></span>
</button>
</div>
<div
style={{
padding: "0 20px 120px 20px",
overflowY: "auto",
}}
>
<div className={classes.formContainer}>
<div className={classes.formGroup}>
<Input
type="text"
label="Virtual Machine Group Name"
placeholder="Enter Name"
name="virtual_group_name"
mandatorySign
data={state.data}
error={state.error}
info={
"In Buildpiper, for a monolithic application, you can onboard a single VM or a group of VMs, referred to as a VM Group."
}
onChangeHandler={onChangeHandler}
style={{ height: "46px" }}
/>
</div>
<div className={classes.formGroup}>
<MasterEnvDropdown
envTabList={[]}
selectedMasterEnv={state.selectedMasterEnv}
selectedEnvTab={state.selected_env_master_id}
envChangeHandler={updateSelectedMasterEnv}
masterEnvList={state.master_envs_list}
selectedComponentEnv={state.selected_component_env_taborder}
masterEnvChangeHandler={updateMasterEnv}
removeFromList={removeMasterEnv}
error={state?.error?.selectedMasterEnv ? true : false}
style={{ marginTop: "5px" }}
/>
{state?.error?.selectedMasterEnv && (
<p className="error-message">
{state.error.selectedMasterEnv}
</p>
)}
</div>
</div>
</div>
<div className="footer-right-panel d-flex align-center justify-end">
<Button variant="ghost" onClick={closeDialog}>
CANCEL
</Button>
<Button
className="btn btn-primary"
isLoading={state.isLoading}
onClick={handleSave}
>
SAVE & CONTINUE
</Button>
</div>
</div>
</div>
</Dialog>
);
};
const useStyles = makeStyles((theme) => ({
root: {
"&.dialog-align-corner": {
"& .MuiPaper-root": {
maxWidth: "1100px",
margin: "0",
fontFamily: "Montserrat",
},
},
"& .right-panel-dialog": {
position: "relative",
width: "650px",
height: "100%",
display: "flex",
flexDirection: "column",
},
"& .left-panel-dialog": {
width: "396px",
transition: "width 0.3s",
"& .left-panel-header": {
borderBottom: "1px solid #f1f1f1",
fontSize: "12px",
fontWeight: "600",
color: "#0086FF",
},
"& .checkbox-only-divi": {
position: "absolute",
bottom: "10px",
backcolor: "#fff",
},
},
"& .left-panel-dialog-down": {
width: "0px",
overflow: "hidden",
transition: "width 0.3s",
},
"& .footer-right-panel": {
backgroundColor: "#fafafa",
padding: "20px",
position: "absolute",
bottom: "0px",
width: "650px",
gap: "13px",
borderTop: "1px solid #e6e6e6",
},
"& .wrapper-new-file": {
"& .input-file-wraper": {
border: "none",
padding: "4px",
gap: "0px",
justifyContent: "center",
},
},
},
formContainer: {
width: "100%",
marginTop: "30px",
},
formGroup: {
marginBottom: "20px",
fontSize: "14px",
},
}));
export default AddVirtualMachineDialog;