Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for "+" wildcard in search expression #751

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions app/src/actions/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export const storeSettings = () => async (dispatch: Dispatch<any>, getState: ()

export const setAutoExpandLimit =
(autoExpandLimit: number = 0) =>
(dispatch: Dispatch<any>) => {
dispatch({
autoExpandLimit,
type: ActionTypes.SETTINGS_SET_AUTO_EXPAND_LIMIT,
})
}
(dispatch: Dispatch<any>) => {
dispatch({
autoExpandLimit,
type: ActionTypes.SETTINGS_SET_AUTO_EXPAND_LIMIT,
})
}

export const setTimeLocale = (timeLocale: string) => (dispatch: Dispatch<any>) => {
dispatch({
Expand Down Expand Up @@ -85,13 +85,13 @@ export const toggleHighlightTopicUpdates = () => (dispatch: Dispatch<any>) => {

export const setTopicOrder =
(topicOrder: TopicOrder = TopicOrder.none) =>
(dispatch: Dispatch<any>) => {
dispatch({
topicOrder,
type: ActionTypes.SETTINGS_SET_TOPIC_ORDER,
})
dispatch(storeSettings())
}
(dispatch: Dispatch<any>) => {
dispatch({
topicOrder,
type: ActionTypes.SETTINGS_SET_TOPIC_ORDER,
})
dispatch(storeSettings())
}

export const filterTopics = (filterStr: string) => (dispatch: Dispatch<any>, getState: () => AppState) => {
const { tree } = getState().connection
Expand All @@ -106,10 +106,13 @@ export const filterTopics = (filterStr: string) => (dispatch: Dispatch<any>, 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<TopicViewModel>): boolean => {
const topicMatches = node.path().toLowerCase().indexOf(topicFilter) !== -1
const topicMatches = node.path().search(reTopicFilter) !== -1
if (topicMatches) {
return true
}
Expand All @@ -127,7 +130,8 @@ export const filterTopics = (filterStr: string) => (dispatch: Dispatch<any>, get
.filter(nodeFilter)
.map((node: q.TreeNode<TopicViewModel>) => {
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<TopicViewModel>, b: q.TreeNode<TopicViewModel>) => {
Expand Down Expand Up @@ -167,4 +171,4 @@ export const toggleTheme = () => (dispatch: Dispatch<any>, getState: () => AppSt
: ActionTypes.SETTINGS_SET_THEME_LIGHT,
})
dispatch(storeSettings())
}
}