1
1
import * as React from 'react' ;
2
2
import '../../style/output-components-style.css' ;
3
3
import { OutputAddedSignalPayload } from 'traceviewer-base/lib/signals/output-added-signal-payload' ;
4
- import { signalManager , Signals } from 'traceviewer-base/lib/signals/signal-manager' ;
4
+ import { signalManager } from 'traceviewer-base/lib/signals/signal-manager' ;
5
5
import { OutputDescriptor , ProviderType } from 'tsp-typescript-client/lib/models/output-descriptor' ;
6
6
import { Experiment } from 'tsp-typescript-client/lib/models/experiment' ;
7
7
import { ITspClientProvider } from 'traceviewer-base/lib/tsp-client-provider' ;
@@ -216,7 +216,7 @@ export class ReactAvailableViewsWidget extends React.Component<ReactAvailableVie
216
216
}
217
217
218
218
private entryToTreeNode ( entry : OutputDescriptor , idStringToNodeId : { [ key : string ] : number } ) : TreeNode {
219
- let id = idStringToNodeId [ entry . id ] ?? ( idStringToNodeId [ entry . id ] = this . _idGenerator ++ ) ;
219
+ const id = idStringToNodeId [ entry . id ] ?? ( idStringToNodeId [ entry . id ] = this . _idGenerator ++ ) ;
220
220
221
221
let parentId = - 1 ;
222
222
if ( entry . parentId ) {
@@ -241,6 +241,7 @@ export class ReactAvailableViewsWidget extends React.Component<ReactAvailableVie
241
241
const isCustomizable = entry . capabilities ?. canCreate === true ;
242
242
const isDeletable = entry . capabilities ?. canDelete === true ;
243
243
244
+ // Return undefined if no relevant capabilities
244
245
if ( ! isCustomizable && ! isDeletable ) {
245
246
return undefined ;
246
247
}
@@ -253,36 +254,42 @@ export class ReactAvailableViewsWidget extends React.Component<ReactAvailableVie
253
254
flexShrink : 1
254
255
} ;
255
256
256
- if ( isCustomizable ) {
257
- return ( ) : JSX . Element => (
258
- < >
259
- < span style = { nameSpanStyle } > { entry . name } </ span >
260
- < div className = "remove-output-button-container" title = { `Add custom analysis to ${ entry . name } ` } >
261
- < button className = "remove-output-button" onClick = { e => this . handleCustomizeClick ( entry , e ) } >
262
- < FontAwesomeIcon icon = { faPlus } />
263
- </ button >
264
- </ div >
265
- </ >
266
- ) ;
267
- } else {
268
- // Must be deletable based on our conditions
269
- return ( ) : JSX . Element => (
257
+ const useCustomizableUI = isCustomizable ;
258
+
259
+ const EnrichedContent = ( ) : JSX . Element => {
260
+ const displayName = useCustomizableUI
261
+ ? entry . name
262
+ : entry . configuration ?. name ;
263
+
264
+ const buttonTitle = useCustomizableUI
265
+ ? `Add custom analysis to ${ displayName } `
266
+ : `Remove "${ displayName } "` ;
267
+
268
+ const icon = useCustomizableUI ? faPlus : faTimes ;
269
+
270
+ const handleClick = useCustomizableUI ?
271
+ ( e : React . MouseEvent ) => this . handleCustomizeClick ( entry , e ) :
272
+ ( e : React . MouseEvent ) => this . handleDeleteClick ( entry , e ) ;
273
+
274
+ return (
270
275
< >
271
- < span style = { nameSpanStyle } > { entry . configuration ?. name } </ span >
272
- < div className = "remove -output-button-container" title = { `Remove " ${ entry . configuration ?. name } "` } >
273
- < button className = "remove -output-button" onClick = { e => this . handleDeleteClick ( entry , e ) } >
274
- < FontAwesomeIcon icon = { faTimes } />
276
+ < span style = { nameSpanStyle } > { displayName } </ span >
277
+ < div className = { 'enriched -output-button-container' } title = { buttonTitle } >
278
+ < button className = { 'enriched -output-button' } onClick = { handleClick } >
279
+ < FontAwesomeIcon icon = { icon } />
275
280
</ button >
276
281
</ div >
277
282
</ >
278
283
) ;
279
- }
284
+ } ;
285
+
286
+ return EnrichedContent ;
280
287
}
281
288
282
289
private handleCustomizeClick = async ( entry : OutputDescriptor , e : React . MouseEvent ) => {
283
290
e . stopPropagation ( ) ;
284
291
if ( this . props . onCustomizationClick && this . _selectedExperiment ) {
285
- await this . props . onCustomizationClick ( entry , this . _selectedExperiment ) ;
292
+ this . props . onCustomizationClick ( entry , this . _selectedExperiment ) ;
286
293
this . updateAvailableViews ( ) ;
287
294
}
288
295
} ;
0 commit comments