This commit is contained in:
Thomas Nordquist
2019-02-18 19:58:17 +01:00
parent 24c6b7e7b3
commit ddc801fe93
2 changed files with 35 additions and 15 deletions

View File

@@ -12,7 +12,7 @@ export const clearRetainedTopic = () => (dispatch: Dispatch<any>, getState: () =
dispatch(clearTopic(selectedTopic, false)) dispatch(clearTopic(selectedTopic, false))
} }
export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean) => (dispatch: Dispatch<any>, getState: () => AppState) => { export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean, subtopicClearLimit = 50) => (dispatch: Dispatch<any>, getState: () => AppState) => {
const { connectionId } = getState().connection const { connectionId } = getState().connection
if (!connectionId) { if (!connectionId) {
return return
@@ -29,7 +29,10 @@ export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean) => (dispa
rendererEvents.emit(publishEvent, mqttMessage) rendererEvents.emit(publishEvent, mqttMessage)
if (recursive) { if (recursive) {
topic.childTopics().forEach((topic) => { topic.childTopics()
.filter(topic => Boolean(topic.message && topic.message.value))
.slice(0, subtopicClearLimit)
.forEach((topic) => {
console.log('deleting', topic.path()) console.log('deleting', topic.path())
const mqttMessage = { const mqttMessage = {
topic: topic.path(), topic: topic.path(),

View File

@@ -4,6 +4,7 @@ import Clear from '@material-ui/icons/Clear'
import Copy from '../Copy' import Copy from '../Copy'
import DateFormatter from '../helper/DateFormatter' import DateFormatter from '../helper/DateFormatter'
import Delete from '@material-ui/icons/Delete' import Delete from '@material-ui/icons/Delete'
import DeleteForever from '@material-ui/icons/DeleteForever'
import ExpandMore from '@material-ui/icons/ExpandMore' import ExpandMore from '@material-ui/icons/ExpandMore'
import MessageHistory from './MessageHistory' import MessageHistory from './MessageHistory'
import NodeStats from './NodeStats' import NodeStats from './NodeStats'
@@ -26,8 +27,10 @@ import {
Popper, Popper,
Typography, Typography,
Tooltip, Tooltip,
Badge,
} from '@material-ui/core' } from '@material-ui/core'
import CustomIconButton from '../CustomIconButton'; import CustomIconButton from '../CustomIconButton';
import { max } from 'moment';
const throttle = require('lodash.throttle') const throttle = require('lodash.throttle')
@@ -102,19 +105,33 @@ class Sidebar extends React.Component<Props, State> {
} }
private renderRecursiveTopicDeleteButton() { private renderRecursiveTopicDeleteButton() {
if (!this.props.node) { const deleteLimit = 50
const topicCount = this.props.node ? this.props.node.childTopicCount() : 0
if (!this.props.node || topicCount <= 1) {
return null return null
} }
return <CustomIconButton onClick={() => this.deleteTopic(this.props.node, true)}><Delete style={{ color: 'red' }} /></CustomIconButton> return (
<CustomIconButton onClick={() => this.deleteTopic(this.props.node, true, deleteLimit)}>
<Tooltip title={`Deletes up to ${deleteLimit} sub-topics with a single click`}>
<Badge
classes={{ badge: this.props.classes.badge }}
badgeContent={<span style={{ whiteSpace: 'nowrap' }}>{topicCount >= deleteLimit ? '50+' : topicCount}</span>}
color="secondary"
>
<DeleteForever color="action" />
</Badge>
</Tooltip>
</CustomIconButton>
)
} }
private deleteTopic = (topic?: q.TreeNode<TopicViewModel>, recursive: boolean = false) => { private deleteTopic = (topic?: q.TreeNode<TopicViewModel>, recursive: boolean = false, maxCount = 50) => {
if (!topic) { if (!topic) {
return return
} }
this.props.actions.clearTopic(topic, recursive) this.props.actions.clearTopic(topic, recursive, maxCount)
} }
private renderNode() { private renderNode() {