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
Implement searchable
property for marker schema
#4352
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,10 +56,16 @@ export const markerSchemaFrontEndOnly: MarkerSchema[] = [ | |
chartLabel: '{marker.data.messageType}', | ||
display: ['marker-chart', 'marker-table', 'timeline-ipc'], | ||
data: [ | ||
{ key: 'messageType', label: 'Type', format: 'string' }, | ||
{ key: 'messageType', label: 'Type', format: 'string', searchable: true }, | ||
{ key: 'sync', label: 'Sync', format: 'string' }, | ||
{ key: 'sendThreadName', label: 'From', format: 'string' }, | ||
{ key: 'recvThreadName', label: 'To', format: 'string' }, | ||
{ | ||
key: 'otherPid', | ||
label: 'Other Pid', | ||
format: 'string', | ||
searchable: true, | ||
}, | ||
], | ||
}, | ||
{ | ||
|
@@ -564,3 +570,39 @@ export function formatMarkupFromMarkerSchema( | |
throw new Error(`Unknown format type ${JSON.stringify((format: empty))}`); | ||
} | ||
} | ||
|
||
/** | ||
* Takes a marker and a RegExp and checks if any of its `searchable` marker | ||
* payload fields match the search regular expression. | ||
*/ | ||
export function markerPayloadMatchesSearch( | ||
markerSchema: MarkerSchema, | ||
marker: Marker, | ||
searchRegExp: RegExp | ||
): boolean { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that makes sense. Added it. |
||
const { data } = marker; | ||
if (!data) { | ||
return false; | ||
} | ||
|
||
// Reset regexp for each marker. Otherwise state from previous | ||
// usages can cause matches to fail if the search is global or | ||
// sticky. | ||
searchRegExp.lastIndex = 0; | ||
|
||
// Check if searchable fields match the search regular expression. | ||
for (const payloadField of markerSchema.data) { | ||
if (payloadField.searchable) { | ||
const value = data[payloadField.key]; | ||
if (value === undefined || value === null || value === '') { | ||
continue; | ||
} | ||
|
||
if (searchRegExp.test(value)) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea! maybe
target
wasn't existing at the time we implemented the custom search. Not sure :-)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it looks like this was added after the initial implementation.