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

[Synthetics] waterfall chart - support wildcard search #191132

Merged
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,26 @@ export const getConnectingTime = (connect?: number, ssl?: number) => {
}
};

export const getQueryMatcher = (query?: string): ItemMatcher => {
export const getQueryMatcher = (query?: string): ItemMatcher | undefined => {
if (!query) {
return (item: NetworkEvent) => true;
}

const regExp = new RegExp(query, 'i');
/* 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('\\*', '.');

return (item: NetworkEvent) => {
return (item.url?.search(regExp) ?? -1) > -1;
};
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