Skip to content

Commit

Permalink
[Synthetics] waterfall chart - support wildcard search (elastic#191132)
Browse files Browse the repository at this point in the history
## Summary

Resolves elastic#172033

### Release note
Enables wildcard search for the Synthetics waterfall chart.

### Testing

1. Create a browser monitor
2. Navigate to the waterfall chart
3. Add a wildcard search in the text box. For example `*.js`. 
4. You shouldn't see an error, and it should match all requests with
`.js` in the name
  • Loading branch information
dominiqueclarke authored Aug 23, 2024
1 parent fa69337 commit eca2cdc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('WaterfallChartWrapper', () => {

const filterInput = getByLabelText(FILTER_REQUESTS_LABEL);

const searchText = '.js';
const searchText = '*.js';

fireEvent.change(filterInput, { target: { value: searchText } });

Expand Down

0 comments on commit eca2cdc

Please sign in to comment.