Skip to content

Commit 39d87d5

Browse files
Remove recursive topic removal limit
1 parent 6781170 commit 39d87d5

File tree

4 files changed

+25
-37
lines changed

4 files changed

+25
-37
lines changed

app/src/actions/clearTopic.ts

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import { makePublishEvent, rendererEvents } from '../../../events'
55
import { moveSelectionUpOrDownwards } from './visibleTreeTraversal'
66
import { globalActions } from '.'
77

8-
export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean, subtopicClearLimit = 50) => async (
8+
export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean) => async (
99
dispatch: Dispatch<any>,
1010
getState: () => AppState
1111
) => {
1212
if (recursive) {
1313
const topicCount = topic.childTopicCount()
14-
const deleteLimitMessage =
15-
topicCount > subtopicClearLimit ? ` You can only delete ${subtopicClearLimit} child topics at once.` : ''
1614

1715
const topicDelta = topic.hasMessage() ? -1 : 0
1816
const childTopicsMessage =
@@ -23,7 +21,7 @@ export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean, subtopicC
2321
const confirmed = await dispatch(
2422
globalActions.requestConfirmation(
2523
'Confirm delete',
26-
`Do you want to delete "${topic.path()}"${childTopicsMessage}?${deleteLimitMessage}`
24+
`Do you want to delete "${topic.path()}"${childTopicsMessage}?`
2725
)
2826
)
2927
if (!confirmed) {
@@ -38,27 +36,19 @@ export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean, subtopicC
3836
return
3937
}
4038
const publishEvent = makePublishEvent(connectionId)
41-
const mqttMessage = {
42-
topic: topic.path(),
43-
payload: null,
44-
retain: true,
45-
qos: 0 as 0,
46-
}
47-
rendererEvents.emit(publishEvent, mqttMessage)
48-
if (recursive) {
49-
topic
50-
.childTopics()
51-
.filter(topic => Boolean(topic.message && topic.message.value))
52-
.slice(0, subtopicClearLimit)
53-
.forEach((topic, idx) => {
54-
const mqttMessage = {
55-
topic: topic.path(),
56-
payload: null,
57-
retain: true,
58-
qos: 0 as 0,
59-
}
60-
// Rate limit deletion
61-
setTimeout(() => rendererEvents.emit(publishEvent, mqttMessage), 20 * idx)
62-
})
63-
}
39+
const topicsForPurging = recursive ? [topic, ...topic.childTopics()] : [topic]
40+
41+
topicsForPurging
42+
.filter(t => t.path() !== '' && t.hasMessage())
43+
.map(t => t.path())
44+
.forEach((path, idx) => {
45+
const mqttMessage = {
46+
topic: path,
47+
payload: null,
48+
retain: true,
49+
qos: 0 as 0,
50+
}
51+
// Rate limit deletion
52+
setTimeout(() => rendererEvents.emit(publishEvent, mqttMessage), 20 * idx)
53+
})
6454
}

app/src/components/Sidebar/TopicPanel/RecursiveTopicDeleteButton.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,23 @@ export const RecursiveTopicDeleteButton = (props: {
1313
if (props.node) {
1414
event.stopPropagation()
1515
event.preventDefault()
16-
props.deleteTopicAction(props.node, true, deleteLimit)
16+
props.deleteTopicAction(props.node, true, Infinity)
1717
}
1818
},
1919
[props.node]
2020
)
21+
2122
if (!props.node) {
2223
return null
2324
}
24-
const deleteLimit = 50
25+
2526
const topicCount = props.node ? props.node.childTopicCount() : 0
2627
if (topicCount === 0 || (props.node.message && topicCount === 1)) {
2728
return null
2829
}
2930
return (
30-
<Badge
31-
badgeContent={<span style={{ whiteSpace: 'nowrap' }}>{topicCount >= deleteLimit ? '50+' : topicCount}</span>}
32-
color="secondary"
33-
>
34-
<CustomIconButton onClick={onClick} tooltip={`Deletes up to ${deleteLimit} sub-topics with a single click`}>
31+
<Badge badgeContent={<span style={{ whiteSpace: 'nowrap' }}>{topicCount}</span>} color="secondary">
32+
<CustomIconButton onClick={onClick} tooltip={`Deletes ${topicCount} sub-topics with a single click`}>
3533
<Delete color="action" />
3634
</CustomIconButton>
3735
</Badge>

app/src/components/Sidebar/TopicPanel/TopicPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ const TopicPanel = (props: { node?: q.TreeNode<any>; actions: typeof sidebarActi
1414
console.log(node && node.path())
1515
const copyTopic = node ? <Copy value={node.path()} /> : null
1616

17-
const deleteTopic = useCallback((topic?: q.TreeNode<any>, recursive: boolean = false, maxCount = 50) => {
17+
const deleteTopic = useCallback((topic?: q.TreeNode<any>, recursive: boolean = false) => {
1818
if (!topic) {
1919
return
2020
}
2121

22-
props.actions.clearTopic(topic, recursive, maxCount)
22+
props.actions.clearTopic(topic, recursive)
2323
}, [])
2424

2525
return useMemo(

app/src/components/Tree/TreeNode/effects/useDeleteKeyCallback.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function useDeleteKeyCallback(topic: q.TreeNode<any>, actions: typeof tre
99
if (event.keyCode === KeyCodes.delete || event.keyCode === KeyCodes.backspace) {
1010
event.stopPropagation()
1111
event.preventDefault()
12-
actions.clearTopic(topic, true, 50)
12+
actions.clearTopic(topic, true)
1313
}
1414
},
1515
[topic]

0 commit comments

Comments
 (0)