@@ -18,12 +18,14 @@ import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
18
18
import Grid from "@material-ui/core/Grid" ;
19
19
import get from "lodash/get" ;
20
20
import { InputLabel , Tooltip } from "@material-ui/core" ;
21
+ import IconButton from "@material-ui/core/IconButton" ;
21
22
import HelpIcon from "@material-ui/icons/Help" ;
22
23
import InputBoxWrapper from "../../Common/FormComponents/InputBoxWrapper/InputBoxWrapper" ;
23
24
import {
24
25
fieldBasic ,
25
26
tooltipHelper ,
26
27
} from "../../Common/FormComponents/common/styleLibrary" ;
28
+ import DeleteIcon from "../../../../icons/DeleteIcon" ;
27
29
import { IZone } from "./types" ;
28
30
29
31
interface IZonesMultiSelector {
@@ -37,7 +39,7 @@ interface IZonesMultiSelector {
37
39
38
40
const gridBasic = {
39
41
display : "grid" ,
40
- gridTemplateColumns : "calc(50% - 4px ) calc(50% - 4px) " ,
42
+ gridTemplateColumns : "calc(50% - 20px ) calc(50% - 20px) 30px " ,
41
43
gridGap : 8 ,
42
44
} ;
43
45
@@ -66,6 +68,13 @@ const styles = (theme: Theme) =>
66
68
...gridBasic ,
67
69
marginBottom : 5 ,
68
70
} ,
71
+ deleteIconContainer : {
72
+ alignSelf : "center" ,
73
+ "& button" : {
74
+ padding : 0 ,
75
+ marginBottom : 10 ,
76
+ } ,
77
+ } ,
69
78
} ) ;
70
79
71
80
const ZonesMultiSelector = ( {
@@ -122,6 +131,16 @@ const ZonesMultiSelector = ({
122
131
setCurrentElements ( updatedElement ) ;
123
132
} ;
124
133
134
+ const deleteElement = ( zoneToRemove : number ) => {
135
+ const zonesClone = [ ...currentElements ] ;
136
+
137
+ const newArray = zonesClone
138
+ . slice ( 0 , zoneToRemove )
139
+ . concat ( zonesClone . slice ( zoneToRemove + 1 , zonesClone . length ) ) ;
140
+
141
+ setCurrentElements ( newArray ) ;
142
+ } ;
143
+
125
144
const inputs = currentElements . map ( ( element , index ) => {
126
145
return (
127
146
< React . Fragment key = { `zone-${ name } -${ index . toString ( ) } ` } >
@@ -148,6 +167,17 @@ const ZonesMultiSelector = ({
148
167
key = { `Zones-${ name } -${ index . toString ( ) } -servers` }
149
168
/>
150
169
</ div >
170
+ < div className = { classes . deleteIconContainer } >
171
+ < IconButton
172
+ color = "primary"
173
+ onClick = { ( ) => {
174
+ deleteElement ( index ) ;
175
+ } }
176
+ disabled = { index === currentElements . length - 1 }
177
+ >
178
+ < DeleteIcon />
179
+ </ IconButton >
180
+ </ div >
151
181
</ React . Fragment >
152
182
) ;
153
183
} ) ;
0 commit comments