@@ -5,33 +5,100 @@ import {Card} from "primereact/card";
55import { ScrollPanel } from "primereact/scrollpanel" ;
66import { SelectButton } from "primereact/selectbutton" ;
77import ChartCard from "./chart-card" ;
8+ import { AutoComplete } from "primereact/autocomplete" ;
9+ import { ListBox } from "primereact/listbox" ;
10+ import { Button } from "primereact/button" ;
11+ import randomColor from 'randomcolor' ;
12+ import TagsCard from "./tags-card" ;
813
914const Dashboard = ( props ) => {
1015 const [ chartType , setChartType ] = useState ( "bar" ) ;
16+ const [ tags , setTags ] = useState ( null ) ;
17+ const [ samples , setSamples ] = useState ( props . samples ) ;
18+ const [ tagsSuggestions , setTagsSuggestions ] = useState ( null ) ;
1119 const types = [
1220 { label : 'Vertical Bar' , value : 'bar' } ,
1321 { label : 'Horizontal Bar' , value : 'horizontalBar' } ,
1422 ] ;
23+
24+ const filterTags = ( event ) => {
25+ setTimeout ( ( ) => {
26+ const results = props . tags . filter ( tag => ( tag . toLowerCase ( ) . indexOf ( event . query . toLowerCase ( ) ) >= 0 ) ) ;
27+ setTagsSuggestions ( results )
28+ } , 250 ) ;
29+ } ;
30+
31+ const renderListItem = ( item ) => {
32+ const classes = ! ! samples . find ( ( it ) => it . name === item . name ) ?
33+ "mdi mdi-checkbox-marked-outline mdi-18" : "mdi mdi-checkbox-blank-outline mdi-18" ;
34+ return ( < span > < i className = { classes } style = { { paddingRight : '5px' } } /> { item . name } </ span > ) ;
35+ } ;
36+
37+ const selectTags = ( e ) => {
38+ const tags = e . value ;
39+ setTags ( tags ) ;
40+ if ( tags . length > 0 ) {
41+ setSamples ( props . samples . filter ( ( it ) => _ . intersection ( it . tags , tags ) . length > 0 ) ) ;
42+ }
43+ } ;
44+
1545 return (
1646 < div className = "p-grid" >
1747 < div className = "p-sm-12 p-md-12 p-lg-4 p-xl-3" style = { { paddingTop : '5em' } } >
1848 < div className = "p-grid p-justify-around" >
1949 < Card style = { { width : '280px' } } >
20- < SelectButton value = { chartType } options = { types } onChange = { ( e ) => setChartType ( e . value ) } />
50+ < div className = "p-grid p-dir-col" >
51+ < div className = "p-col" >
52+ < SelectButton value = { chartType } options = { types }
53+ onChange = { ( e ) => setChartType ( e . value ) } />
54+ </ div >
55+ < div className = "p-col" >
56+ < AutoComplete value = { tags } suggestions = { tagsSuggestions } completeMethod = { filterTags }
57+ minLength = { 1 } placeholder = "Tags" multiple = { true } className = "tags-search"
58+ onChange = { selectTags } />
59+ </ div >
60+ < div className = "p-col" >
61+ < ListBox value = { samples } options = { props . samples } className = "samples-list"
62+ onChange = { ( e ) => setSamples ( e . value ) }
63+ filter = { true } multiple = { true } optionLabel = "name"
64+ itemTemplate = { renderListItem }
65+ />
66+
67+ < div className = "p-grid app-tools" >
68+ < div className = "p-col" >
69+ < Button label = "Select All" className = "p-button-raised p-button-secondary"
70+ onClick = { ( ) => setSamples ( props . samples ) }
71+ />
72+ </ div >
73+ < div className = "p-col" >
74+ < Button label = "Clear All" className = "p-button-raised p-button-secondary"
75+ onClick = { ( ) => setSamples ( [ ] ) }
76+ />
77+ </ div >
78+ </ div >
79+ </ div >
80+ </ div >
2181 </ Card >
82+
83+ < TagsCard samples = { props . samples } />
2284 </ div >
2385 </ div >
2486 < div className = "p-sm-12 p-md-12 p-lg-8 p-xl-6" >
2587 < ScrollPanel style = { { width : '100%' , height : 'calc(100vh - 5.1em)' , paddingTop : '5em' } } >
26- < ChartCard title = "Memory on start (Mb)" chartType = { chartType } data = { props . memoryOnStart } first = { true } />
88+ < ChartCard title = "Memory on start (Mb)" chartType = { chartType } data = { props . memoryOnStart }
89+ first = { true } samples = { samples } />
2790
28- < ChartCard title = "Working memory (Mb)" chartType = { chartType } data = { props . memoryOnWork } />
91+ < ChartCard title = "Working memory (Mb)" chartType = { chartType } data = { props . memoryOnWork }
92+ samples = { samples } />
2993
30- < ChartCard title = "Uptime (ms)" chartType = { chartType } data = { props . uptime } />
94+ < ChartCard title = "Uptime (ms)" chartType = { chartType } data = { props . uptime }
95+ samples = { samples } />
3196
32- < ChartCard title = "Warming up (ms)" chartType = { chartType } data = { props . warmingUp } />
97+ < ChartCard title = "Warming up (ms)" chartType = { chartType } data = { props . warmingUp }
98+ samples = { samples } />
3399
34- < ChartCard title = "Request time (ms)" chartType = { chartType } data = { props . requestTime } />
100+ < ChartCard title = "Request time (ms)" chartType = { chartType } data = { props . requestTime }
101+ samples = { samples } />
35102 </ ScrollPanel >
36103 </ div >
37104 </ div >
@@ -45,14 +112,12 @@ const mapStateToProps = state => {
45112
46113 const colors = _ . zipObject (
47114 state . metrics . map ( sample => ( sample . name ) ) ,
48- state . metrics . map ( ( ) => ( '#' + ( 0x1000000 + ( Math . random ( ) ) * 0xffffff ) . toString ( 16 ) . substr ( 1 , 6 ) ) )
115+ state . metrics . map ( ( ) => ( randomColor ( ) ) )
49116 ) ;
50117
51118 return ( {
52- samples : _ . zipObject (
53- state . metrics . map ( sample => ( sample . name ) ) ,
54- state . metrics . map ( sample => ( sample . tags ) )
55- ) ,
119+ samples : state . metrics . map ( sample => ( { name : sample . name , tags : sample . tags } ) ) ,
120+ tags : _ . uniq ( _ . flatMap ( state . metrics . map ( sample => ( sample . tags ) ) ) ) ,
56121 uptime : {
57122 labels : [ 'Avg' , 'Max' , 'Min' ] ,
58123 datasets : state . metrics . map ( sample => ( {
0 commit comments