1
1
import * as React from 'react' ;
2
- import { List , ListRowProps , AutoSizer } from 'react-virtualized' ;
3
2
import { OutputAddedSignalPayload } from 'traceviewer-base/lib/signals/output-added-signal-payload' ;
4
3
import { signalManager , Signals } from 'traceviewer-base/lib/signals/signal-manager' ;
5
4
import { OutputDescriptor } from 'tsp-typescript-client/lib/models/output-descriptor' ;
6
5
import { Experiment } from 'tsp-typescript-client/lib/models/experiment' ;
7
6
import { ITspClientProvider } from 'traceviewer-base/lib/tsp-client-provider' ;
8
7
import { ExperimentManager } from 'traceviewer-base/lib/experiment-manager' ;
8
+ import { AvailableViewsComponent } from '../components/utils/available-views-component' ;
9
9
10
10
export interface ReactAvailableViewsProps {
11
11
id : string ,
@@ -15,16 +15,10 @@ export interface ReactAvailableViewsProps {
15
15
}
16
16
17
17
export interface ReactAvailableViewsState {
18
- availableOutputDescriptors : OutputDescriptor [ ] ,
19
- lastSelectedOutputIndex : number ;
18
+ availableOutputDescriptors : OutputDescriptor [ ]
20
19
}
21
20
22
21
export class ReactAvailableViewsWidget extends React . Component < ReactAvailableViewsProps , ReactAvailableViewsState > {
23
- static LIST_MARGIN = 2 ;
24
- static LINE_HEIGHT = 16 ;
25
- static ROW_HEIGHT = ( 2 * ReactAvailableViewsWidget . LINE_HEIGHT ) + ReactAvailableViewsWidget . LIST_MARGIN ;
26
-
27
- private _forceUpdateKey = false ;
28
22
private _selectedExperiment : Experiment | undefined ;
29
23
private _experimentManager : ExperimentManager ;
30
24
@@ -39,7 +33,7 @@ export class ReactAvailableViewsWidget extends React.Component<ReactAvailableVie
39
33
} ) ;
40
34
signalManager ( ) . on ( Signals . EXPERIMENT_SELECTED , this . _onExperimentSelected ) ;
41
35
signalManager ( ) . on ( Signals . EXPERIMENT_CLOSED , this . _onExperimentClosed ) ;
42
- this . state = { availableOutputDescriptors : [ ] , lastSelectedOutputIndex : - 1 } ;
36
+ this . state = { availableOutputDescriptors : [ ] } ;
43
37
}
44
38
45
39
componentWillUnmount ( ) : void {
@@ -48,85 +42,25 @@ export class ReactAvailableViewsWidget extends React.Component<ReactAvailableVie
48
42
}
49
43
50
44
render ( ) : React . ReactNode {
51
- this . _forceUpdateKey = ! this . _forceUpdateKey ;
52
- const key = Number ( this . _forceUpdateKey ) ;
53
- let outputsRowCount = 0 ;
54
- const outputs = this . state . availableOutputDescriptors ;
55
- if ( outputs ) {
56
- outputsRowCount = outputs . length ;
57
- }
58
- const totalHeight = this . getTotalHeight ( ) ;
59
45
return (
60
46
< div className = 'trace-explorer-views' >
61
- < div className = 'trace-explorer-panel-content disable-select' >
62
- < AutoSizer >
63
- { ( { width } ) =>
64
- < List
65
- key = { key }
66
- height = { totalHeight }
67
- width = { width }
68
- rowCount = { outputsRowCount }
69
- rowHeight = { ReactAvailableViewsWidget . ROW_HEIGHT }
70
- rowRenderer = { this . renderRowOutputs }
71
- />
72
- }
73
- </ AutoSizer >
74
- </ div >
47
+ < AvailableViewsComponent
48
+ traceID = { this . _selectedExperiment ?. UUID }
49
+ outputDescriptors = { this . state . availableOutputDescriptors }
50
+ onContextMenuEvent = { this . handleContextMenuEvent }
51
+ onOutputClicked = { this . handleOutputClicked }
52
+ highlightAfterSelection = { true }
53
+ > </ AvailableViewsComponent >
75
54
</ div >
76
55
) ;
77
56
}
78
57
79
- protected renderRowOutputs = ( props : ListRowProps ) : React . ReactNode => this . doRenderRowOutputs ( props ) ;
80
-
81
- private doRenderRowOutputs ( props : ListRowProps ) : React . ReactNode {
82
- let outputName = '' ;
83
- let outputDescription = '' ;
84
- let output : OutputDescriptor | undefined ;
85
- const outputDescriptors = this . state . availableOutputDescriptors ;
86
- if ( outputDescriptors && outputDescriptors . length && props . index < outputDescriptors . length ) {
87
- output = outputDescriptors [ props . index ] ;
88
- outputName = output . name ;
89
- outputDescription = output . description ;
90
- }
91
- let traceContainerClassName = 'outputs-list-container' ;
92
- if ( props . index === this . state . lastSelectedOutputIndex ) {
93
- traceContainerClassName = traceContainerClassName + ' theia-mod-selected' ;
94
- }
95
- return < div className = { traceContainerClassName }
96
- title = { outputName + ':\n' + outputDescription }
97
- id = { `${ traceContainerClassName } -${ props . index } ` }
98
- key = { props . key }
99
- style = { props . style }
100
- onClick = { this . handleOutputClicked }
101
- onContextMenu = { event => { this . handleContextMenuEvent ( event , output ) ; } }
102
- data-id = { `${ props . index } ` }
103
- >
104
- < h4 className = 'outputs-element-name' >
105
- { outputName }
106
- </ h4 >
107
- < div className = 'outputs-element-description child-element' >
108
- { outputDescription }
109
- </ div >
110
- </ div > ;
111
- }
112
-
113
- protected getTotalHeight ( ) : number {
114
- let totalHeight = 0 ;
115
- const outputDescriptors = this . state . availableOutputDescriptors ;
116
- outputDescriptors ?. forEach ( ( ) => totalHeight += ReactAvailableViewsWidget . ROW_HEIGHT ) ;
117
- return totalHeight ;
118
- }
119
-
120
- protected handleOutputClicked = ( e : React . MouseEvent < HTMLDivElement > ) : void => this . doHandleOutputClicked ( e ) ;
58
+ protected handleOutputClicked = ( outputDescriptor : OutputDescriptor ) : void => this . doHandleOutputClicked ( outputDescriptor ) ;
121
59
protected handleContextMenuEvent = ( e : React . MouseEvent < HTMLDivElement > , output : OutputDescriptor | undefined ) : void => this . doHandleContextMenuEvent ( e , output ) ;
122
60
123
- private doHandleOutputClicked ( e : React . MouseEvent < HTMLDivElement > ) {
124
- const index = Number ( e . currentTarget . getAttribute ( 'data-id' ) ) ;
125
- this . setState ( { lastSelectedOutputIndex : index } ) ;
126
- const outputs = this . state . availableOutputDescriptors ;
127
-
128
- if ( outputs && this . _selectedExperiment ) {
129
- signalManager ( ) . fireOutputAddedSignal ( new OutputAddedSignalPayload ( outputs [ index ] , this . _selectedExperiment ) ) ;
61
+ private doHandleOutputClicked ( selectedOutput : OutputDescriptor ) {
62
+ if ( selectedOutput && this . _selectedExperiment ) {
63
+ signalManager ( ) . fireOutputAddedSignal ( new OutputAddedSignalPayload ( selectedOutput , this . _selectedExperiment ) ) ;
130
64
}
131
65
}
132
66
@@ -141,7 +75,7 @@ export class ReactAvailableViewsWidget extends React.Component<ReactAvailableVie
141
75
protected doHandleExperimentSelectedSignal ( experiment : Experiment | undefined ) : void {
142
76
if ( ( this . _selectedExperiment ?. UUID !== experiment ?. UUID ) || this . state . availableOutputDescriptors . length === 0 ) {
143
77
this . _selectedExperiment = experiment ;
144
- this . setState ( { availableOutputDescriptors : [ ] , lastSelectedOutputIndex : - 1 } ) ;
78
+ this . setState ( { availableOutputDescriptors : [ ] } ) ;
145
79
this . updateAvailableViews ( ) ;
146
80
}
147
81
}
0 commit comments