-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1505 from orchest/feat/auto-save-jupyterlab-config
Auto save Jupyterlab setup script
- Loading branch information
Showing
13 changed files
with
280 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...ces/orchest-webserver/client/src/api/jupyter-lab-setup-script/jupyterLabSetupScriptApi.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { fetcher } from "@orchest/lib-utils"; | ||
|
||
export const JUPYTER_LAB_SETUP_SCRIPT_API_URL = "/async/jupyter-setup-script"; | ||
|
||
/** Fetches the setup script of JupyterLab */ | ||
export const fetchOne = () => | ||
fetcher<{ script: string }>(JUPYTER_LAB_SETUP_SCRIPT_API_URL).then( | ||
(response) => response.script | ||
); | ||
|
||
/** Update JupyterLab setup script */ | ||
export const update = (payload: string) => { | ||
const formData = new FormData(); | ||
formData.append("setup_script", payload); | ||
return fetcher<void>(JUPYTER_LAB_SETUP_SCRIPT_API_URL, { | ||
method: "POST", | ||
body: formData, | ||
}); | ||
}; | ||
|
||
export const jupyterLabSetupScriptApi = { | ||
fetchOne, | ||
update, | ||
}; |
25 changes: 25 additions & 0 deletions
25
.../orchest-webserver/client/src/api/jupyter-lab-setup-script/useJupyterLabSetupScriptApi.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import create from "zustand"; | ||
import { jupyterLabSetupScriptApi } from "./jupyterLabSetupScriptApi"; | ||
|
||
export type JupyterLabSetupScriptApi = { | ||
setupScript: string | undefined; | ||
fetch: () => Promise<string>; | ||
update: (payload: string) => Promise<void>; | ||
}; | ||
|
||
export const useJupyterLabSetupScriptApi = create<JupyterLabSetupScriptApi>( | ||
(set) => { | ||
return { | ||
setupScript: undefined, | ||
fetch: async () => { | ||
const setupScript = await jupyterLabSetupScriptApi.fetchOne(); | ||
set({ setupScript }); | ||
return setupScript; | ||
}, | ||
update: async (payload) => { | ||
set({ setupScript: payload }); | ||
return await jupyterLabSetupScriptApi.update(payload); | ||
}, | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.