Skip to content

Commit 652b13f

Browse files
committed
fix: better serrverless, still wip
1 parent f44a529 commit 652b13f

12 files changed

+112
-62
lines changed

packages/react/src/components/filebrowser/FileBrowser.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useState, useEffect, useReducer } from 'react';
88
import { TreeView } from '@primer/react';
99
import { FileIcon } from '@primer/octicons-react';
1010
import { useJupyter } from './../../jupyter/JupyterContext';
11-
import Services from './../../jupyter/services/Services';
11+
import JupyterServices from './../../jupyter/services/JupyterServices';
1212

1313
interface RenderTree {
1414
id: string;
@@ -26,12 +26,12 @@ export const FileBrowser = () => {
2626
const [, forceUpdate] = useReducer(x => x + 1, 0);
2727
const { serviceManager } = useJupyter();
2828
const loadPath = (
29-
services: Services,
29+
services: JupyterServices,
3030
subTree: RenderTree,
3131
path: string[]
3232
) => {
3333
const loadFolderItems = (
34-
services: Services,
34+
services: JupyterServices,
3535
path: string[]
3636
): Promise<RenderTree[]> => {
3737
const folderItems = services
@@ -79,7 +79,7 @@ export const FileBrowser = () => {
7979
};
8080
useEffect(() => {
8181
if (serviceManager) {
82-
const services = new Services(serviceManager);
82+
const services = new JupyterServices(serviceManager);
8383
loadPath(services, initialTree, []);
8484
}
8585
}, [serviceManager]);

packages/react/src/examples/JupyterLabAppHeadlessServeless.tsx renamed to packages/react/src/examples/JupyterLabAppHeadlessServerless.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ const JupyterLabAppHeadlessServerless = () => {
117117
</div>
118118
)}
119119
<JupyterLabApp
120+
headless
120121
serverless
122+
nosplash={false}
121123
plugins={[
122124
lightThemePlugins,
123125
darkThemePlugins,
@@ -127,8 +129,6 @@ const JupyterLabAppHeadlessServerless = () => {
127129
mimeRenderers={[
128130
plotlyMimeRenderers
129131
]}
130-
headless
131-
nosplash={false}
132132
onJupyterLab={onJupyterLab}
133133
pluginId="@jupyterlab/apputils-extension:themes"
134134
PluginType={ThemeManager}

packages/react/src/examples/JupyterLabAppServerless.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const JupyterLabAppSeverless = () => {
2424
return (
2525
<JupyterLabApp
2626
serverless
27+
nosplash={false}
2728
plugins={[
2829
lightThemePlugins,
2930
ipywidgetsPlugins,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2021-2023 Datalayer, Inc.
3+
*
4+
* MIT License
5+
*/
6+
7+
import { useState } from 'react';
8+
import { createRoot } from 'react-dom/client';
9+
import JupyterLabTheme from '../jupyter/lab/JupyterLabTheme';
10+
import JupyterLabApp from '../components/jupyterlab/JupyterLabApp';
11+
import JupyterLabAppAdapter from '../components/jupyterlab/JupyterLabAppAdapter';
12+
import JupyterServiceManagerMock from '../jupyter/services/JupyterServiceManagerMock';
13+
14+
import * as lightThemePlugins from '@jupyterlab/theme-light-extension';
15+
import * as ipywidgetsPlugins from '@jupyter-widgets/jupyterlab-manager';
16+
import * as plotlyPlugins from 'jupyterlab-plotly/lib/jupyterlab-plugin';
17+
import * as reactPlugins from './../jupyter/lab/index';
18+
19+
import * as plotlyMimeRenderers from 'jupyterlab-plotly/lib/plotly-renderer';
20+
21+
const JupyterLabAppServiceManager = () => {
22+
const [serviceManager, _] = useState(new JupyterServiceManagerMock());
23+
const onJupyterLab = async (jupyterLabAdapter: JupyterLabAppAdapter) => {
24+
const jupyterLab = jupyterLabAdapter.jupyterLab;
25+
console.log('JupyterLab is ready', jupyterLab);
26+
};
27+
return (
28+
<JupyterLabApp
29+
serviceManager={serviceManager}
30+
plugins={[
31+
lightThemePlugins,
32+
ipywidgetsPlugins,
33+
plotlyPlugins,
34+
reactPlugins,
35+
]}
36+
mimeRenderers={[
37+
plotlyMimeRenderers
38+
]}
39+
height="calc(100vh - 74px)"
40+
onJupyterLab={onJupyterLab}
41+
/>
42+
);
43+
};
44+
45+
const div = document.createElement('div');
46+
document.body.appendChild(div);
47+
const root = createRoot(div);
48+
49+
root.render(
50+
<JupyterLabTheme>
51+
<h1>JupyterLab Application with Service Manager property</h1>
52+
<JupyterLabAppServiceManager />
53+
</JupyterLabTheme>
54+
);

packages/react/src/jupyter/JupyterContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Kernel as JupyterKernel, ServerConnection, ServiceManager } from '@jupy
99
import type { JupyterLiteServerPlugin } from '@jupyterlite/server';
1010
import { requestAPI } from './JupyterHandlers';
1111
import Kernel from './kernel/Kernel';
12-
import { useJupyterStoreFromContext } from '../state';
12+
import { useJupyterReactStoreFromContext } from '../state';
1313

1414
export type Lite =
1515
| boolean
@@ -194,7 +194,7 @@ export const useJupyter = (props?: JupyterPropsType): JupyterContextType => {
194194
kernelIsLoading,
195195
serviceManager,
196196
jupyterConfig,
197-
} = useJupyterStoreFromContext(props ?? {});
197+
} = useJupyterReactStoreFromContext(props ?? {});
198198
const storeContext: JupyterContextType = {
199199
collaborative: false,
200200
defaultKernel: kernel,

packages/react/src/jupyter/services/ServiceManagerMock.ts renamed to packages/react/src/jupyter/services/JupyterServiceManagerMock.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
* MIT License
55
*/
66

7-
/*
8-
* Copyright (c) 2021-2024 Datalayer, Inc.
9-
*
10-
* Datalayer License
11-
*/
12-
137
import {
148
Builder, Contents, Event, IManager, NbConvert, NbConvertManager,
159
ServerConnection, ServiceManager, Setting, User, Workspace
@@ -39,7 +33,7 @@ export class TerminalManagerMock implements ITerminaManager {
3933
return true;
4034
}
4135
running(): IterableIterator<ISessionModel> {
42-
return [] as unknown as IterableIterator<ISessionModel>;
36+
return [].values();
4337
}
4438
startNew(options?: ITerminal.IOptions | undefined): Promise<ITerminalConnection> {
4539
return Promise.resolve({} as unknown as ITerminalConnection);
@@ -135,7 +129,7 @@ export class KernelsManagerMock implements IKernelManager {
135129
this.serverSettings = serverSettings;
136130
}
137131
running(): IterableIterator<IModel> {
138-
return [] as any;
132+
return [].values();
139133
}
140134
refreshRunning(): Promise<void> {
141135
return new Promise(() => {});
@@ -190,7 +184,7 @@ export class SessionManagerMock implements ISessionManager {
190184
this.serverSettings = serverSettings;
191185
}
192186
running(): IterableIterator<ISessionModel> {
193-
return [] as any;
187+
return [].values();
194188
}
195189
startNew(createOptions: ISessionOptions, connectOptions?: Omit<ISessionConnection.IOptions, 'serverSettings' | 'model' | 'connectToKernel'> | undefined): Promise<ISessionConnection> {
196190
return new Promise(() => {});
@@ -349,33 +343,33 @@ export class JupyterServiceManagerMock implements ServiceManager.IManager {
349343
nbconvert: NbConvert.IManager;
350344
constructor(serverSettings: ServerConnection.ISettings = ServerConnection.makeSettings()) {
351345
this.serverSettings = serverSettings;
346+
this.terminals = new TerminalManagerMock(serverSettings);
347+
this.builder = new BuilderManagerMock(serverSettings) as Builder.IManager;
348+
this.contents = new ContentsManagerMock(serverSettings);
349+
this.events = new EventsManagerMock(serverSettings);
350+
this.sessions = new SessionManagerMock(serverSettings);
351+
this.kernels = new KernelsManagerMock(serverSettings);
352+
this.kernelspecs = new KernelspecManagerMock(serverSettings);
353+
this.settings = new SettingManagerMock(serverSettings)
354+
this.user = new UserManagerMock(serverSettings)
355+
this.workspaces = new WorkspaceManagerMock(serverSettings);
356+
this.nbconvert = new NbConvertManagerMock(serverSettings) as unknown as NbConvert.IManager;
352357
/*
353358
const serviceManager = new ServiceManager({
354359
serverSettings,
355360
})
361+
this.settings = serviceManager.settings;
356362
this.terminals = serviceManager.terminals;
357363
this.builder = serviceManager.builder;
358364
this.contents = serviceManager.contents;
359365
this.events = serviceManager.events;
360366
this.sessions = serviceManager.sessions;
361367
this.kernels = serviceManager.kernels;
362368
this.kernelspecs = serviceManager.kernelspecs;
363-
this.settings = serviceManager.settings;
364369
this.user = serviceManager.user;
365370
this.workspaces = serviceManager.workspaces;
366371
this.nbconvert = serviceManager.nbconvert;
367372
*/
368-
this.terminals = new TerminalManagerMock(serverSettings);
369-
this.builder = new BuilderManagerMock(serverSettings) as Builder.IManager;
370-
this.contents = new ContentsManagerMock(serverSettings);
371-
this.events = new EventsManagerMock(serverSettings);
372-
this.sessions = new SessionManagerMock(serverSettings);
373-
this.kernels = new KernelsManagerMock(serverSettings);
374-
this.kernelspecs = new KernelspecManagerMock(serverSettings);
375-
this.settings = new SettingManagerMock(serverSettings)
376-
this.user = new UserManagerMock(serverSettings)
377-
this.workspaces = new WorkspaceManagerMock(serverSettings);
378-
this.nbconvert = new NbConvertManagerMock(serverSettings) as unknown as NbConvert.IManager;
379373
}
380374
dispose(): void {
381375
}

packages/react/src/jupyter/services/Services.ts renamed to packages/react/src/jupyter/services/JupyterServices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IManager as IKernelspecManager} from '@jupyterlab/services/lib/kernelsp
99
import { IManager as ISessionManager } from '@jupyterlab/services/lib/session/session';
1010
import { IManager as ITerminaManager } from '@jupyterlab/services/lib/terminal/terminal';
1111

12-
export class Services {
12+
export class JupyterServices {
1313
private _serviceManager: ServiceManager.IManager;
1414

1515
public constructor(services: ServiceManager.IManager) {
@@ -61,4 +61,4 @@ export class Services {
6161
}
6262
}
6363

64-
export default Services;
64+
export default JupyterServices;

packages/react/src/jupyter/services/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
* Datalayer License
1111
*/
1212

13-
export * from './Services';
14-
export * from './ServiceManagerMock';
13+
export * from './JupyterServiceManagerMock';
14+
export * from './JupyterServices';

packages/react/src/state/IState.ts renamed to packages/react/src/state/IJupyterReactState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* MIT License
55
*/
66

7-
export type IDatalayerConfig = {
7+
export type IJupyterReactState = {
88
/**
99
* Cloud API URL
1010
*/

0 commit comments

Comments
 (0)