|
1 | | -import React from 'react'; |
2 | | -import { ReactWidget } from '@jupyterlab/ui-components'; |
3 | | -import { pluginIcon } from '../icons/pluginIcon'; |
| 1 | +// src/components/variableInspectorSidebarWidget.tsx |
| 2 | +import React from 'react' |
| 3 | +import { ReactWidget } from '@jupyterlab/ui-components' |
| 4 | +import { Message } from '@lumino/messaging' |
| 5 | +import { pluginIcon } from '../icons/pluginIcon' |
4 | 6 | import { NotebookWatcher } from '../watchers/notebookWatcher' |
5 | | -import { NotebookPanelContextProvider } from '../context/notebookPanelContext'; |
6 | | -import { CommandRegistry } from '@lumino/commands'; |
7 | | -import { VariableListComponent } from './variableListComponent'; |
8 | | -import { NotebookKernelContextProvider } from '../context/notebookKernelContext'; |
9 | | -import { VariableContextProvider } from '../context/notebookVariableContext'; |
| 7 | +import { CommandRegistry } from '@lumino/commands' |
| 8 | +import { NotebookPanelContextProvider } from '../context/notebookPanelContext' |
| 9 | +import { NotebookKernelContextProvider } from '../context/notebookKernelContext' |
| 10 | +import { VariableContextProvider } from '../context/notebookVariableContext' |
| 11 | +import { VariableListComponent } from './variableListComponent' |
| 12 | +import { PluginVisibilityContextValue, PluginVisibilityContext } from '../context/pluginVisibilityContext' |
| 13 | +import { KernelIdleWatcherContextProvider } from '../context/kernelStatusContext' |
10 | 14 |
|
| 15 | +export class VariableInspectorSidebarWidget extends ReactWidget { |
| 16 | + private notebookWatcher: NotebookWatcher |
| 17 | + private commands: CommandRegistry |
| 18 | + private isOpen = false |
11 | 19 |
|
12 | | -class VariableInspectorSidebarWidget extends ReactWidget { |
13 | | - private notebookWatcher: NotebookWatcher; |
14 | | - private commands: CommandRegistry; |
15 | | - constructor(notebookWatcher:NotebookWatcher, commands: CommandRegistry) { |
16 | | - super(); |
17 | | - this.notebookWatcher = notebookWatcher; |
18 | | - this.commands = commands; |
19 | | - this.id = 'my-plugin::empty-sidebar'; |
20 | | - this.title.icon = pluginIcon; |
21 | | - this.title.caption ='My Plugin'; |
22 | | - this.addClass('my-plugin-sidebar-widget'); |
| 20 | + constructor(notebookWatcher: NotebookWatcher, commands: CommandRegistry) { |
| 21 | + super() |
| 22 | + this.notebookWatcher = notebookWatcher |
| 23 | + this.commands = commands |
| 24 | + this.id = 'my-plugin::empty-sidebar' |
| 25 | + this.title.icon = pluginIcon |
| 26 | + this.title.caption = 'My Plugin' |
| 27 | + this.addClass('mljar-plugin-sidebar-widget') |
| 28 | + } |
| 29 | + |
| 30 | + protected onAfterShow(msg: Message): void { |
| 31 | + super.onAfterShow(msg) |
| 32 | + this.isOpen = true |
| 33 | + this.update() |
| 34 | + } |
| 35 | + |
| 36 | + protected onAfterHide(msg: Message): void { |
| 37 | + super.onAfterHide(msg) |
| 38 | + this.isOpen = false |
| 39 | + this.update() |
23 | 40 | } |
24 | 41 |
|
25 | 42 | render(): JSX.Element { |
| 43 | + const contextValue: PluginVisibilityContextValue = { |
| 44 | + isPluginOpen: this.isOpen, |
| 45 | + setPluginOpen: open => { |
| 46 | + this.isOpen = open |
| 47 | + this.update() |
| 48 | + } |
| 49 | + } |
26 | 50 | return ( |
27 | | - <div |
28 | | - className='mljar-sidebar-container' |
29 | | - > |
30 | | - |
| 51 | + <PluginVisibilityContext.Provider value={contextValue}> |
31 | 52 | <NotebookPanelContextProvider notebookWatcher={this.notebookWatcher}> |
32 | 53 | <NotebookKernelContextProvider notebookWatcher={this.notebookWatcher}> |
33 | | - <VariableContextProvider> |
34 | | - <VariableListComponent/> |
35 | | - <button |
36 | | - onClick={() => this.commands.execute('custom:open-variable-inspector')} |
37 | | - > |
38 | | - Hello |
39 | | - </button> |
| 54 | + <VariableContextProvider> |
| 55 | + <KernelIdleWatcherContextProvider> |
| 56 | + <VariableListComponent /> |
| 57 | + |
| 58 | + <button onClick={() => this.commands.execute('custom:open-variable-inspector')}> |
| 59 | + Hello |
| 60 | + </button> |
| 61 | + </KernelIdleWatcherContextProvider> |
40 | 62 | </VariableContextProvider> |
41 | 63 | </NotebookKernelContextProvider> |
42 | 64 | </NotebookPanelContextProvider> |
43 | | - </div> |
44 | | - ); |
| 65 | + </PluginVisibilityContext.Provider> |
| 66 | + ) |
45 | 67 | } |
46 | 68 | } |
47 | 69 |
|
48 | 70 | export function createVariableInspectorSidebar(notebookWatcher: NotebookWatcher, commands: CommandRegistry): VariableInspectorSidebarWidget { |
49 | | - return new VariableInspectorSidebarWidget(notebookWatcher, commands); |
| 71 | + return new VariableInspectorSidebarWidget(notebookWatcher, commands) |
50 | 72 | } |
51 | | - |
52 | | - |
|
0 commit comments