1
1
import React , { useEffect , useMemo } from 'react' ;
2
2
import { NavLink , useLocation } from 'react-router-dom' ;
3
3
import type { Maybe } from 'true-myth' ;
4
- import type { ClickEvent } from '@pyroscope/ui/Menu' ;
5
4
import Color from 'color' ;
6
5
import TotalSamplesChart from '@pyroscope/pages/tagExplorer/components/TotalSamplesChart' ;
7
6
import type { Profile } from '@pyroscope/legacy/models' ;
@@ -10,7 +9,6 @@ import Toolbar from '@pyroscope/components/Toolbar';
10
9
import TimelineChartWrapper , {
11
10
TimelineGroupData ,
12
11
} from '@pyroscope/components/TimelineChart/TimelineChartWrapper' ;
13
- import Dropdown , { MenuItem } from '@pyroscope/ui/Dropdown' ;
14
12
import TagsSelector from '@pyroscope/pages/tagExplorer/components/TagsSelector' ;
15
13
import TableUI , { useTableSort , BodyRow } from '@pyroscope/ui/Table' ;
16
14
import useTimeZone from '@pyroscope/hooks/timeZone.hook' ;
@@ -23,7 +21,6 @@ import {
23
21
selectQueries ,
24
22
selectContinuousState ,
25
23
selectAppTags ,
26
- TagsState ,
27
24
fetchTagExplorerView ,
28
25
fetchTagExplorerViewProfile ,
29
26
ALL_TAGS ,
@@ -48,6 +45,7 @@ import styles from './TagExplorerView.module.scss';
48
45
import { formatTitle } from './formatTitle' ;
49
46
import { FlameGraphWrapper } from '@pyroscope/components/FlameGraphWrapper' ;
50
47
import profileMetrics from '../constants/profile-metrics.json' ;
48
+ import { ExploreHeader } from '@pyroscope/pages/tagExplorer/components/ExploreHeader' ;
51
49
52
50
const TIMELINE_SERIES_COLORS = [
53
51
Color . rgb ( 242 , 204 , 12 ) ,
@@ -160,7 +158,7 @@ const TIMELINE_WRAPPER_ID = 'explore_timeline_wrapper';
160
158
const getTimelineColor = ( index : number , palette : Color [ ] ) : Color =>
161
159
Color ( palette [ index % ( palette . length - 1 ) ] ) ;
162
160
163
- const getProfileMetricTitle = ( appName : Maybe < string > ) => {
161
+ export const getProfileMetricTitle = ( appName : Maybe < string > ) => {
164
162
const name = appName . unwrapOr ( '' ) ;
165
163
const profileMetric = ( profileMetrics as Record < string , any > ) [ name ] ;
166
164
@@ -650,82 +648,4 @@ function Table({
650
648
) ;
651
649
}
652
650
653
- function ExploreHeader ( {
654
- appName,
655
- whereDropdownItems,
656
- tags,
657
- selectedTag,
658
- selectedTagValue,
659
- handleGroupByTagChange,
660
- handleGroupByTagValueChange,
661
- } : {
662
- appName : Maybe < string > ;
663
- whereDropdownItems : string [ ] ;
664
- tags : TagsState ;
665
- selectedTag : string ;
666
- selectedTagValue : string ;
667
- handleGroupByTagChange : ( value : string ) => void ;
668
- handleGroupByTagValueChange : ( value : string ) => void ;
669
- } ) {
670
- const tagKeys = Object . keys ( tags . tags ) ;
671
- const groupByDropdownItems =
672
- tagKeys . length > 0 ? tagKeys : [ 'No tags available' ] ;
673
-
674
- const handleGroupByClick = ( e : ClickEvent ) => {
675
- handleGroupByTagChange ( e . value ) ;
676
- } ;
677
-
678
- const handleGroupByValueClick = ( e : ClickEvent ) => {
679
- handleGroupByTagValueChange ( e . value ) ;
680
- } ;
681
-
682
- useEffect ( ( ) => {
683
- if ( tagKeys . length && ! selectedTag ) {
684
- const firstGoodTag = tagKeys . find ( ( tag ) => ! tag . startsWith ( '__' ) ) ;
685
- handleGroupByTagChange ( firstGoodTag || tagKeys [ 0 ] ) ;
686
- }
687
- } , [ tagKeys , selectedTag , handleGroupByTagChange ] ) ;
688
-
689
- return (
690
- < div className = { styles . header } data-testid = "explore-header" >
691
- < span className = { styles . title } > { getProfileMetricTitle ( appName ) } </ span >
692
- < div className = { styles . queryGrouppedBy } >
693
- < span className = { styles . selectName } > grouped by</ span >
694
- < Dropdown
695
- label = "select tag"
696
- value = { selectedTag ? `tag: ${ selectedTag } ` : 'select tag' }
697
- onItemClick = { tagKeys . length > 0 ? handleGroupByClick : undefined }
698
- menuButtonClassName = {
699
- selectedTag === '' ? styles . notSelectedTagDropdown : undefined
700
- }
701
- >
702
- { groupByDropdownItems . map ( ( tagName ) => (
703
- < MenuItem key = { tagName } value = { tagName } >
704
- { tagName }
705
- </ MenuItem >
706
- ) ) }
707
- </ Dropdown >
708
- </ div >
709
- < div className = { styles . query } >
710
- < span className = { styles . selectName } > where</ span >
711
- < Dropdown
712
- label = "select where"
713
- value = { `${ selectedTag ? `${ selectedTag } = ` : selectedTag } ${
714
- selectedTagValue || ALL_TAGS
715
- } `}
716
- onItemClick = { handleGroupByValueClick }
717
- menuButtonClassName = { styles . whereSelectButton }
718
- >
719
- { /* always show "All" option */ }
720
- { [ ALL_TAGS , ...whereDropdownItems ] . map ( ( tagGroupName ) => (
721
- < MenuItem key = { tagGroupName } value = { tagGroupName } >
722
- { tagGroupName }
723
- </ MenuItem >
724
- ) ) }
725
- </ Dropdown >
726
- </ div >
727
- </ div >
728
- ) ;
729
- }
730
-
731
651
export default TagExplorerView ;
0 commit comments