-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: add state control for cell execution (#279) * feat: add example for cell execution control (#279) * fix: reject promise error cases in onReply (#279) * feat: improve kernelexecutor error reject (#279) --------- Co-authored-by: Marcos Alves <[email protected]>
- Loading branch information
Showing
4 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2021-2023 Datalayer, Inc. | ||
* | ||
* MIT License | ||
*/ | ||
import React, {useEffect} from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
|
||
import {Button, Box} from '@primer/react'; | ||
|
||
import Jupyter from '../jupyter/Jupyter'; | ||
import Cell from '../components/cell/Cell'; | ||
import { cellsStore, ICellsState } from '../components/cell/CellState'; | ||
|
||
|
||
const div = document.createElement('div'); | ||
document.body.appendChild(div); | ||
const root = createRoot(div); | ||
|
||
const btnStyle = { | ||
marginLeft: '50px', | ||
marginTop: '20px' | ||
} | ||
|
||
const CELL_CODE = `import time\ntime.sleep(3)` | ||
|
||
const CellExecuteControl = () => { | ||
const [executionDisable, setExecutionDisable] = React.useState(false); | ||
|
||
useEffect(() => { | ||
const handleChange = (newState: ICellsState) => { | ||
setExecutionDisable(newState.isAnyCellExecuting); | ||
}; | ||
|
||
const unsubscribe = cellsStore.subscribe(handleChange); | ||
return () => { | ||
unsubscribe(); | ||
}; | ||
}, []); | ||
|
||
const onExecuteClick = () => { | ||
cellsStore.getState().execute(); | ||
} | ||
|
||
return ( | ||
<Jupyter> | ||
<Box style={{marginTop: '20px'}}> | ||
<Cell | ||
id='1' | ||
type='code' | ||
source={CELL_CODE} | ||
autoStart={false} | ||
showToolbar={false} /> | ||
<Cell | ||
id='2' | ||
type='code' | ||
autoStart={false} | ||
showToolbar={false} /> | ||
<Button | ||
onClick={onExecuteClick} | ||
disabled={executionDisable} | ||
style={btnStyle}>Execute all</Button> | ||
</Box> | ||
</Jupyter> | ||
) | ||
}; | ||
|
||
root.render(<CellExecuteControl/>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters