MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / PythonCell

Function PythonCell

frontend/src/components/tabs/notebooks/PythonCell.tsx:50–684  ·  view source on GitHub ↗
({
  cell,
  isActive,
  onActivate,
  cellNumber,
})

Source from the content-addressed store, hash-verified

48 * Individual Python cell component with editor and output display
49 */
50const PythonCell: React.FC<PythonCellProps> = ({
51 cell,
52 isActive,
53 onActivate,
54 cellNumber,
55}) => {
56 const { t } = useTranslation();
57 const {
58 updateCell,
59 deleteCell,
60 executeCell,
61 moveCell,
62 clearCell,
63 toggleCellEditMode,
64 toggleCellInputCollapse,
65 toggleCellOutputCollapse,
66 isExecuting: globalExecuting,
67 } = usePythonStore();
68
69 const [showMenu, setShowMenu] = useState(false);
70 const [executionTime, setExecutionTime] = useState<number | null>(null);
71 const menuRef = useRef<HTMLDivElement>(null);
72 const cellRef = useRef<HTMLDivElement>(null);
73
74 // Close menu when clicking outside and exit markdown edit mode when clicking outside
75 useEffect(() => {
76 const handleClickOutside = (event: MouseEvent) => {
77 // Close dropdown menu if clicking outside
78 if (menuRef.current && !menuRef.current.contains(event.target as Node)) {
79 setShowMenu(false);
80 }
81
82 // Exit markdown edit mode if clicking outside the cell
83 if (
84 cell.type === 'markdown' &&
85 cell.isEditing &&
86 cellRef.current &&
87 !cellRef.current.contains(event.target as Node)
88 ) {
89 toggleCellEditMode(cell.id);
90 }
91 };
92
93 document.addEventListener('mousedown', handleClickOutside);
94 return () => document.removeEventListener('mousedown', handleClickOutside);
95 }, [cell.type, cell.isEditing, cell.id, toggleCellEditMode]);
96
97 const handleExecute = async () => {
98 const startTime = performance.now();
99 await executeCell(cell.id);
100 const endTime = performance.now();
101 setExecutionTime(endTime - startTime);
102 };
103
104 const handleCopyCell = () => {
105 navigator.clipboard.writeText(cell.code);
106 setShowMenu(false);
107 };

Callers

nothing calls this directly

Calls 4

handleExecuteFunction · 0.85
handleToggleEditFunction · 0.85
insertMarkdownFormatFunction · 0.85
renderOutputFunction · 0.85

Tested by

no test coverage detected