-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a widget for properties view in react-components
Changes made: - Implemented a properties widget in react-components - Change theia implementation to use the widget from react-components This will move the properties widget to the react-components npm package, so it can be used by both the theia extension and vscode extension. Signed-off-by: Neel Gondalia ngondalia@blackberry.com
- Loading branch information
Showing
2 changed files
with
98 additions
and
57 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
packages/react-components/src/trace-explorer/trace-explorer-tooltip-widget.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import * as React from 'react'; | ||
import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-manager'; | ||
|
||
export interface ReactPropertiesWidgetProps { | ||
id: string, | ||
title: string, | ||
handleSourcecodeLookup: (e: React.MouseEvent<HTMLParagraphElement>) => void; | ||
} | ||
|
||
export interface ReactPropertiesWidgetState { | ||
tooltip: { [key: string]: string }; | ||
} | ||
|
||
export class ReactItemPropertiesWidget extends React.Component<ReactPropertiesWidgetProps, ReactPropertiesWidgetState> { | ||
|
||
constructor(props: ReactPropertiesWidgetProps) { | ||
super(props); | ||
this.state = { | ||
tooltip: {} | ||
}; | ||
signalManager().on(Signals.TOOLTIP_UPDATED, this._onTooltip); | ||
} | ||
|
||
componentWillUnmount(): void { | ||
signalManager().off(Signals.TOOLTIP_UPDATED, this._onTooltip); | ||
} | ||
|
||
render(): React.ReactNode { | ||
return ( | ||
<div className='trace-explorer-tooltip'> | ||
<div className='trace-explorer-panel-content'> | ||
{this.renderTooltip()} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
private renderTooltip() { | ||
const tooltipArray: JSX.Element[] = []; | ||
if (this.state.tooltip) { | ||
Object.entries(this.state.tooltip).forEach(([key, value]) => { | ||
if (key === 'Source') { | ||
const sourceCodeInfo = value; | ||
const matches = sourceCodeInfo.match('(.*):(\\d+)'); | ||
let fileLocation; | ||
let line; | ||
if (matches && matches.length === 3) { | ||
fileLocation = matches[1]; | ||
line = matches[2]; | ||
} | ||
tooltipArray.push(<p className='source-code-tooltip' | ||
key={key} | ||
onClick={this.props.handleSourcecodeLookup} | ||
data-id={JSON.stringify({ fileLocation, line })} | ||
>{key + ': ' + sourceCodeInfo}</p>); | ||
} else { | ||
tooltipArray.push(<p key={key}>{key + ': ' + value}</p>); | ||
} | ||
}); | ||
} else { | ||
tooltipArray.push(<p key="-1"><i>Select item to view properties</i></p>); | ||
} | ||
|
||
return ( | ||
<React.Fragment> | ||
{tooltipArray.map(element => element)} | ||
</React.Fragment>); | ||
} | ||
|
||
/** Tooltip Signal and Signal Handlers */ | ||
protected _onTooltip = (tooltip: { [key: string]: string }): void => this.doHandleTooltipSignal(tooltip); | ||
|
||
private doHandleTooltipSignal(tooltipProps: { [key: string]: string }): void { | ||
this.setState({tooltip: tooltipProps}); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters