Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added delete option to multi-zone selector #167

Merged
merged 1 commit into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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