Skip to content

Commit

Permalink
Added delete option to multi-zone selector (#167)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Perez <benjamin@bexsoft.net>
  • Loading branch information
bexsoft and Benjamin Perez committed Jun 15, 2020
1 parent 991204c commit f2c8f15
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 122 deletions.
219 changes: 98 additions & 121 deletions portal-ui/bindata_assetfs.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
import Grid from "@material-ui/core/Grid";
import get from "lodash/get";
import { InputLabel, Tooltip } from "@material-ui/core";
import IconButton from "@material-ui/core/IconButton";
import HelpIcon from "@material-ui/icons/Help";
import InputBoxWrapper from "../../Common/FormComponents/InputBoxWrapper/InputBoxWrapper";
import {
fieldBasic,
tooltipHelper,
} from "../../Common/FormComponents/common/styleLibrary";
import DeleteIcon from "../../../../icons/DeleteIcon";
import { IZone } from "./types";

interface IZonesMultiSelector {
Expand All @@ -37,7 +39,7 @@ interface IZonesMultiSelector {

const gridBasic = {
display: "grid",
gridTemplateColumns: "calc(50% - 4px) calc(50% - 4px)",
gridTemplateColumns: "calc(50% - 20px) calc(50% - 20px) 30px",
gridGap: 8,
};

Expand Down Expand Up @@ -66,6 +68,13 @@ const styles = (theme: Theme) =>
...gridBasic,
marginBottom: 5,
},
deleteIconContainer: {
alignSelf: "center",
"& button": {
padding: 0,
marginBottom: 10,
},
},
});

const ZonesMultiSelector = ({
Expand Down Expand Up @@ -122,6 +131,16 @@ const ZonesMultiSelector = ({
setCurrentElements(updatedElement);
};

const deleteElement = (zoneToRemove: number) => {
const zonesClone = [...currentElements];

const newArray = zonesClone
.slice(0, zoneToRemove)
.concat(zonesClone.slice(zoneToRemove + 1, zonesClone.length));

setCurrentElements(newArray);
};

const inputs = currentElements.map((element, index) => {
return (
<React.Fragment key={`zone-${name}-${index.toString()}`}>
Expand All @@ -148,6 +167,17 @@ const ZonesMultiSelector = ({
key={`Zones-${name}-${index.toString()}-servers`}
/>
</div>
<div className={classes.deleteIconContainer}>
<IconButton
color="primary"
onClick={() => {
deleteElement(index);
}}
disabled={index === currentElements.length - 1}
>
<DeleteIcon />
</IconButton>
</div>
</React.Fragment>
);
});
Expand Down

0 comments on commit f2c8f15

Please sign in to comment.