Remove recursive topic removal limit

This commit is contained in:
Thomas Nordquist
2019-07-23 00:36:15 +02:00
parent 6781170b85
commit 39d87d5a8e
4 changed files with 25 additions and 37 deletions

View File

@@ -5,14 +5,12 @@ import { makePublishEvent, rendererEvents } from '../../../events'
import { moveSelectionUpOrDownwards } from './visibleTreeTraversal' import { moveSelectionUpOrDownwards } from './visibleTreeTraversal'
import { globalActions } from '.' import { globalActions } from '.'
export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean, subtopicClearLimit = 50) => async ( export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean) => async (
dispatch: Dispatch<any>, dispatch: Dispatch<any>,
getState: () => AppState getState: () => AppState
) => { ) => {
if (recursive) { if (recursive) {
const topicCount = topic.childTopicCount() const topicCount = topic.childTopicCount()
const deleteLimitMessage =
topicCount > subtopicClearLimit ? ` You can only delete ${subtopicClearLimit} child topics at once.` : ''
const topicDelta = topic.hasMessage() ? -1 : 0 const topicDelta = topic.hasMessage() ? -1 : 0
const childTopicsMessage = const childTopicsMessage =
@@ -23,7 +21,7 @@ export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean, subtopicC
const confirmed = await dispatch( const confirmed = await dispatch(
globalActions.requestConfirmation( globalActions.requestConfirmation(
'Confirm delete', 'Confirm delete',
`Do you want to delete "${topic.path()}"${childTopicsMessage}?${deleteLimitMessage}` `Do you want to delete "${topic.path()}"${childTopicsMessage}?`
) )
) )
if (!confirmed) { if (!confirmed) {
@@ -38,21 +36,14 @@ export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean, subtopicC
return return
} }
const publishEvent = makePublishEvent(connectionId) const publishEvent = makePublishEvent(connectionId)
const topicsForPurging = recursive ? [topic, ...topic.childTopics()] : [topic]
topicsForPurging
.filter(t => t.path() !== '' && t.hasMessage())
.map(t => t.path())
.forEach((path, idx) => {
const mqttMessage = { const mqttMessage = {
topic: topic.path(), topic: path,
payload: null,
retain: true,
qos: 0 as 0,
}
rendererEvents.emit(publishEvent, mqttMessage)
if (recursive) {
topic
.childTopics()
.filter(topic => Boolean(topic.message && topic.message.value))
.slice(0, subtopicClearLimit)
.forEach((topic, idx) => {
const mqttMessage = {
topic: topic.path(),
payload: null, payload: null,
retain: true, retain: true,
qos: 0 as 0, qos: 0 as 0,
@@ -60,5 +51,4 @@ export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean, subtopicC
// Rate limit deletion // Rate limit deletion
setTimeout(() => rendererEvents.emit(publishEvent, mqttMessage), 20 * idx) setTimeout(() => rendererEvents.emit(publishEvent, mqttMessage), 20 * idx)
}) })
}
} }

View File

@@ -13,25 +13,23 @@ export const RecursiveTopicDeleteButton = (props: {
if (props.node) { if (props.node) {
event.stopPropagation() event.stopPropagation()
event.preventDefault() event.preventDefault()
props.deleteTopicAction(props.node, true, deleteLimit) props.deleteTopicAction(props.node, true, Infinity)
} }
}, },
[props.node] [props.node]
) )
if (!props.node) { if (!props.node) {
return null return null
} }
const deleteLimit = 50
const topicCount = props.node ? props.node.childTopicCount() : 0 const topicCount = props.node ? props.node.childTopicCount() : 0
if (topicCount === 0 || (props.node.message && topicCount === 1)) { if (topicCount === 0 || (props.node.message && topicCount === 1)) {
return null return null
} }
return ( return (
<Badge <Badge badgeContent={<span style={{ whiteSpace: 'nowrap' }}>{topicCount}</span>} color="secondary">
badgeContent={<span style={{ whiteSpace: 'nowrap' }}>{topicCount >= deleteLimit ? '50+' : topicCount}</span>} <CustomIconButton onClick={onClick} tooltip={`Deletes ${topicCount} sub-topics with a single click`}>
color="secondary"
>
<CustomIconButton onClick={onClick} tooltip={`Deletes up to ${deleteLimit} sub-topics with a single click`}>
<Delete color="action" /> <Delete color="action" />
</CustomIconButton> </CustomIconButton>
</Badge> </Badge>

View File

@@ -14,12 +14,12 @@ const TopicPanel = (props: { node?: q.TreeNode<any>; actions: typeof sidebarActi
console.log(node && node.path()) console.log(node && node.path())
const copyTopic = node ? <Copy value={node.path()} /> : null const copyTopic = node ? <Copy value={node.path()} /> : null
const deleteTopic = useCallback((topic?: q.TreeNode<any>, recursive: boolean = false, maxCount = 50) => { const deleteTopic = useCallback((topic?: q.TreeNode<any>, recursive: boolean = false) => {
if (!topic) { if (!topic) {
return return
} }
props.actions.clearTopic(topic, recursive, maxCount) props.actions.clearTopic(topic, recursive)
}, []) }, [])
return useMemo( return useMemo(

View File

@@ -9,7 +9,7 @@ export function useDeleteKeyCallback(topic: q.TreeNode<any>, actions: typeof tre
if (event.keyCode === KeyCodes.delete || event.keyCode === KeyCodes.backspace) { if (event.keyCode === KeyCodes.delete || event.keyCode === KeyCodes.backspace) {
event.stopPropagation() event.stopPropagation()
event.preventDefault() event.preventDefault()
actions.clearTopic(topic, true, 50) actions.clearTopic(topic, true)
} }
}, },
[topic] [topic]