From bbe20f700d875ecada2a193dacb688940105780c Mon Sep 17 00:00:00 2001 From: Eric Charles Date: Fri, 6 Oct 2023 17:09:04 +0200 Subject: [PATCH] chore: jupyterlab restorer --- .yarnrc.yml | 1 + src/Datalayer.tsx | 2 +- src/DatalayerJupyterLabHeadless.tsx | 14 +++++++------- src/jupyterlab/index.ts | 2 +- src/state/{zustand.ts => index.ts} | 4 +++- src/tabs/JupyterLabTab.tsx | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) rename src/state/{zustand.ts => index.ts} (63%) diff --git a/.yarnrc.yml b/.yarnrc.yml index 05fb818..7126b6d 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -7,6 +7,7 @@ enableTelemetry: false httpTimeout: 60000 nodeLinker: node-modules npmRegistryServer: "https://registry.yarnpkg.com" +checksumBehavior: update # This will fix the build error with @lerna/legacy-package-management # See https://github.com/lerna/repro/pull/11 diff --git a/src/Datalayer.tsx b/src/Datalayer.tsx index a424421..a7cac10 100644 --- a/src/Datalayer.tsx +++ b/src/Datalayer.tsx @@ -6,7 +6,7 @@ import { DatalayerGreenPaddingIcon, JupyterLabIcon } from '@datalayer/icons-reac import AboutTab from './tabs/AboutTab'; import JupyterLabTab from './tabs/JupyterLabTab'; import { requestAPI } from './jupyterlab/handler'; -import useStore from './state/zustand'; +import useStore from './state'; export type DatalayerProps = { jupyterFrontend?: JupyterFrontEnd; diff --git a/src/DatalayerJupyterLabHeadless.tsx b/src/DatalayerJupyterLabHeadless.tsx index 5827021..e3b9008 100644 --- a/src/DatalayerJupyterLabHeadless.tsx +++ b/src/DatalayerJupyterLabHeadless.tsx @@ -15,19 +15,19 @@ const ThemeGlobalStyle = createGlobalStyle` ` const JupyterLabHeadless = () => { - const [jupyterlab, setJupyterlab] = useState(); - const onReady = (jupyterlabAppAdapter: JupyterLabAppAdapter) => { - setJupyterlab(jupyterlabAppAdapter.jupyterlab); + const [jupyterLab, setJupyterLab] = useState(); + const onJupyterLab = (jupyterLabAppAdapter: JupyterLabAppAdapter) => { + setJupyterLab(jupyterLabAppAdapter.jupyterLab); /* - jupyterlab.deactivatePlugin(datalayerExtension.PLUGIN_ID).then((deactivatedDownstreamPlugins) => { + jupyterLab.deactivatePlugin(datalayerExtension.PLUGIN_ID).then((deactivatedDownstreamPlugins) => { console.log('Deactivated downstream plugins', deactivatedDownstreamPlugins); }); - jupyterlab.deregisterPlugin(datalayerExtension.PLUGIN_ID, true); + jupyterLab.deregisterPlugin(datalayerExtension.PLUGIN_ID, true); */ } return ( <> - {jupyterlab && } + {jupyterLab && } { datalayerExtension, ]} headless={true} - onReady={onReady} + onJupyterLab={onJupyterLab} /> ) diff --git a/src/jupyterlab/index.ts b/src/jupyterlab/index.ts index 6b73fcb..4a04d29 100644 --- a/src/jupyterlab/index.ts +++ b/src/jupyterlab/index.ts @@ -45,12 +45,12 @@ const plugin: JupyterFrontEndPlugin = { restorer?: ILayoutRestorer, ) => { const { commands } = app; + const command = CommandIDs.create; if (!tracker) { tracker = new WidgetTracker>({ namespace: 'datalayer', }); } - const command = CommandIDs.create; if (restorer) { void restorer.restore(tracker, { command, diff --git a/src/state/zustand.ts b/src/state/index.ts similarity index 63% rename from src/state/zustand.ts rename to src/state/index.ts index 0a993dd..5f58c49 100644 --- a/src/state/zustand.ts +++ b/src/state/index.ts @@ -2,11 +2,13 @@ import { create } from 'zustand'; export type ZustandState = { tab: number; + getIntTab: () => number; setTab: (tab: number) => void, } -export const useStore = create((set) => ({ +export const useStore = create((set, get) => ({ tab: 0.0, + getIntTab: () => Math.floor(get().tab), setTab: (tab: number) => set((state: ZustandState) => ({ tab })), })); diff --git a/src/tabs/JupyterLabTab.tsx b/src/tabs/JupyterLabTab.tsx index 105fff0..90db3aa 100644 --- a/src/tabs/JupyterLabTab.tsx +++ b/src/tabs/JupyterLabTab.tsx @@ -13,7 +13,7 @@ import WidgetExtensions from './jupyterlab/WidgetExtensions'; import Settings from './jupyterlab/Settings'; import IPyWidgets from './jupyterlab/IPyWidgets'; import Server from './jupyterlab/Server'; -import useStore from './../state/zustand'; +import useStore from '../state'; const JupyterLabTab = (props: DatalayerProps) => { const { jupyterFrontend } = props;