44
55import * as React from 'react' ;
66import classNames from 'classnames' ;
7+ import { Localized } from '@fluent/react' ;
78import {
89 formatMilliseconds ,
910 formatTimestamp ,
@@ -20,6 +21,7 @@ import {
2021 getProcessIdToNameMap ,
2122 getThreadSelectorsFromThreadsKey ,
2223} from 'firefox-profiler/selectors' ;
24+ import { changeMarkersSearchString } from 'firefox-profiler/actions/profile-view' ;
2325
2426import {
2527 TooltipNetworkMarkerPhases ,
@@ -96,10 +98,15 @@ type StateProps = {
9698 readonly processIdToNameMap : Map < Pid , string > ;
9799 readonly markerSchemaByName : MarkerSchemaByName ;
98100 readonly getMarkerLabel : ( param : MarkerIndex ) => string ;
101+ readonly getMarkerSearchTerm : ( param : MarkerIndex ) => string ;
99102 readonly categories : CategoryList ;
100103} ;
101104
102- type Props = ConnectedProps < OwnProps , StateProps , { } > ;
105+ type DispatchProps = {
106+ readonly changeMarkersSearchString : typeof changeMarkersSearchString ;
107+ } ;
108+
109+ type Props = ConnectedProps < OwnProps , StateProps , DispatchProps > ;
103110
104111// Maximum image size of a tooltip field.
105112const MAXIMUM_IMAGE_SIZE = 350 ;
@@ -473,10 +480,12 @@ class MarkerTooltipContents extends React.PureComponent<Props> {
473480 return null ;
474481 }
475482
476- _renderTitle ( ) : string {
477- const { markerIndex, getMarkerLabel } = this . props ;
478- return getMarkerLabel ( markerIndex ) ;
479- }
483+ _onFilterButtonClick = ( ) => {
484+ const { markerIndex, getMarkerSearchTerm, changeMarkersSearchString } =
485+ this . props ;
486+ const searchTerm = getMarkerSearchTerm ( markerIndex ) ;
487+ changeMarkersSearchString ( searchTerm ) ;
488+ } ;
480489
481490 /**
482491 * Often-times component logic is split out into several different components. This
@@ -501,13 +510,31 @@ class MarkerTooltipContents extends React.PureComponent<Props> {
501510 * a short list of rendering strategies, in the order they appear.
502511 */
503512 override render ( ) {
504- const { className } = this . props ;
513+ const { className, markerIndex, getMarkerLabel, getMarkerSearchTerm } =
514+ this . props ;
515+ const markerLabel = getMarkerLabel ( markerIndex ) ;
516+ const searchTerm = getMarkerSearchTerm ( markerIndex ) ;
505517 return (
506518 < div className = { classNames ( 'tooltipMarker' , className ) } >
507519 < div className = "tooltipHeader" >
508520 < div className = "tooltipOneLine" >
509521 { this . _maybeRenderMarkerDuration ( ) }
510- < div className = "tooltipTitle" > { this . _renderTitle ( ) } </ div >
522+ < div className = "tooltipTitle" >
523+ < span className = "tooltipTitleText" > { markerLabel } </ span >
524+ < Localized
525+ id = "MarkerTooltip--filter-button-tooltip"
526+ vars = { { filter : searchTerm } }
527+ attrs = { { title : true , 'aria-label' : true } }
528+ >
529+ < button
530+ className = "tooltipTitleFilterButton"
531+ type = "button"
532+ title = { `Only show markers matching: “${ searchTerm } ”` }
533+ aria-label = { `Only show markers matching: “${ searchTerm } ”` }
534+ onClick = { this . _onFilterButtonClick }
535+ />
536+ </ Localized >
537+ </ div >
511538 </ div >
512539 </ div >
513540 < TooltipDetails >
@@ -522,7 +549,11 @@ class MarkerTooltipContents extends React.PureComponent<Props> {
522549 }
523550}
524551
525- export const TooltipMarker = explicitConnect < OwnProps , StateProps , { } > ( {
552+ export const TooltipMarker = explicitConnect <
553+ OwnProps ,
554+ StateProps ,
555+ DispatchProps
556+ > ( {
526557 mapStateToProps : ( state , props ) => {
527558 const selectors = getThreadSelectorsFromThreadsKey ( props . threadsKey ) ;
528559 return {
@@ -536,8 +567,10 @@ export const TooltipMarker = explicitConnect<OwnProps, StateProps, {}>({
536567 processIdToNameMap : getProcessIdToNameMap ( state ) ,
537568 markerSchemaByName : getMarkerSchemaByName ( state ) ,
538569 getMarkerLabel : selectors . getMarkerTooltipLabelGetter ( state ) ,
570+ getMarkerSearchTerm : selectors . getMarkerSearchTermGetter ( state ) ,
539571 categories : getCategories ( state ) ,
540572 } ;
541573 } ,
574+ mapDispatchToProps : { changeMarkersSearchString } ,
542575 component : MarkerTooltipContents ,
543576} ) ;
0 commit comments