Add "delete retained topic" button

This commit is contained in:
Thomas Nordquist
2019-01-20 14:56:52 +01:00
parent b0d25b438d
commit 1ac1dede98
3 changed files with 56 additions and 6 deletions

View File

@@ -0,0 +1,19 @@
import { Dispatch, Action } from 'redux'
import { AppState } from '../reducers'
import { makePublishEvent, rendererEvents } from '../../../events'
export const clearRetainedTopic = () => (dispatch: Dispatch<Action>, getState: () => AppState) => {
const { selectedTopic, connectionId } = getState().tooBigReducer
if (!selectedTopic || !connectionId) {
return
}
const publishEvent = makePublishEvent(connectionId)
const mqttMessage = {
topic: selectedTopic.path(),
payload: null,
retain: true,
qos: 0 as 0,
}
rendererEvents.emit(publishEvent, mqttMessage)
}

View File

@@ -3,5 +3,6 @@ import * as publishActions from './Publish'
import * as treeActions from './Tree' import * as treeActions from './Tree'
import * as updateNotifierActions from './UpdateNotifier' import * as updateNotifierActions from './UpdateNotifier'
import * as connectionActions from './Connection' import * as connectionActions from './Connection'
import * as sidebarActons from './Sidebar'
export { settingsActions, treeActions, publishActions, updateNotifierActions, connectionActions } export { settingsActions, treeActions, publishActions, updateNotifierActions, connectionActions, sidebarActons }

View File

@@ -2,31 +2,40 @@ import * as React from 'react'
import * as q from '../../../../backend/src/Model' import * as q from '../../../../backend/src/Model'
import { import {
Button,
ExpansionPanel, ExpansionPanel,
ExpansionPanelDetails, ExpansionPanelDetails,
ExpansionPanelSummary, ExpansionPanelSummary,
Fade, Fade,
Fab,
Paper, Paper,
Popper, Popper,
Typography, Typography,
IconButton,
Tooltip,
} from '@material-ui/core' } from '@material-ui/core'
import { StyleRulesCallback, Theme, withStyles } from '@material-ui/core/styles' import { StyleRulesCallback, Theme, withStyles } from '@material-ui/core/styles'
import { sidebarActons } from '../../actions'
import { AppState } from '../../reducers' import { AppState } from '../../reducers'
import Copy from '../Copy' import Copy from '../Copy'
import DateFormatter from '../DateFormatter' import DateFormatter from '../DateFormatter'
import ExpandMore from '@material-ui/icons/ExpandMore' import ExpandMore from '@material-ui/icons/ExpandMore'
import Clear from '@material-ui/icons/Clear'
import MessageHistory from './MessageHistory' import MessageHistory from './MessageHistory'
import NodeStats from './NodeStats' import NodeStats from './NodeStats'
import Publish from './Publish/Publish' import Publish from './Publish/Publish'
import Topic from './Topic' import Topic from './Topic'
import ValueRenderer from './ValueRenderer' import ValueRenderer from './ValueRenderer'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { bindActionCreators } from 'redux';
const throttle = require('lodash.throttle') const throttle = require('lodash.throttle')
interface Props { interface Props {
node?: q.TreeNode, node?: q.TreeNode,
actions: typeof sidebarActons,
classes: any, classes: any,
theme: Theme, theme: Theme,
connectionId?: string, connectionId?: string,
@@ -157,13 +166,28 @@ class Sidebar extends React.Component<Props, State> {
return null return null
} }
const retainedButton = (
<Tooltip title="Delete retained topic" placement="top">
<Button
size="small"
color="secondary"
variant="contained"
mini={true}
style={{ marginTop: '-2px', padding: '0px 4px', minHeight: '24px' }}
onClick={this.props.actions.clearRetainedTopic}
>
retained <Clear style={{ fontSize: '16px', marginLeft: '2px' }} />
</Button>
</Tooltip>
)
return ( return (
<div style={{ width: '100%', display: 'flex' }}> <div style={{ width: '100%', display: 'flex' }}>
<div style={{ flex: 1 }}><Typography>QoS: {this.props.node.mqttMessage.qos}</Typography></div> <div style={{ flex: 6 }}><Typography>QoS: {this.props.node.mqttMessage.qos}</Typography></div>
<div style={{ flex: 1, textAlign: 'center' }}> <div style={{ flex: 8, textAlign: 'center' }}>
<Typography style={{ color: this.props.theme.palette.secondary.main }}><b>{this.props.node.mqttMessage.retain ? 'retained' : null}</b></Typography> {this.props.node.mqttMessage.retain ? retainedButton : null}
</div> </div>
<div style={{ flex: 1, textAlign: 'right' }}><Typography><i><DateFormatter date={this.props.node.message.received} /></i></Typography></div> <div style={{ flex: 8, textAlign: 'right' }}><Typography><i><DateFormatter date={this.props.node.message.received} /></i></Typography></div>
</div> </div>
) )
} }
@@ -195,4 +219,10 @@ const mapStateToProps = (state: AppState) => {
} }
} }
export default withStyles(Sidebar.styles, { withTheme: true })(connect(mapStateToProps)(Sidebar)) const mapDispatchToProps = (dispatch: any) => {
return {
actions: bindActionCreators(sidebarActons, dispatch),
}
}
export default withStyles(Sidebar.styles, { withTheme: true })(connect(mapStateToProps, mapDispatchToProps)(Sidebar))