variableTableDescription.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { ReactWidget } from '@jupyterlab/apputils';
  4. import { ArrayExt } from '@phosphor/algorithm';
  5. import { SplitPanel, Widget } from '@phosphor/widgets';
  6. import React, { useState } from 'react';
  7. import { IVariablesModel } from '../model';
  8. import useTbody from './useTbody';
  9. const ROW_CLASS = 'jp-DebuggerSidebarVariables-table-row';
  10. const HEAD_CLASS = 'jp-DebuggerSidebarVariables-table-head';
  11. const Table = ({ model }: { model: IVariablesModel }) => {
  12. const [variables, setVariables] = useState(model.variables);
  13. const [variable, TableBody] = useTbody(variables, model.current, ROW_CLASS);
  14. model.variablesChanged.connect((_: any, updates) => {
  15. if (ArrayExt.shallowEqual(variables, updates)) {
  16. return;
  17. }
  18. setVariables(updates);
  19. });
  20. model.current = variable;
  21. return (
  22. <table>
  23. <thead>
  24. <tr>
  25. <th style={{ width: '25%' }} className={HEAD_CLASS}>
  26. Name
  27. </th>
  28. <th style={{ width: '75%' }} className={HEAD_CLASS}>
  29. Value
  30. </th>
  31. </tr>
  32. </thead>
  33. <TableBody />
  34. </table>
  35. );
  36. };
  37. class TableVariableWidget extends ReactWidget {
  38. state: IVariablesModel;
  39. constructor(props: any) {
  40. super(props);
  41. this.state = props;
  42. }
  43. render() {
  44. return <Table model={this.state} />;
  45. }
  46. }
  47. export class VariableTableDescription extends SplitPanel {
  48. private _model: IVariablesModel;
  49. constructor(model: IVariablesModel) {
  50. super();
  51. this._model = model;
  52. const myWidget: Widget = new TableVariableWidget(this._model);
  53. this.addWidget(myWidget);
  54. }
  55. }