diff --git a/app/src/actions/clearTopic.ts b/app/src/actions/clearTopic.ts index 71874f3..f5d4ee7 100644 --- a/app/src/actions/clearTopic.ts +++ b/app/src/actions/clearTopic.ts @@ -5,14 +5,12 @@ import { makePublishEvent, rendererEvents } from '../../../events' import { moveSelectionUpOrDownwards } from './visibleTreeTraversal' import { globalActions } from '.' -export const clearTopic = (topic: q.TreeNode, recursive: boolean, subtopicClearLimit = 50) => async ( +export const clearTopic = (topic: q.TreeNode, recursive: boolean) => async ( dispatch: Dispatch, getState: () => AppState ) => { if (recursive) { const topicCount = topic.childTopicCount() - const deleteLimitMessage = - topicCount > subtopicClearLimit ? ` You can only delete ${subtopicClearLimit} child topics at once.` : '' const topicDelta = topic.hasMessage() ? -1 : 0 const childTopicsMessage = @@ -23,7 +21,7 @@ export const clearTopic = (topic: q.TreeNode, recursive: boolean, subtopicC const confirmed = await dispatch( globalActions.requestConfirmation( 'Confirm delete', - `Do you want to delete "${topic.path()}"${childTopicsMessage}?${deleteLimitMessage}` + `Do you want to delete "${topic.path()}"${childTopicsMessage}?` ) ) if (!confirmed) { @@ -38,27 +36,19 @@ export const clearTopic = (topic: q.TreeNode, recursive: boolean, subtopicC return } const publishEvent = makePublishEvent(connectionId) - const mqttMessage = { - topic: 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, - retain: true, - qos: 0 as 0, - } - // Rate limit deletion - setTimeout(() => rendererEvents.emit(publishEvent, mqttMessage), 20 * idx) - }) - } + const topicsForPurging = recursive ? [topic, ...topic.childTopics()] : [topic] + + topicsForPurging + .filter(t => t.path() !== '' && t.hasMessage()) + .map(t => t.path()) + .forEach((path, idx) => { + const mqttMessage = { + topic: path, + payload: null, + retain: true, + qos: 0 as 0, + } + // Rate limit deletion + setTimeout(() => rendererEvents.emit(publishEvent, mqttMessage), 20 * idx) + }) } diff --git a/app/src/components/Sidebar/TopicPanel/RecursiveTopicDeleteButton.tsx b/app/src/components/Sidebar/TopicPanel/RecursiveTopicDeleteButton.tsx index 2cb32a2..66a3f63 100644 --- a/app/src/components/Sidebar/TopicPanel/RecursiveTopicDeleteButton.tsx +++ b/app/src/components/Sidebar/TopicPanel/RecursiveTopicDeleteButton.tsx @@ -13,25 +13,23 @@ export const RecursiveTopicDeleteButton = (props: { if (props.node) { event.stopPropagation() event.preventDefault() - props.deleteTopicAction(props.node, true, deleteLimit) + props.deleteTopicAction(props.node, true, Infinity) } }, [props.node] ) + if (!props.node) { return null } - const deleteLimit = 50 + const topicCount = props.node ? props.node.childTopicCount() : 0 if (topicCount === 0 || (props.node.message && topicCount === 1)) { return null } return ( - {topicCount >= deleteLimit ? '50+' : topicCount}} - color="secondary" - > - + {topicCount}} color="secondary"> + diff --git a/app/src/components/Sidebar/TopicPanel/TopicPanel.tsx b/app/src/components/Sidebar/TopicPanel/TopicPanel.tsx index 8507dc1..d42b34b 100644 --- a/app/src/components/Sidebar/TopicPanel/TopicPanel.tsx +++ b/app/src/components/Sidebar/TopicPanel/TopicPanel.tsx @@ -14,12 +14,12 @@ const TopicPanel = (props: { node?: q.TreeNode; actions: typeof sidebarActi console.log(node && node.path()) const copyTopic = node ? : null - const deleteTopic = useCallback((topic?: q.TreeNode, recursive: boolean = false, maxCount = 50) => { + const deleteTopic = useCallback((topic?: q.TreeNode, recursive: boolean = false) => { if (!topic) { return } - props.actions.clearTopic(topic, recursive, maxCount) + props.actions.clearTopic(topic, recursive) }, []) return useMemo( diff --git a/app/src/components/Tree/TreeNode/effects/useDeleteKeyCallback.tsx b/app/src/components/Tree/TreeNode/effects/useDeleteKeyCallback.tsx index 6eefe0d..e662180 100644 --- a/app/src/components/Tree/TreeNode/effects/useDeleteKeyCallback.tsx +++ b/app/src/components/Tree/TreeNode/effects/useDeleteKeyCallback.tsx @@ -9,7 +9,7 @@ export function useDeleteKeyCallback(topic: q.TreeNode, actions: typeof tre if (event.keyCode === KeyCodes.delete || event.keyCode === KeyCodes.backspace) { event.stopPropagation() event.preventDefault() - actions.clearTopic(topic, true, 50) + actions.clearTopic(topic, true) } }, [topic]