From 59ac1601ffbba05ba033f47cadbc25e9846a6fb4 Mon Sep 17 00:00:00 2001 From: Georg Rempfler Date: Sat, 27 Jan 2024 22:28:08 +0100 Subject: [PATCH 1/3] Allow "+"-wildcard in search expression. --- app/src/actions/Settings.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/actions/Settings.ts b/app/src/actions/Settings.ts index 0202aff1..20213487 100644 --- a/app/src/actions/Settings.ts +++ b/app/src/actions/Settings.ts @@ -103,9 +103,12 @@ export const filterTopics = (filterStr: string) => (dispatch: Dispatch, get } const topicFilter = filterStr.toLowerCase() + // code heavily inspired by https://stackoverflow.com/a/32402438 + const escapeRegex = (str: string) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); + const reTopicFilter = new RegExp(topicFilter.split('+').map(escapeRegex).join('[^/]+')) const nodeFilter = (node: q.TreeNode): boolean => { - const topicMatches = node.path().toLowerCase().indexOf(topicFilter) !== -1 + const topicMatches = node.path().toLowerCase().search(reTopicFilter) !== -1 if (topicMatches) { return true } From 4a9e4b69eccb4ae953c5a029bf1981e0bcef72a7 Mon Sep 17 00:00:00 2001 From: Georg Rempfler Date: Sat, 27 Jan 2024 22:29:31 +0100 Subject: [PATCH 2/3] Replace topic level(s) corresponding to "+"-wildcard(s) in search expression by "+" in topic tree. Watchout, the search expression changed to be case sensitive. This has been carefully considered. The internal switch to regular expressions and the use of that expression for the replacement in the topic tree has led to two options a) entering a search expression leads to a topic tree with all text lower cased (independent of the casing in the search expression) b) making the search expression case sensitive. Replacement does not change casing of original topics. Since MQTT-Topics are case sensitive themselves, option b) has been chosen. --- app/src/actions/Settings.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/actions/Settings.ts b/app/src/actions/Settings.ts index 20213487..c98c373f 100644 --- a/app/src/actions/Settings.ts +++ b/app/src/actions/Settings.ts @@ -102,13 +102,13 @@ export const filterTopics = (filterStr: string) => (dispatch: Dispatch, get return } - const topicFilter = filterStr.toLowerCase() + const topicFilter = filterStr // code heavily inspired by https://stackoverflow.com/a/32402438 const escapeRegex = (str: string) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); const reTopicFilter = new RegExp(topicFilter.split('+').map(escapeRegex).join('[^/]+')) const nodeFilter = (node: q.TreeNode): boolean => { - const topicMatches = node.path().toLowerCase().search(reTopicFilter) !== -1 + const topicMatches = node.path().search(reTopicFilter) !== -1 if (topicMatches) { return true } @@ -126,7 +126,8 @@ export const filterTopics = (filterStr: string) => (dispatch: Dispatch, get .filter(nodeFilter) .map((node: q.TreeNode) => { const clone = node.unconnectedClone() - q.TreeNodeFactory.insertNodeAtPosition(node.path().split('/'), clone) + const edgeNames = node.path().replace(reTopicFilter, filterStr).split('/') + q.TreeNodeFactory.insertNodeAtPosition(edgeNames, clone) return clone.firstNode() }) .reduce((a: q.TreeNode, b: q.TreeNode) => { From c08ef3182f62d29bc1bb27950e3320af594ead05 Mon Sep 17 00:00:00 2001 From: Georg Rempfler Date: Thu, 9 May 2024 22:40:51 +0200 Subject: [PATCH 3/3] run prettier on app/src/actions/Settings.ts. --- app/src/actions/Settings.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/src/actions/Settings.ts b/app/src/actions/Settings.ts index 21c96050..f6ac8eee 100644 --- a/app/src/actions/Settings.ts +++ b/app/src/actions/Settings.ts @@ -45,12 +45,12 @@ export const storeSettings = () => async (dispatch: Dispatch, getState: () export const setAutoExpandLimit = (autoExpandLimit: number = 0) => - (dispatch: Dispatch) => { - dispatch({ - autoExpandLimit, - type: ActionTypes.SETTINGS_SET_AUTO_EXPAND_LIMIT, - }) - } + (dispatch: Dispatch) => { + dispatch({ + autoExpandLimit, + type: ActionTypes.SETTINGS_SET_AUTO_EXPAND_LIMIT, + }) + } export const setTimeLocale = (timeLocale: string) => (dispatch: Dispatch) => { dispatch({ @@ -85,13 +85,13 @@ export const toggleHighlightTopicUpdates = () => (dispatch: Dispatch) => { export const setTopicOrder = (topicOrder: TopicOrder = TopicOrder.none) => - (dispatch: Dispatch) => { - dispatch({ - topicOrder, - type: ActionTypes.SETTINGS_SET_TOPIC_ORDER, - }) - dispatch(storeSettings()) - } + (dispatch: Dispatch) => { + dispatch({ + topicOrder, + type: ActionTypes.SETTINGS_SET_TOPIC_ORDER, + }) + dispatch(storeSettings()) + } export const filterTopics = (filterStr: string) => (dispatch: Dispatch, getState: () => AppState) => { const { tree } = getState().connection @@ -108,7 +108,7 @@ export const filterTopics = (filterStr: string) => (dispatch: Dispatch, get const topicFilter = filterStr // code heavily inspired by https://stackoverflow.com/a/32402438 - const escapeRegex = (str: string) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); + const escapeRegex = (str: string) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1') const reTopicFilter = new RegExp(topicFilter.split('+').map(escapeRegex).join('[^/]+')) const nodeFilter = (node: q.TreeNode): boolean => { @@ -171,4 +171,4 @@ export const toggleTheme = () => (dispatch: Dispatch, getState: () => AppSt : ActionTypes.SETTINGS_SET_THEME_LIGHT, }) dispatch(storeSettings()) -} +} \ No newline at end of file