From 79c36b9a84623fb99db0ab71cc9a31391f06489e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 27 Mar 2020 00:11:05 -0700 Subject: Partially implement device menu --- modern/src/DeviceList.js | 56 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'modern/src/DeviceList.js') diff --git a/modern/src/DeviceList.js b/modern/src/DeviceList.js index 235ba22..a97e4fe 100644 --- a/modern/src/DeviceList.js +++ b/modern/src/DeviceList.js @@ -1,3 +1,4 @@ +import t from './common/localization' import React, { Component, Fragment } from 'react'; import { connect } from 'react-redux'; import List from '@material-ui/core/List'; @@ -10,6 +11,9 @@ import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction'; import IconButton from '@material-ui/core/IconButton'; import MoreVertIcon from '@material-ui/icons/MoreVert'; import Divider from '@material-ui/core/Divider'; +import Menu from '@material-ui/core/Menu'; +import MenuItem from '@material-ui/core/MenuItem'; +import RemoveDialog from './RemoveDialog' import { devicesActions } from './store'; const mapStateToProps = state => ({ @@ -17,14 +21,40 @@ const mapStateToProps = state => ({ }); class DeviceList extends Component { - handleClick(device) { + constructor(props) { + super(props); + this.state = { + menuAnchorEl: null, + removeDialogOpen: false + }; + } + + handleItemClick(device) { this.props.dispatch(devicesActions.select(device)); } + handleMenuClick(event) { + this.setState({ menuAnchorEl: event.currentTarget }); + } + + handleMenuClose() { + this.setState({ menuAnchorEl: null }); + } + + handleMenuEdit() { + this.props.history.push('/device'); + this.handleMenuClose(); + } + + handleMenuRemove() { + this.setState({ removeDialogOpen: true }); + this.handleMenuClose(); + } + render() { const devices = this.props.devices.map((device, index, list) => - this.handleClick(device)}> + this.handleItemClick(device)}> @@ -32,7 +62,7 @@ class DeviceList extends Component { - + this.handleMenuClick(event)}> @@ -42,9 +72,23 @@ class DeviceList extends Component { ); return ( - - {devices} - + + + {devices} + + this.handleMenuClose()}> + this.handleMenuEdit()}>{t('sharedEdit')} + this.handleMenuRemove()}>{t('sharedRemove')} + + { this.setState({ removeDialogOpen: false }) }} /> + ); } } -- cgit v1.2.3