Skip to content

Commit

Permalink
ui: form builder delete modal propery refactor
Browse files Browse the repository at this point in the history
* closes cernanalysispreservation#1950

Signed-off-by: papadopan <[email protected]>
  • Loading branch information
papadopan authored and pamfilos committed Nov 20, 2020
1 parent 4ff923c commit 08546ed
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from "react";
import PropTypes from "prop-types";
import Modal from "../../../../partials/Modal";
import Button from "../../../../partials/Button";
import Box from "grommet/components/Box";
import Paragraph from "grommet/components/Paragraph";

const DeletePropertyModal = ({ show, text, onClose, onDelete }) => {
return (
show && (
<Modal title="Delete Item" separator onClose={onClose}>
<Box pad={{ vertical: "medium", horizontal: "small" }}>
<Box align="center" justify="center" colorIndex="light-1">
<Paragraph margin="none">Are you sure you want to delete</Paragraph>
<Paragraph margin="none">{text}</Paragraph>
</Box>

<Box margin={{ top: "medium" }} direction="row" justify="between">
<Button text="Cancel" secondary onClick={onClose} />
<Button text="Delete" critical onClick={onDelete} />
</Box>
</Box>
</Modal>
)
);
};

DeletePropertyModal.propTypes = {
show: PropTypes.bool,
text: PropTypes.string,
onClose: PropTypes.func,
onDelete: PropTypes.func
};

export default DeletePropertyModal;
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from "react";

import Box from "grommet/components/Box";
import Paragraph from "grommet/components/Paragraph";

import Form from "../../../../drafts/form/GrommetForm";
import { PropTypes } from "prop-types";
import Button from "../../../../partials/Button";
import Modal from "../../../../partials/Modal";

import Image1 from "./svg/AccordionField";
import Image2 from "./svg/TabObjectField";
Expand All @@ -19,6 +17,8 @@ import Image7 from "./svg/SidebarTwoColLayout";
import { schemaSchema } from "../../utils/schemas";
import { Label } from "grommet";

import DeleteModal from "./DeletePropertyModal";

const GRID_COLUMNS_OPTIONS = [
"1/1",
"1/2",
Expand Down Expand Up @@ -147,46 +147,20 @@ class CustomizeField extends React.Component {
render() {
return (
<Box flex={false}>
{this.state.showDeleteLayer && (
<Modal
title="Delete Item"
separator
onClose={() => this.setState({ showDeleteLayer: false })}
>
<Box pad={{ vertical: "medium", horizontal: "small" }}>
<Box align="center" justify="center" colorIndex="light-1">
<Paragraph margin="none">
Are you sure you want to delete
</Paragraph>
<Paragraph margin="none">
{this.props.path
.toJS()
.path.filter(
item => item != "properties" && item != "items"
)
.map(item => item)
.join(" > ")}
</Paragraph>
</Box>

<Box margin={{ top: "medium" }} direction="row" justify="between">
<Button
text="Cancel"
secondary
onClick={() => this.setState({ showDeleteLayer: false })}
/>
<Button
text="Delete"
critical
onClick={() => {
this.props.deleteByPath(this.props.path.toJS());
this.setState({ showDeleteLayer: false });
}}
/>
</Box>
</Box>
</Modal>
)}
<DeleteModal
show={this.state.showDeleteLayer}
text={this.props.path
.toJS()
.path.filter(item => item != "properties" && item != "items")
.map(item => item)
.join(" > ")}
onClose={() => this.setState({ showDeleteLayer: false })}
onDelete={() => {
this.props.deleteByPath(this.props.path.toJS());
this.setState({ showDeleteLayer: false });
}}
/>

<Box flex={true} margin={{ bottom: "small" }}>
<Box
colorIndex="accent-2"
Expand Down Expand Up @@ -384,14 +358,14 @@ class CustomizeField extends React.Component {
? "white"
: null,
padding:
this.props.uiSchema &&
this.props.uiSchema &&
this.props.uiSchema.toJS()["ui:options"] &&
this.props.uiSchema.toJS()["ui:options"].align &&
align === this.props.uiSchema.toJS()["ui:options"].align
? "0 2px"
: null,
borderRadius:
this.props.uiSchema &&
this.props.uiSchema &&
this.props.uiSchema.toJS()["ui:options"] &&
this.props.uiSchema.toJS()["ui:options"].align &&
align === this.props.uiSchema.toJS()["ui:options"].align
Expand Down

0 comments on commit 08546ed

Please sign in to comment.