Skip to content

Commit

Permalink
chore: mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
echarles committed Oct 6, 2024
1 parent 5e1bf5f commit 65d43cc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
18 changes: 11 additions & 7 deletions packages/react/src/components/notebook/Notebook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,18 @@ export const Notebook = (props: INotebookProps) => {
}
// Mutation Effects.
useEffect(() => {
if (!adapter && serviceManager) {
createAdapter(serviceManager);
}
else if (adapter && serviceManager) {
setFlipflop(false);
setAdapter(undefined);
if (serviceManager) {
if (kernel || serverless) {
if (!adapter) {
createAdapter(serviceManager);
}
else if (adapter) {
setFlipflop(false);
setAdapter(undefined);
}
}
}
}, [serviceManager]);
}, [serviceManager, kernel]);
useEffect(() => {
if (!flipflop) {
setFlipflop(true);
Expand Down
35 changes: 20 additions & 15 deletions packages/react/src/examples/NotebookMutations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,34 @@ import nb from './notebooks/NotebookExample1.ipynb.json';
const NOTEBOOK_ID = 'notebook-mutations-id';

loadJupyterConfig({});
// const SERVICE_MANAGER = new ServiceManagerLess();
const serverSettings = createServerSettings(getJupyterServerUrl(), getJupyterServerToken());
const SERVICE_MANAGER = new ServiceManager({ serverSettings });
// const serverSettings = createServerSettings(getJupyterServerUrl(), getJupyterServerToken());
// const SERVICE_MANAGER = new ServiceManager({ serverSettings });
const SERVICE_MANAGER = new ServiceManagerLess();

const NotebookMutations = () => {
const [index, setIndex] = useState(2);
const [index, setIndex] = useState(0);
const [nbformat, setNbformat] = useState(nb as INotebookContent);
const [readonly, setReadonly] = useState(true);
const [serverless, setServerless] = useState(true);
const [lite, setLite] = useState(false);
const [serviceManager, setServiceManager] = useState<ServiceManager.IManager>(SERVICE_MANAGER);
const notebookStore = useNotebookStore();
const adapter = notebookStore.selectNotebookAdapter(NOTEBOOK_ID);
const notebook = notebookStore.selectNotebook(NOTEBOOK_ID);
const changeIndex = (index: number) => {
setIndex(index);
switch(index) {
case 0: {
setNbformat(adapter?.nbformat!);
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON() as INotebookContent);
setServerless(true);
setReadonly(true);
setLite(false);
const serviceManager = new ServiceManagerLess();
setServiceManager(serviceManager);
break;
}
case 1: {
setNbformat(adapter?.nbformat!);
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON() as INotebookContent);
setServerless(false);
setReadonly(false);
setLite(true);
createServiceManagerLite().then(listServiceManager => {
Expand All @@ -52,7 +55,8 @@ const NotebookMutations = () => {
break;
}
case 2: {
setNbformat(adapter?.nbformat!);
setNbformat(notebook?.adapter?.notebookPanel?.content.model?.toJSON() as INotebookContent);
setServerless(false);
setReadonly(false);
setLite(false);
const serverSettings = createServerSettings(getJupyterServerUrl(), getJupyterServerToken());
Expand All @@ -75,13 +79,13 @@ const NotebookMutations = () => {
</SegmentedControl>
</Box>
<Box ml={1} mt={1}>
<Label>Readonly: {String(adapter?.readonly)}</Label>
<Label>Serverless: {String(adapter?.serverless)}</Label>
<Label>Lite: {String(adapter?.lite)}</Label>
<Label>Service Manager URL: {adapter?.serviceManager.serverSettings.baseUrl}</Label>
<Label>Service Manager is ready: {String(adapter?.serviceManager.isReady)}</Label>
<Label>Kernel ID: {adapter?.kernel?.id}</Label>
<Label>Kernel Banner: {adapter?.kernel?.info?.banner}</Label>
<Label>Readonly: {String(notebook?.adapter?.readonly)}</Label>
<Label>Serverless: {String(notebook?.adapter?.serverless)}</Label>
<Label>Lite: {String(notebook?.adapter?.lite)}</Label>
<Label>Service Manager URL: {notebook?.adapter?.serviceManager.serverSettings.baseUrl}</Label>
<Label>Service Manager is ready: {String(notebook?.adapter?.serviceManager.isReady)}</Label>
<Label>Kernel ID: {notebook?.adapter?.kernel?.id}</Label>
<Label>Kernel Banner: {notebook?.adapter?.kernel?.info?.banner}</Label>
</Box>
</Box>
<Notebook
Expand All @@ -90,6 +94,7 @@ const NotebookMutations = () => {
lite={lite}
nbformat={nbformat as INotebookContent}
readonly={readonly}
serverless={serverless}
serviceManager={serviceManager}
/>
</JupyterReactTheme>
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/jupyter/kernel/Kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ export class Kernel {
toString() {
return `id:${this.id} - client_id:${this.clientId} - session_id:${this.sessionId} - path:${this._path}`;
}

}

export namespace Kernel {
Expand Down
4 changes: 2 additions & 2 deletions packages/react/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const ENTRY =
// './src/examples/Kernels';
// './src/examples/Lumino';
// './src/examples/Matplotlib';
'./src/examples/Notebook';
// './src/examples/Notebook';
// './src/examples/NotebookURL';
// './src/examples/NotebookColorMode';
// './src/examples/NotebookKernelChange';
// './src/examples/NotebookLite';
// './src/examples/NotebookMutations';
'./src/examples/NotebookMutations';
// './src/examples/NotebookNbformat';
// './src/examples/NotebookNbformatChange';
// './src/examples/NotebookNoContext';
Expand Down

0 comments on commit 65d43cc

Please sign in to comment.