-
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 818a14b
Showing
10 changed files
with
233 additions
and
4 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
67 changes: 67 additions & 0 deletions
67
...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,67 @@ | ||
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 { AbstractDialogComponent, DialogComponentProps } from '../abstract-dialog-component'; | ||
|
||
export interface TraceConfigurationVisibility { | ||
list: boolean; | ||
add: boolean; | ||
} | ||
|
||
export interface TraceConfigurationsDialogComponentProps extends DialogComponentProps { | ||
tspClient: ITspClient; | ||
} | ||
export interface TraceConfigurationsDialogComponentState { | ||
visibility: TraceConfigurationVisibility; | ||
configurationSourceTypes: ConfigurationSourceType[]; | ||
} | ||
|
||
export class TraceConfigurationsDialogComponent extends AbstractDialogComponent< | ||
TraceConfigurationsDialogComponentProps, | ||
TraceConfigurationsDialogComponentState | ||
> { | ||
protected renderDialogBody(): React.ReactElement { | ||
return ( | ||
<React.Fragment> | ||
<TraceConfigurationListComponent | ||
traceConfigurationManager={this.traceConfigurationManager} | ||
configurationSourceTypes={this.state.configurationSourceTypes} | ||
></TraceConfigurationListComponent> | ||
</React.Fragment> | ||
); | ||
} | ||
protected renderFooter(): React.ReactElement { | ||
return <React.Fragment></React.Fragment>; | ||
} | ||
private traceConfigurationManager: TraceConfigurationManager; | ||
|
||
constructor(props: TraceConfigurationsDialogComponentProps) { | ||
super(props); | ||
this.traceConfigurationManager = new TraceConfigurationManager(this.props.tspClient); | ||
this.state = { | ||
visibility: { | ||
list: false, | ||
add: false | ||
}, | ||
configurationSourceTypes: [] | ||
}; | ||
} | ||
|
||
protected onAfterOpen(): void { | ||
this.traceConfigurationManager.getConfigurationSourceTypes().then(result => { | ||
if (result !== undefined) { | ||
this.setState({ | ||
configurationSourceTypes: result | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
private updateVisibility(visibility: TraceConfigurationVisibility): void { | ||
this.setState({ | ||
visibility: visibility | ||
}); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...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,70 @@ | ||
import React from 'react'; | ||
import { ConfigurationSourceType } from 'tsp-typescript-client/lib/models/configuration-source'; | ||
import { AutoSizer, List, ListRowProps } from 'react-virtualized'; | ||
import { TraceConfigurationManager } from './trace-configuration-manager'; | ||
|
||
export interface TraceConfigurationListComponentProps { | ||
traceConfigurationManager: TraceConfigurationManager; | ||
configurationSourceTypes: ConfigurationSourceType[]; | ||
} | ||
|
||
export class TraceConfigurationListComponent extends React.Component<TraceConfigurationListComponentProps> { | ||
private _forceUpdateKey = false; | ||
private readonly TRACE_CONFIGURATIONS_ROW_HEIGHT = 20; | ||
|
||
constructor(props: TraceConfigurationListComponentProps) { | ||
super(props); | ||
} | ||
|
||
render(): React.ReactElement { | ||
this._forceUpdateKey = !this._forceUpdateKey; | ||
const key = Number(this._forceUpdateKey); | ||
let outputsRowCount = 0; | ||
const outputs = this.props.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.props.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; | ||
} | ||
} |
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