Skip to content

Commit

Permalink
synthetics - waterfall chart - support wildcard search
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiqueclarke committed Aug 22, 2024
1 parent bf673d9 commit e309ebb
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,21 @@ export const getQueryMatcher = (query?: string): ItemMatcher => {
return (item: NetworkEvent) => true;
}

const regExp = new RegExp(query, 'i');

return (item: NetworkEvent) => {
return (item.url?.search(regExp) ?? -1) > -1;
};
/* RegExp below taken from: https://github.com/sindresorhus/escape-string-regexp/blob/main/index.js
* First, escape all special character to use an exact string match
* Next, replace escaped '*' with '.' to match any character and support wildcard search */
const formattedQuery = query.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
const wildcardQuery = formattedQuery.replaceAll('\\*', '.');

try {
const regExp = new RegExp(wildcardQuery, 'i');

return (item: NetworkEvent) => {
return (item.url?.search(regExp) ?? -1) > -1;
};
} catch (e) {
// ignore invalid regex
}
};

export const getFilterMatcher = (filters: string[] | undefined): ItemMatcher => {
Expand Down

0 comments on commit e309ebb

Please sign in to comment.