Refactored some components

This commit is contained in:
Alejandro Celaya 2018-08-12 08:45:48 +02:00
parent 86eb963176
commit 34155aae58
6 changed files with 51 additions and 20 deletions

View file

@ -18,6 +18,7 @@
"chart.js": "^2.7.2", "chart.js": "^2.7.2",
"moment": "^2.22.2", "moment": "^2.22.2",
"promise": "8.0.1", "promise": "8.0.1",
"prop-types": "^15.6.2",
"qs": "^6.5.2", "qs": "^6.5.2",
"ramda": "^0.25.0", "ramda": "^0.25.0",
"react": "^16.3.2", "react": "^16.3.2",

View file

@ -1,12 +1,13 @@
import listIcon from '@fortawesome/fontawesome-free-solid/faBars' import listIcon from '@fortawesome/fontawesome-free-solid/faBars';
import createIcon from '@fortawesome/fontawesome-free-solid/faPlus' import createIcon from '@fortawesome/fontawesome-free-solid/faPlus';
import FontAwesomeIcon from '@fortawesome/react-fontawesome' import FontAwesomeIcon from '@fortawesome/react-fontawesome';
import React from 'react' import React from 'react';
import { NavLink } from 'react-router-dom' import { NavLink } from 'react-router-dom';
import DeleteServerButton from '../servers/DeleteServerButton' import DeleteServerButton from '../servers/DeleteServerButton';
import './AsideMenu.scss' import './AsideMenu.scss';
import PropTypes from 'prop-types';
export default function AsideMenu({ selectedServer, history }) { export default function AsideMenu({ selectedServer }) {
const serverId = selectedServer ? selectedServer.id : ''; const serverId = selectedServer ? selectedServer.id : '';
return ( return (
@ -31,10 +32,18 @@ export default function AsideMenu({ selectedServer, history }) {
<DeleteServerButton <DeleteServerButton
className="aside-menu__item aside-menu__item--danger" className="aside-menu__item aside-menu__item--danger"
history={history}
server={selectedServer} server={selectedServer}
/> />
</nav> </nav>
</aside> </aside>
); );
} }
AsideMenu.propTypes = {
selectedServer: PropTypes.shape({
id: PropTypes.string,
name: PropTypes.string,
url: PropTypes.string,
apiKey: PropTypes.string,
}),
};

View file

@ -16,9 +16,11 @@ export class MenuLayout extends React.Component {
} }
render() { render() {
const { selectedServer } = this.props;
return ( return (
<div className="row"> <div className="row">
<AsideMenu {...this.props} /> <AsideMenu selectedServer={selectedServer} />
<div className="col-lg-10 offset-lg-2 col-md-9 offset-md-3"> <div className="col-lg-10 offset-lg-2 col-md-9 offset-md-3">
<Switch> <Switch>
<Route <Route

View file

@ -7,7 +7,7 @@ export default class DeleteServerButton extends React.Component {
state = { isModalOpen: false }; state = { isModalOpen: false };
render() { render() {
const { history, server } = this.props; const { server } = this.props;
return [ return [
( (
@ -24,7 +24,6 @@ export default class DeleteServerButton extends React.Component {
<DeleteServerModal <DeleteServerModal
isOpen={this.state.isModalOpen} isOpen={this.state.isModalOpen}
toggle={() => this.setState({ isModalOpen: !this.state.isModalOpen })} toggle={() => this.setState({ isModalOpen: !this.state.isModalOpen })}
history={history}
server={server} server={server}
key="deleteServerModal" key="deleteServerModal"
/> />

View file

@ -1,9 +1,12 @@
import PropTypes from 'prop-types';
import React from 'react'; import React from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
import { compose } from 'redux';
import { deleteServer } from './reducers/server'; import { deleteServer } from './reducers/server';
export const DeleteServerModal = ({ server, deleteServer, toggle, history, isOpen }) => { export const DeleteServerModal = ({ server, toggle, isOpen, deleteServer, history }) => {
const closeModal = () => { const closeModal = () => {
deleteServer(server); deleteServer(server);
toggle(); toggle();
@ -15,7 +18,10 @@ export const DeleteServerModal = ({ server, deleteServer, toggle, history, isOpe
<ModalHeader toggle={toggle}><span className="text-danger">Delete server</span></ModalHeader> <ModalHeader toggle={toggle}><span className="text-danger">Delete server</span></ModalHeader>
<ModalBody> <ModalBody>
<p>Are you sure you want to delete server <b>{server ? server.name : ''}</b>?</p> <p>Are you sure you want to delete server <b>{server ? server.name : ''}</b>?</p>
<p>No data will be deleted, only the access to that server will be removed from this host. You can create it again at any moment.</p> <p>
No data will be deleted, only the access to that server will be removed from this host.
You can create it again at any moment.
</p>
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
<button className="btn btn-link" onClick={toggle}>Cancel</button> <button className="btn btn-link" onClick={toggle}>Cancel</button>
@ -25,4 +31,18 @@ export const DeleteServerModal = ({ server, deleteServer, toggle, history, isOpe
); );
}; };
export default connect(null, { deleteServer })(DeleteServerModal); DeleteServerModal.propTypes = {
toggle: PropTypes.func.isRequired,
isOpen: PropTypes.bool.isRequired,
server: PropTypes.shape({
id: PropTypes.string,
name: PropTypes.string,
url: PropTypes.string,
apiKey: PropTypes.string,
}),
};
export default compose(
withRouter,
connect(null, { deleteServer })
)(DeleteServerModal);

View file

@ -1,8 +1,8 @@
import { shallow } from 'enzyme' import { shallow } from 'enzyme';
import { values } from 'ramda' import { values } from 'ramda';
import React from 'react' import React from 'react';
import * as sinon from 'sinon' import * as sinon from 'sinon';
import { Home } from '../../src/common/Home' import { Home } from '../../src/common/Home';
describe('<Home />', () => { describe('<Home />', () => {
let wrapped; let wrapped;