mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-11 14:24:24 +00:00
fix(cockpit/editor): add delete modal to confirm deletion
Also fix cases where modals closed for no reason
This commit is contained in:
parent
563ba154a3
commit
3f488e1d88
@ -7,11 +7,14 @@ import {isDarkTheme} from '../utils/utils';
|
|||||||
|
|
||||||
class AddFileModal extends React.Component {
|
class AddFileModal extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
this.state = {modal: false, filename: ''};
|
this.state = {modal: false, filename: ''};
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle() {
|
toggle(open) {
|
||||||
|
if (open !== undefined) {
|
||||||
|
return this.setState({modal: open});
|
||||||
|
}
|
||||||
this.setState({modal: !this.state.modal});
|
this.setState({modal: !this.state.modal});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,24 +24,24 @@ class AddFileModal extends React.Component {
|
|||||||
|
|
||||||
addFile() {
|
addFile() {
|
||||||
this.props.saveFile({path: `${this.props.node.path}/${this.state.filename}`, content: ''});
|
this.props.saveFile({path: `${this.props.node.path}/${this.state.filename}`, content: ''});
|
||||||
this.toggle();
|
this.toggle(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Modal contentClassName={classNames({'dark-theme': isDarkTheme(this.props.theme)})}
|
<Modal contentClassName={classNames({'dark-theme': isDarkTheme(this.props.theme)})}
|
||||||
isOpen={this.state.modal}
|
isOpen={this.state.modal}
|
||||||
toggle={() => this.toggle()}>
|
toggle={(open) => this.toggle(open)}>
|
||||||
<ModalHeader toggle={() => this.toggle()}>Please give the file a name</ModalHeader>
|
<ModalHeader toggle={() => this.toggle(false)}>Please give the file a name</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<Input autofocus="true" value={this.state.filename} onChange={e => this.handleChange(e)} />
|
<Input autoFocus={true} value={this.state.filename} onChange={e => this.handleChange(e)}/>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button color="primary" onClick={() => this.addFile()}>Add File</Button>{' '}
|
<Button color="primary" onClick={() => this.addFile()}>Add File</Button>{' '}
|
||||||
<Button color="secondary" onClick={() => this.toggle()}>Cancel</Button>
|
<Button color="secondary" onClick={() => this.toggle(false)}>Cancel</Button>
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</Modal>
|
</Modal>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,4 +51,4 @@ AddFileModal.propTypes = {
|
|||||||
theme: PropTypes.string
|
theme: PropTypes.string
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AddFileModal;
|
export default AddFileModal;
|
||||||
|
@ -7,11 +7,14 @@ import {isDarkTheme} from '../utils/utils';
|
|||||||
|
|
||||||
class AddFolderModal extends React.Component {
|
class AddFolderModal extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
this.state = {modal: false, folder: ''};
|
this.state = {modal: false, folder: ''};
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle() {
|
toggle(open) {
|
||||||
|
if (open !== undefined) {
|
||||||
|
return this.setState({modal: open});
|
||||||
|
}
|
||||||
this.setState({modal: !this.state.modal});
|
this.setState({modal: !this.state.modal});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,21 +24,21 @@ class AddFolderModal extends React.Component {
|
|||||||
|
|
||||||
addFolder() {
|
addFolder() {
|
||||||
this.props.saveFolder({path: `${this.props.node.path}/${this.state.folder}`});
|
this.props.saveFolder({path: `${this.props.node.path}/${this.state.folder}`});
|
||||||
this.toggle();
|
this.toggle(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Modal contentClassName={classNames({'dark-theme': isDarkTheme(this.props.theme)})}
|
<Modal contentClassName={classNames({'dark-theme': isDarkTheme(this.props.theme)})}
|
||||||
isOpen={this.state.modal}
|
isOpen={this.state.modal}
|
||||||
toggle={() => this.toggle()}>
|
toggle={(open) => this.toggle(open)}>
|
||||||
<ModalHeader toggle={() => this.toggle()}>Please give the folder a name</ModalHeader>
|
<ModalHeader toggle={() => this.toggle(false)}>Please give the folder a name</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<Input autofocus="true" value={this.state.filename} onChange={e => this.handleChange(e)} />
|
<Input autoFocus={true} value={this.state.filename} onChange={e => this.handleChange(e)} />
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button color="primary" onClick={() => this.addFolder()}>Add Folder</Button>{' '}
|
<Button color="primary" onClick={() => this.addFolder()}>Add Folder</Button>{' '}
|
||||||
<Button color="secondary" onClick={() => this.toggle()}>Cancel</Button>
|
<Button color="secondary" onClick={() => this.toggle(false)}>Cancel</Button>
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</Modal>
|
</Modal>
|
||||||
)
|
)
|
||||||
@ -48,4 +51,4 @@ AddFolderModal.propTypes = {
|
|||||||
theme: PropTypes.string
|
theme: PropTypes.string
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AddFolderModal;
|
export default AddFolderModal;
|
||||||
|
@ -18,7 +18,7 @@ const ContractsList = ({contracts}) => (
|
|||||||
contracts.map((contract) => {
|
contracts.map((contract) => {
|
||||||
const contractDisplay = formatContractForDisplay(contract);
|
const contractDisplay = formatContractForDisplay(contract);
|
||||||
if (!contractDisplay) {
|
if (!contractDisplay) {
|
||||||
return '';
|
return null;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<tr key={contract.className} className={contractDisplay.stateColor}>
|
<tr key={contract.className} className={contractDisplay.stateColor}>
|
||||||
@ -31,7 +31,7 @@ const ContractsList = ({contracts}) => (
|
|||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</Table>
|
</Table>
|
||||||
)
|
);
|
||||||
|
|
||||||
ContractsList.propTypes = {
|
ContractsList.propTypes = {
|
||||||
contracts: PropTypes.array,
|
contracts: PropTypes.array,
|
||||||
|
44
packages/embark-ui/src/components/DeleteModal.js
Normal file
44
packages/embark-ui/src/components/DeleteModal.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import {Button, Modal, ModalHeader, ModalBody, ModalFooter} from 'reactstrap';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
import {isDarkTheme} from '../utils/utils';
|
||||||
|
|
||||||
|
class DeleteModal extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {modal: false};
|
||||||
|
}
|
||||||
|
|
||||||
|
toggle(open) {
|
||||||
|
if (open !== undefined) {
|
||||||
|
return this.setState({modal: open});
|
||||||
|
}
|
||||||
|
this.setState({modal: !this.state.modal});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Modal contentClassName={classNames({'dark-theme': isDarkTheme(this.props.theme)})}
|
||||||
|
isOpen={this.state.modal}
|
||||||
|
toggle={(open) => this.toggle(open)}>
|
||||||
|
<ModalHeader toggle={() => this.toggle(false)}>Are you sure you want to remove this?</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
<p>This change is permanent and cannot be undone (from the Cockpit)</p>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button color="secondary" onClick={() => this.toggle(false)}>Cancel</Button>
|
||||||
|
<Button color="danger" onClick={() => {this.props.delete(); this.toggle(false);}}>Delete</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</Modal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DeleteModal.propTypes = {
|
||||||
|
delete: PropTypes.func,
|
||||||
|
theme: PropTypes.string
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DeleteModal;
|
@ -8,6 +8,7 @@ import {VelocityComponent} from 'velocity-react';
|
|||||||
import {removeFile as removeFileAction, saveFile as saveFileAction, saveFolder as saveFolderAction} from '../actions';
|
import {removeFile as removeFileAction, saveFile as saveFileAction, saveFolder as saveFolderAction} from '../actions';
|
||||||
import AddFileModal from '../components/AddFileModal';
|
import AddFileModal from '../components/AddFileModal';
|
||||||
import AddFolderModal from '../components/AddFolderModal';
|
import AddFolderModal from '../components/AddFolderModal';
|
||||||
|
import DeleteModal from '../components/DeleteModal';
|
||||||
import { getTheme } from '../reducers/selectors';
|
import { getTheme } from '../reducers/selectors';
|
||||||
|
|
||||||
class FileExplorerRowContainer extends React.Component {
|
class FileExplorerRowContainer extends React.Component {
|
||||||
@ -16,6 +17,7 @@ class FileExplorerRowContainer extends React.Component {
|
|||||||
this.state = {active: false};
|
this.state = {active: false};
|
||||||
this.addFileModal = React.createRef();
|
this.addFileModal = React.createRef();
|
||||||
this.addFolderModal = React.createRef();
|
this.addFolderModal = React.createRef();
|
||||||
|
this.deleteModal = React.createRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
activateNode() {
|
activateNode() {
|
||||||
@ -33,12 +35,12 @@ class FileExplorerRowContainer extends React.Component {
|
|||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<span id="add-file"
|
<span id="add-file"
|
||||||
className="pointer"
|
className="pointer"
|
||||||
onClick={() => this.addFileModal.current.toggle()}>
|
onClick={() => this.addFileModal.current.toggle(true)}>
|
||||||
<FontAwesome name="plus" className="text-success mr-2" />
|
<FontAwesome name="plus" className="text-success mr-2" />
|
||||||
</span>
|
</span>
|
||||||
<span id="add-folder"
|
<span id="add-folder"
|
||||||
className="pointer"
|
className="pointer"
|
||||||
onClick={() => this.addFolderModal.current.toggle()}>
|
onClick={() => this.addFolderModal.current.toggle(true)}>
|
||||||
<FontAwesome name="folder-open" className="text-success mr-2" />
|
<FontAwesome name="folder-open" className="text-success mr-2" />
|
||||||
</span>
|
</span>
|
||||||
<UncontrolledTooltip placement="bottom" target="add-file">
|
<UncontrolledTooltip placement="bottom" target="add-file">
|
||||||
@ -53,12 +55,13 @@ class FileExplorerRowContainer extends React.Component {
|
|||||||
}
|
}
|
||||||
<span id="delete"
|
<span id="delete"
|
||||||
style={{cursor: "pointer"}}
|
style={{cursor: "pointer"}}
|
||||||
onClick={() => this.props.removeFile(this.props.node)}>
|
onClick={() => this.deleteModal.current.toggle(true)}>
|
||||||
<FontAwesome name="trash" className="text-danger" />
|
<FontAwesome name="trash" className="text-danger" />
|
||||||
</span>
|
</span>
|
||||||
<UncontrolledTooltip placement="bottom" target="delete">
|
<UncontrolledTooltip placement="bottom" target="delete">
|
||||||
Delete
|
Delete
|
||||||
</UncontrolledTooltip>
|
</UncontrolledTooltip>
|
||||||
|
<DeleteModal theme={this.props.theme} delete={() => this.props.removeFile(this.props.node)} ref={this.deleteModal} />
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user