github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/runners/interactive/extensions/apache-beam-jupyterlab-sidepanel/src/index.ts (about) 1 // Licensed under the Apache License, Version 2.0 (the 'License'); you may not 2 // use this file except in compliance with the License. You may obtain a copy of 3 // the License at 4 // 5 // http://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT 9 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 // License for the specific language governing permissions and limitations under 11 // the License. 12 13 import { 14 JupyterFrontEnd, 15 JupyterFrontEndPlugin 16 } from '@jupyterlab/application'; 17 import { ICommandPalette } from '@jupyterlab/apputils'; 18 import { ILauncher } from '@jupyterlab/launcher'; 19 import { IMainMenu } from '@jupyterlab/mainmenu'; 20 import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; 21 import { Menu } from '@lumino/widgets'; 22 23 import { ClustersWidget } from './clusters/ClustersWidget'; 24 import { SessionContext } from '@jupyterlab/apputils'; 25 import { SidePanel } from './SidePanel'; 26 27 // prettier-ignore 28 import { 29 InteractiveInspectorWidget 30 } from './inspector/InteractiveInspectorWidget'; 31 32 namespace CommandIDs { 33 export const open_inspector = 34 'apache-beam-jupyterlab-sidepanel:open_inspector'; 35 export const open_clusters_panel = 36 'apache-beam-jupyterlab-sidepanel:open_clusters_panel'; 37 } 38 39 /** 40 * Initialization data for the apache-beam-jupyterlab-sidepanel extension. 41 * 42 * There are two user interfaces that use the JupyterLab sidepanel. There is 43 * the Interactive Inspector, and the Cluster Management side panel. 44 * 45 * To open the main user interface of the side panel, a user can: 46 * 1. Select either the `Open Inspector` or `Manage Clusters` item from 47 * the `Interactive Beam` category on the launcher page of JupyterLab. 48 * 2. Same selection from the `Commands` palette on the left side of the 49 * workspace. 50 * 3. Same selection from the top menu bar of the workspace. 51 */ 52 const extension: JupyterFrontEndPlugin<void> = { 53 id: 'apache-beam-jupyterlab-sidepanel', 54 autoStart: true, 55 optional: [ILauncher], 56 requires: [ICommandPalette, IMainMenu, IRenderMimeRegistry], 57 activate: activate 58 }; 59 60 function activate( 61 app: JupyterFrontEnd, 62 palette: ICommandPalette, 63 mainMenu: IMainMenu, 64 rendermime: IRenderMimeRegistry, 65 launcher: ILauncher | null 66 ): void { 67 const category = 'Interactive Beam'; 68 const inspectorCommandLabel = 'Open Inspector'; 69 const clustersCommandLabel = 'Manage Clusters'; 70 const { commands, shell, serviceManager } = app; 71 72 async function createInspectorPanel(): Promise<SidePanel> { 73 const sessionContext = new SessionContext({ 74 sessionManager: serviceManager.sessions, 75 specsManager: serviceManager.kernelspecs, 76 name: 'Interactive Beam Inspector Session' 77 }); 78 const inspector = new InteractiveInspectorWidget(sessionContext); 79 const panel = new SidePanel( 80 serviceManager, 81 rendermime, 82 sessionContext, 83 'Interactive Beam Inspector', 84 inspector 85 ); 86 activatePanel(panel); 87 return panel; 88 } 89 90 async function createClustersPanel(): Promise<SidePanel> { 91 const sessionContext = new SessionContext({ 92 sessionManager: serviceManager.sessions, 93 specsManager: serviceManager.kernelspecs, 94 name: 'Interactive Beam Clusters Session' 95 }); 96 const clusters = new ClustersWidget(sessionContext); 97 const panel = new SidePanel( 98 serviceManager, 99 rendermime, 100 sessionContext, 101 'Interactive Beam Cluster Manager', 102 clusters 103 ); 104 activatePanel(panel); 105 return panel; 106 } 107 108 function activatePanel(panel: SidePanel): void { 109 shell.add(panel, 'main'); 110 shell.activateById(panel.id); 111 } 112 113 // The open_inspector command is used by all 3 below entry points. 114 commands.addCommand(CommandIDs.open_inspector, { 115 label: inspectorCommandLabel, 116 execute: createInspectorPanel 117 }); 118 119 // The open_clusters_panel command is also used by the below entry points. 120 commands.addCommand(CommandIDs.open_clusters_panel, { 121 label: clustersCommandLabel, 122 execute: createClustersPanel 123 }); 124 125 // Entry point in launcher. 126 if (launcher) { 127 launcher.add({ 128 command: CommandIDs.open_inspector, 129 category: category 130 }); 131 launcher.add({ 132 command: CommandIDs.open_clusters_panel, 133 category: category 134 }); 135 } 136 137 // Entry point in top menu. 138 const menu = new Menu({ commands }); 139 menu.title.label = 'Interactive Beam'; 140 mainMenu.addMenu(menu); 141 menu.addItem({ command: CommandIDs.open_inspector }); 142 menu.addItem({ command: CommandIDs.open_clusters_panel }); 143 144 // Entry point in commands palette. 145 palette.addItem({ command: CommandIDs.open_inspector, category }); 146 palette.addItem({ command: CommandIDs.open_clusters_panel, category }); 147 } 148 149 export default extension;