Skip to content

Commit

Permalink
feat: add kernel optional prop to Cell.tsx (#332) (#334)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcos Alves <[email protected]>
  • Loading branch information
MarcosVn and Marcos Alves authored Dec 11, 2024
1 parent 3ac5b26 commit c71f19d
Showing 1 changed file with 12 additions and 4 deletions.
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

0 comments on commit c71f19d

Please sign in to comment.