-
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.
Add prototype of React Component displaying configurations source types
ADR-0011 introduces the API for managing global configurations. Thus, the Trace Extension needs an interface to expose this API to users. The purpose of this commit is to start creating this UI for the trace extension as a React Component. It provides a skeleton for the component so that it can be further extended in future commits: [1] Added TraceConfigurationManager to handle calls to the TSPClient that relates to trace configuration. [2] Introduce a prototype of the UI as the TraceConfigurationsDialogComponent. This is the main component of the UI that handles the display logic for other sub-components, such as [3]. [3] Added TraceConfigurationListComponent to list the available configuration source types and their instances from the server. To test, open a trace and hover the mouse over the toolbar of the Available Views widget. There should be an icon that appears. Click on the icon to open the trace configuration dialog. In this prototype, the dialog should only display the configuration source types. Signed-off-by: Hoang Thuan Pham <hoang.pham@calian.ca>
- Loading branch information
1 parent
9b5a515
commit b903ecf
Showing
11 changed files
with
272 additions
and
3 deletions.
There are no files selected for viewing
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
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
71 changes: 71 additions & 0 deletions
71
...t-components/src/components/trace-configurations/trace-configuration-dialog-component.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,71 @@ | ||
import React from 'react'; | ||
import { ConfigurationSourceType } from 'tsp-typescript-client/lib/models/configuration-source'; | ||
import { ITspClient } from 'tsp-typescript-client'; | ||
import { TraceConfigurationListComponent } from './trace-configuration-list-component'; | ||
import { TraceConfigurationManager } from './trace-configuration-manager'; | ||
import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-manager'; | ||
|
||
const TRACE_CONFIGURATION_TITLE = 'Trace Configuration'; | ||
|
||
export interface TraceConfigurationVisibility { | ||
list: boolean, | ||
add: boolean | ||
} | ||
|
||
export interface TraceConfigurationsDialogComponentProps { | ||
tspClient: ITspClient | ||
} | ||
export interface TraceConfigurationsDialogComponentState { | ||
visibility: TraceConfigurationVisibility | ||
configurationSourceTypes: ConfigurationSourceType[]; | ||
} | ||
|
||
export class TraceConfigurationsDialogComponent extends React.Component<TraceConfigurationsDialogComponentProps, TraceConfigurationsDialogComponentState> { | ||
private traceConfigurationManager: TraceConfigurationManager; | ||
|
||
constructor(props: TraceConfigurationsDialogComponentProps) { | ||
super(props); | ||
this.traceConfigurationManager = new TraceConfigurationManager(this.props.tspClient); | ||
this.state = { | ||
visibility: { | ||
list: false, | ||
add: false | ||
}, | ||
configurationSourceTypes: [] | ||
}; | ||
|
||
signalManager().on(Signals.SHOW_TRACE_CONFIGURATIONS, this.onOpenListView); | ||
} | ||
|
||
render(): React.ReactElement { | ||
return ( | ||
<React.Fragment> | ||
<TraceConfigurationListComponent | ||
traceConfigurationManager={this.traceConfigurationManager} | ||
title={TRACE_CONFIGURATION_TITLE} | ||
onCloseDialog={this.onCloseListView} | ||
isOpen={this.state.visibility.list}></TraceConfigurationListComponent> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
protected onCloseListView = (): void => { | ||
this.updateVisibility({ | ||
list: false, | ||
add: false, | ||
}); | ||
}; | ||
|
||
protected onOpenListView = (): void => { | ||
this.updateVisibility({ | ||
list: true, | ||
add: false, | ||
}); | ||
}; | ||
|
||
private updateVisibility(visibility: TraceConfigurationVisibility): void { | ||
this.setState({ | ||
visibility: visibility | ||
}); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...act-components/src/components/trace-configurations/trace-configuration-list-component.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,94 @@ | ||
|
||
import { ReactElement } from 'react'; | ||
import React from 'react'; | ||
import { ConfigurationSourceType } from 'tsp-typescript-client/lib/models/configuration-source'; | ||
import { AutoSizer, List, ListRowProps } from 'react-virtualized'; | ||
import { AbstractDialogComponent, DialogComponentProps } from '../abstract-dialog-component'; | ||
import { TraceConfigurationManager } from './trace-configuration-manager'; | ||
|
||
export interface TraceConfigurationListComponentProps extends DialogComponentProps { | ||
traceConfigurationManager: TraceConfigurationManager | ||
} | ||
|
||
export interface TraceConfigurationListComponentState { | ||
configurationSourceTypes: ConfigurationSourceType[]; | ||
} | ||
|
||
export class TraceConfigurationListComponent extends AbstractDialogComponent< | ||
TraceConfigurationListComponentProps, | ||
TraceConfigurationListComponentState> { | ||
private _forceUpdateKey = false; | ||
private readonly TRACE_CONFIGURATIONS_ROW_HEIGHT = 20; | ||
|
||
protected renderFooter(): ReactElement { | ||
return ( | ||
<div> | ||
</div> | ||
); | ||
} | ||
|
||
constructor(props: TraceConfigurationListComponentProps) { | ||
super(props); | ||
this.state = { | ||
configurationSourceTypes: [] | ||
}; | ||
} | ||
|
||
protected onAfterOpen(): void { | ||
this.props.traceConfigurationManager.getConfigurationSourceTypes().then(result => { | ||
if (result !== undefined) { | ||
this.setState({ | ||
configurationSourceTypes: result | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
protected renderDialogBody(): React.ReactElement { | ||
this._forceUpdateKey = !this._forceUpdateKey; | ||
const key = Number(this._forceUpdateKey); | ||
let outputsRowCount = 0; | ||
const outputs = this.state.configurationSourceTypes; | ||
if (outputs) { | ||
outputsRowCount = outputs.length; | ||
} | ||
const totalHeight = 400; // TODO: Change this value once styling is applied | ||
return ( | ||
<div> | ||
List of configurations | ||
<AutoSizer> | ||
{({ width }) => ( | ||
<List | ||
key={key} | ||
height={totalHeight} | ||
width={width} | ||
rowCount={outputsRowCount} | ||
rowHeight={this.TRACE_CONFIGURATIONS_ROW_HEIGHT} | ||
rowRenderer={this.renderRowOutputs} | ||
/> | ||
)} | ||
</AutoSizer> | ||
</div> | ||
); | ||
} | ||
|
||
protected renderRowOutputs = (props: ListRowProps): React.ReactNode => this.doRenderRowOutputs(props); | ||
|
||
private doRenderRowOutputs(props: ListRowProps): React.ReactNode { | ||
let outputName = ''; | ||
let output: ConfigurationSourceType | undefined; | ||
const configurationSourceTypes = this.state.configurationSourceTypes; | ||
if (configurationSourceTypes && configurationSourceTypes.length && props.index < configurationSourceTypes.length) { | ||
output = configurationSourceTypes[props.index]; | ||
outputName = output.name; | ||
} | ||
|
||
return ( | ||
<div> | ||
<div style={{width: '100%'}}> | ||
<h4 className="outputs-element-name">{outputName}</h4> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/react-components/src/components/trace-configurations/trace-configuration-manager.ts
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,22 @@ | ||
import { ITspClient } from 'tsp-typescript-client'; | ||
import { ConfigurationSourceType } from 'tsp-typescript-client/lib/models/configuration-source'; | ||
|
||
export class TraceConfigurationManager { | ||
private tspClient: ITspClient; | ||
|
||
constructor(tspClient: ITspClient) { | ||
this.tspClient = tspClient; | ||
} | ||
|
||
/** | ||
* Get an array of OutputDescriptor for a given experiment | ||
* @param experimentUUID experiment UUID | ||
*/ | ||
async getConfigurationSourceTypes(): Promise<ConfigurationSourceType[] | undefined> { | ||
const outputsResponse = await this.tspClient.fetchConfigurationSourceTypes(); | ||
if (outputsResponse && outputsResponse.isOk()) { | ||
return outputsResponse.getModel(); | ||
} | ||
return undefined; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...act-components/src/components/trace-configurations/trace-configurations-add-component.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,30 @@ | ||
|
||
import { ReactElement } from 'react'; | ||
import React from 'react'; | ||
import { AbstractDialogComponent, DialogComponentProps } from '../abstract-dialog-component'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface TraceConfigurationsAddDialogComponentState { | ||
} | ||
|
||
export class TraceConfigurationsAddDialogComponent extends AbstractDialogComponent<DialogComponentProps, TraceConfigurationsAddDialogComponentState> { | ||
protected renderFooter(): ReactElement { | ||
return ( | ||
<div> | ||
<button>Add</button> | ||
</div> | ||
); | ||
} | ||
|
||
constructor(props: DialogComponentProps) { | ||
super(props); | ||
} | ||
|
||
protected renderDialogBody(): React.ReactElement { | ||
return ( | ||
<div> | ||
Add configurations | ||
</div> | ||
); | ||
} | ||
} |
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
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
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
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
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