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,38 @@ 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 ? entry . name : entry . configuration ?. name ;
261
+
262
+ const buttonTitle = useCustomizableUI ? `Add custom analysis to ${ displayName } ` : `Remove " ${ displayName } "` ;
263
+
264
+ const icon = useCustomizableUI ? faPlus : faTimes ;
265
+
266
+ const handleClick = useCustomizableUI
267
+ ? ( e : React . MouseEvent ) => this . handleCustomizeClick ( entry , e )
268
+ : ( e : React . MouseEvent ) => this . handleDeleteClick ( entry , e ) ;
269
+
270
+ return (
270
271
< >
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 } />
272
+ < span style = { nameSpanStyle } > { displayName } </ span >
273
+ < div className = { 'enriched -output-button-container' } title = { buttonTitle } >
274
+ < button className = { 'enriched -output-button' } onClick = { handleClick } >
275
+ < FontAwesomeIcon icon = { icon } />
275
276
</ button >
276
277
</ div >
277
278
</ >
278
279
) ;
279
- }
280
+ } ;
281
+
282
+ return EnrichedContent ;
280
283
}
281
284
282
285
private handleCustomizeClick = async ( entry : OutputDescriptor , e : React . MouseEvent ) => {
283
286
e . stopPropagation ( ) ;
284
287
if ( this . props . onCustomizationClick && this . _selectedExperiment ) {
285
- await this . props . onCustomizationClick ( entry , this . _selectedExperiment ) ;
288
+ this . props . onCustomizationClick ( entry , this . _selectedExperiment ) ;
286
289
this . updateAvailableViews ( ) ;
287
290
}
288
291
} ;
0 commit comments