Skip to content

Commit

Permalink
Launch jupyter notebook from Launcher tab
Browse files Browse the repository at this point in the history
  • Loading branch information
prasunanand committed Dec 31, 2024
1 parent 07cc05f commit ae7b2a7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
5 changes: 3 additions & 2 deletions ui/src/ide/IDE.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import StatusBar from './statusBar/StatusBar';
import getFileExtension from './utils';

import './IDE.scss'
import { fontSizeAtom, languageModeAtom, terminalsAtom } from '../store/AppState';
import { fileBrowserReloadCountAtom, fontSizeAtom, languageModeAtom, terminalsAtom } from '../store/AppState';

interface Ifile {
type: string
Expand Down Expand Up @@ -47,6 +47,7 @@ function IDE () {
const [theme] = useAtom(themeAtom)
const [languageMode, setLanguageMode] = useAtom(languageModeAtom)
const [terminals, setTerminals] = useAtom(terminalsAtom)
const [reloadCount] = useAtom(fileBrowserReloadCountAtom)

const defaultNavState: INavDict = {
fileBrowser: { name: 'fileBrowser', display: 'd-block' },
Expand Down Expand Up @@ -175,7 +176,7 @@ function IDE () {
<div className='navigation'>
<NavigationPanel handleNavigationPanel={handleNavigationPanel} />
<div className='sideBar'>
<FileBrowser sendDataToParent={handleDataFromChild} display={navState.fileBrowser.display} />
<FileBrowser sendDataToParent={handleDataFromChild} display={navState.fileBrowser.display} reloadCount={reloadCount} />
<SettingsPanel sendDataToParent={handleDataFromChild} display={navState.settingsPanel.display} />
<JupyterInfoPanel sendDataToParent={handleDataFromChild} display={navState.jupyterInfoPanel.display}/>
<GitPanel sendDataToParent={handleDataFromChild} display={navState.gitPanel.display}/>
Expand Down
19 changes: 17 additions & 2 deletions ui/src/ide/editor/Launcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { useEffect } from 'react';
import './Launcher.scss';
import { BaseApiUrl } from '../config';
import { atom, useAtom } from 'jotai';
import { kernelspecsAtom, terminalsCountAtom, terminalsAtom } from '../../store/AppState';
import { kernelspecsAtom, terminalsCountAtom, terminalsAtom, fileBrowserReloadCountAtom } from '../../store/AppState';
import { v4 as uuidv4 } from 'uuid';



Expand All @@ -17,6 +18,7 @@ const Launcher: React.FC<LauncherProps> = ({ data, sendDataToParent }) => {
const [kernelspecs, setKernelspecs] = useAtom(kernelspecsAtom);
const [terminalCount, setTerminalCount] = useAtom(terminalsCountAtom);
const [terminals, setTerminals] = useAtom(terminalsAtom)
const [reloadCount, setReloadCount] = useAtom(fileBrowserReloadCountAtom)

// Fetch kernelspecs from the API
const fetchData = async () => {
Expand All @@ -29,6 +31,19 @@ const Launcher: React.FC<LauncherProps> = ({ data, sendDataToParent }) => {
}
};

const createNewFile = async (path: string, contentType: string) => {
console.log("add file")
const res = await fetch(BaseApiUrl + '/api/contents/create', {
method: 'POST',
body: JSON.stringify({ parent_dir: path, type: contentType }),
});

const resJson = await res.json();
console.log(resJson)
sendDataToParent(resJson.name, resJson.path, 'notebook');
setReloadCount(reloadCount + 1);
};

// Handle opening a new terminal
const openTerminal = () => {
console.log('Open terminal');
Expand All @@ -55,7 +70,7 @@ const Launcher: React.FC<LauncherProps> = ({ data, sendDataToParent }) => {
<h2 className="font-h5 fontw-300">Notebook</h2>
{Object.keys(kernelspecs).length > 0 ? (
Object.keys(kernelspecs).map((key) => (
<div className="launcher-icon" key={key}>
<div className="launcher-icon" key={key} onClick={() => createNewFile('/', 'notebook')}>
<h6>{key}</h6>
<img src={kernelspecs[key].resources['logo-64x64']} alt="logo" />
</div>
Expand Down
5 changes: 3 additions & 2 deletions ui/src/ide/sidebar/FileBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ interface IContent {
interface FileBrowserProps {
sendDataToParent: (name: string, path: string, type: string) => void;
display: string;
reloadCount: number;
}

export default function FileBrowser({ sendDataToParent, display }: FileBrowserProps) {
export default function FileBrowser({ sendDataToParent, display, reloadCount }: FileBrowserProps) {
const [contents, setContents] = useState<IContent[]>([]);
const [cwd] = useState<string>('');
const [projectName, setProjectName] = useState('')
Expand Down Expand Up @@ -69,7 +70,7 @@ export default function FileBrowser({ sendDataToParent, display }: FileBrowserPr

useEffect(() => {
FetchData();
}, []);
}, [reloadCount]);

return (
<div className={display}>
Expand Down
1 change: 1 addition & 0 deletions ui/src/store/AppState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const kernelsAtom = atom<IKernelsState>({})
export const terminalsAtom = atom<ITerminalsState>({})
export const terminalsCountAtom = atom<number>(0)
export const userNameAtom = atom<string>("")
export const fileBrowserReloadCountAtom = atom<number>(0)


// left statusBar
Expand Down

0 comments on commit ae7b2a7

Please sign in to comment.