Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling custom kernels for Cell.tsx (#332) (0.17.x) #334

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/react/src/components/cell/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { useState, useEffect } from 'react';
import { CodeCell, MarkdownCell } from '@jupyterlab/cells';
import { Box } from '@primer/react';
import Kernel from '../../jupyter/kernel/Kernel';
import Lumino from '../lumino/Lumino';
import { useJupyter } from './../../jupyter/JupyterContext';
import CellAdapter from './CellAdapter';
Expand Down Expand Up @@ -34,6 +35,10 @@ export type ICellProps = {
* Whether to show the toolbar for cell or not
*/
showToolbar?: boolean;
/**
* Custom kernel for the cell. Falls back to the defaultKernel if not provided.
*/
kernel?: Kernel;
};

export const Cell = (props: ICellProps) => {
Expand All @@ -42,6 +47,7 @@ export const Cell = (props: ICellProps) => {
showToolbar=true,
source = '',
type='code',
kernel: customKernel,
} = props;
const { defaultKernel, serverSettings } = useJupyter();

Expand Down Expand Up @@ -81,14 +87,16 @@ export const Cell = (props: ICellProps) => {
}

useEffect(() => {
if (id && defaultKernel && serverSettings) {
defaultKernel.ready.then(() => {
const kernelToUse = customKernel || defaultKernel;
if (id && serverSettings && kernelToUse) {

kernelToUse.ready.then(() => {
const adapter = new CellAdapter({
id,
type,
source,
serverSettings,
kernel: defaultKernel,
kernel: kernelToUse,
boxOptions: {showToolbar}
});
cellsStore.setAdapter(id, adapter);
Expand Down Expand Up @@ -117,7 +125,7 @@ export const Cell = (props: ICellProps) => {
};
});
}
}, [source, defaultKernel, serverSettings]);
}, [source, defaultKernel, customKernel, serverSettings]);
return adapter ? (
<Box
sx={{
Expand Down
Loading