Skip to content

Commit

Permalink
chore: jupyterlab restorer
Browse files Browse the repository at this point in the history
  • Loading branch information
echarles committed Oct 6, 2023
1 parent 75d422c commit bbe20f7
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Datalayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/DatalayerJupyterLabHeadless.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ const ThemeGlobalStyle = createGlobalStyle<any>`
`

const JupyterLabHeadless = () => {
const [jupyterlab, setJupyterlab] = useState<JupyterLab>();
const onReady = (jupyterlabAppAdapter: JupyterLabAppAdapter) => {
setJupyterlab(jupyterlabAppAdapter.jupyterlab);
const [jupyterLab, setJupyterLab] = useState<JupyterLab>();
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 && <Datalayer jupyterFrontend={jupyterlab}/>}
{jupyterLab && <Datalayer jupyterFrontend={jupyterLab}/>}
<JupyterLabApp
extensions={[
lightThemeExtension,
collaborationExtension,
datalayerExtension,
]}
headless={true}
onReady={onReady}
onJupyterLab={onJupyterLab}
/>
</>
)
Expand Down
2 changes: 1 addition & 1 deletion src/jupyterlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ const plugin: JupyterFrontEndPlugin<void> = {
restorer?: ILayoutRestorer,
) => {
const { commands } = app;
const command = CommandIDs.create;
if (!tracker) {
tracker = new WidgetTracker<MainAreaWidget<DatalayerWidget>>({
namespace: 'datalayer',
});
}
const command = CommandIDs.create;
if (restorer) {
void restorer.restore(tracker, {
command,
Expand Down
4 changes: 3 additions & 1 deletion src/state/zustand.ts → src/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { create } from 'zustand';

export type ZustandState = {
tab: number;
getIntTab: () => number;
setTab: (tab: number) => void,
}

export const useStore = create<ZustandState>((set) => ({
export const useStore = create<ZustandState>((set, get) => ({
tab: 0.0,
getIntTab: () => Math.floor(get().tab),
setTab: (tab: number) => set((state: ZustandState) => ({ tab })),
}));

Expand Down
2 changes: 1 addition & 1 deletion src/tabs/JupyterLabTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bbe20f7

Please sign in to comment.