This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #570 from jtpio/backport-pr-9346
Handle multiple scopes
- Loading branch information
Showing
6 changed files
with
224 additions
and
40 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { ReactWidget, UseSignal } from '@jupyterlab/apputils'; | ||
|
||
import { HTMLSelect } from '@jupyterlab/ui-components'; | ||
|
||
import React, { useState } from 'react'; | ||
|
||
import { IDebugger } from '../../tokens'; | ||
|
||
import { VariablesBodyGrid } from './grid'; | ||
|
||
import { VariablesBodyTree } from './tree'; | ||
|
||
/** | ||
* A React component to handle scope changes. | ||
* | ||
* @param {object} props The component props. | ||
* @param props.model The variables model. | ||
* @param props.tree The variables tree widget. | ||
* @param props.grid The variables grid widget. | ||
*/ | ||
const ScopeSwitcherComponent = ({ | ||
model, | ||
tree, | ||
grid | ||
}: { | ||
model: IDebugger.Model.IVariables; | ||
tree: VariablesBodyTree; | ||
grid: VariablesBodyGrid; | ||
}): JSX.Element => { | ||
const [value, setValue] = useState('-'); | ||
const scopes = model.scopes; | ||
|
||
const onChange = (event: React.ChangeEvent<HTMLSelectElement>): void => { | ||
const value = event.target.value; | ||
setValue(value); | ||
tree.scope = value; | ||
grid.scope = value; | ||
}; | ||
|
||
return ( | ||
<HTMLSelect | ||
className={''} | ||
onChange={onChange} | ||
value={value} | ||
aria-label={'Scope'} | ||
> | ||
{scopes.map(scope => ( | ||
<option key={scope.name} value={scope.name}> | ||
{scope.name} | ||
</option> | ||
))} | ||
</HTMLSelect> | ||
); | ||
}; | ||
|
||
/** | ||
* A widget to switch between scopes. | ||
*/ | ||
export class ScopeSwitcher extends ReactWidget { | ||
/** | ||
* Instantiate a new scope switcher. | ||
* | ||
* @param options The instantiation options for a ScopeSwitcher | ||
*/ | ||
constructor(options: ScopeSwitcher.IOptions) { | ||
super(); | ||
const { model, tree, grid } = options; | ||
this._model = model; | ||
this._tree = tree; | ||
this._grid = grid; | ||
} | ||
|
||
/** | ||
* Render the scope switcher. | ||
*/ | ||
render(): JSX.Element { | ||
return ( | ||
<UseSignal signal={this._model.changed} initialSender={this._model}> | ||
{(): JSX.Element => ( | ||
<ScopeSwitcherComponent | ||
model={this._model} | ||
tree={this._tree} | ||
grid={this._grid} | ||
/> | ||
)} | ||
</UseSignal> | ||
); | ||
} | ||
|
||
private _model: IDebugger.Model.IVariables; | ||
private _tree: VariablesBodyTree; | ||
private _grid: VariablesBodyGrid; | ||
} | ||
|
||
/** | ||
* A namespace for ScopeSwitcher statics | ||
*/ | ||
export namespace ScopeSwitcher { | ||
/** | ||
* The ScopeSwitcher instantiation options. | ||
*/ | ||
export interface IOptions { | ||
/** | ||
* The variables model. | ||
*/ | ||
model: IDebugger.Model.IVariables; | ||
|
||
/** | ||
* The variables tree viewer. | ||
*/ | ||
tree: VariablesBodyTree; | ||
|
||
/** | ||
* The variables table viewer. | ||
*/ | ||
grid: VariablesBodyGrid; | ||
} | ||
} |
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
Oops, something went wrong.