Skip to content

Commit

Permalink
feat: add kernel optional prop to Cell.tsx (datalayer#332) main
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcos Alves committed Dec 11, 2024
1 parent e5d7110 commit 8796661
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/react/src/components/cell/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useState, useEffect } from 'react';
import { CodeCell, MarkdownCell } from '@jupyterlab/cells';
import { Box } from '@primer/react';
import { useJupyter } from './../../jupyter';
import Kernel from '../../jupyter/kernel/Kernel';
import { newUuid } from '../../utils';
import { Lumino } from '../lumino';
import { CellAdapter } from './CellAdapter';
Expand Down Expand Up @@ -38,6 +39,10 @@ export type ICellProps = {
* Cell type
*/
type: 'code' | 'markdown' | 'raw';
/**
* Custom kernel for the cell. Falls back to the defaultKernel if not provided.
*/
kernel?: Kernel;
};

export const Cell = (props: ICellProps) => {
Expand All @@ -47,6 +52,7 @@ export const Cell = (props: ICellProps) => {
source = '',
startDefaultKernel,
type,
kernel: customKernel,
} = props;
const { defaultKernel, serverSettings } = useJupyter({
startDefaultKernel,
Expand Down Expand Up @@ -81,14 +87,15 @@ 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 All @@ -115,7 +122,7 @@ export const Cell = (props: ICellProps) => {
};
});
}
}, [source, defaultKernel, serverSettings]);
}, [source, defaultKernel, customKernel, serverSettings]);
return adapter ? (
<Box
sx={{
Expand Down

0 comments on commit 8796661

Please sign in to comment.