Skip to content

Commit ee96c15

Browse files
MarcosVnMarcos Alves
andauthored
feat: add kernel optional prop to Cell.tsx (#332) main (#336)
Co-authored-by: Marcos Alves <[email protected]>
1 parent e5d7110 commit ee96c15

File tree

1 file changed

+11
-4
lines changed
  • packages/react/src/components/cell

1 file changed

+11
-4
lines changed

packages/react/src/components/cell/Cell.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useState, useEffect } from 'react';
88
import { CodeCell, MarkdownCell } from '@jupyterlab/cells';
99
import { Box } from '@primer/react';
1010
import { useJupyter } from './../../jupyter';
11+
import Kernel from '../../jupyter/kernel/Kernel';
1112
import { newUuid } from '../../utils';
1213
import { Lumino } from '../lumino';
1314
import { CellAdapter } from './CellAdapter';
@@ -38,6 +39,10 @@ export type ICellProps = {
3839
* Cell type
3940
*/
4041
type: 'code' | 'markdown' | 'raw';
42+
/**
43+
* Custom kernel for the cell. Falls back to the defaultKernel if not provided.
44+
*/
45+
kernel?: Kernel;
4146
};
4247

4348
export const Cell = (props: ICellProps) => {
@@ -47,6 +52,7 @@ export const Cell = (props: ICellProps) => {
4752
source = '',
4853
startDefaultKernel,
4954
type,
55+
kernel: customKernel,
5056
} = props;
5157
const { defaultKernel, serverSettings } = useJupyter({
5258
startDefaultKernel,
@@ -81,14 +87,15 @@ export const Cell = (props: ICellProps) => {
8187
});
8288
}
8389
useEffect(() => {
84-
if (id && defaultKernel && serverSettings) {
85-
defaultKernel.ready.then(() => {
90+
const kernelToUse = customKernel || defaultKernel;
91+
if (id && serverSettings && kernelToUse) {
92+
kernelToUse.ready.then(() => {
8693
const adapter = new CellAdapter({
8794
id,
8895
type,
8996
source,
9097
serverSettings,
91-
kernel: defaultKernel,
98+
kernel: kernelToUse,
9299
boxOptions: {showToolbar}
93100
});
94101
cellsStore.setAdapter(id, adapter);
@@ -115,7 +122,7 @@ export const Cell = (props: ICellProps) => {
115122
};
116123
});
117124
}
118-
}, [source, defaultKernel, serverSettings]);
125+
}, [source, defaultKernel, customKernel, serverSettings]);
119126
return adapter ? (
120127
<Box
121128
sx={{

0 commit comments

Comments
 (0)