From 5339541b81b1216c60333bd070c40556eb175d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Gessler?= <36667834+gessfred@users.noreply.github.com> Date: Sat, 20 Jan 2024 15:35:10 +0000 Subject: [PATCH] Handle notebook creation --- app/src/App.jsx | 4 +- app/src/components/DataSourceGrid.jsx | 8 +- app/src/pages/Home.jsx | 4 +- app/src/pages/Notebook.jsx | 149 ++++++++++++++++++++++++-- 4 files changed, 147 insertions(+), 18 deletions(-) diff --git a/app/src/App.jsx b/app/src/App.jsx index d900df0..27e8b90 100644 --- a/app/src/App.jsx +++ b/app/src/App.jsx @@ -241,7 +241,7 @@ function App() { setStateProperty({pageid: 'worksheet', datasource: ds})} + createNotebook={(ds) => setStateProperty({pageid: 'notebook', datasource: ds})} onOpenFile={(file) => { console.log('open',file) setState(prev => Object.assign({}, prev, file, {pageid: Object.keys(file)[0]})) @@ -254,7 +254,7 @@ function App() { /> diff --git a/app/src/components/DataSourceGrid.jsx b/app/src/components/DataSourceGrid.jsx index 6cb8041..0165690 100644 --- a/app/src/components/DataSourceGrid.jsx +++ b/app/src/components/DataSourceGrid.jsx @@ -20,7 +20,7 @@ function parseConnectionString(connectionString) { return Object.fromEntries(connectionString?.split(' ').map(kv => kv.split('='))) } -function DatasourceCard({ds, createWorksheet, editDataSource}) { +function DatasourceCard({ds, createNotebook, editDataSource}) { const connection = parseConnectionString(ds.connection_string) return (
  • @@ -41,7 +41,7 @@ function DatasourceCard({ds, createWorksheet, editDataSource}) {
    + + + + + + + + + + + {/* Dropdown */} + + + More + + + + + + {({ active }) => ( + + Edit + + )} + + + {({ active }) => ( + + View + + )} + + + + +
    + + ) +} + + function NotebookToolbar({data, newCell, saveNotebook, metadata, setData}) { return (
    @@ -117,9 +238,9 @@ function NotebookCellToolbar({cell, run, isComputing, setStyle}) { function NotebookCell({api, datasource, setQuery, setResult, setStyle, cell, onCtrlEnter}) { const [state, setState] = useState({isComputing: false}) - console.log(cell, state) + console.log('NotebookCell', cell, state, datasource) const onQueryResult = res => { - console.log("RECEIVED result") + console.log("RECEIVED result", res) setResult(res) setState({isComputing: false}) } @@ -129,6 +250,7 @@ function NotebookCell({api, datasource, setQuery, setResult, setStyle, cell, onC code={cell.query} setCode={setQuery} onCtrlEnter={() => { + console.log(cell.query) execSql(api, cell.query, datasource, onQueryResult, onQueryResult) setState({isComputing: true}) }} @@ -149,11 +271,14 @@ function NotebookCell({api, datasource, setQuery, setResult, setStyle, cell, onC columns={cell.result.columns} rows={cell.result.rows} />} - {cell.result.error && {cell.result && cell.result.error}} + {cell.result.error && {JSON.stringify(cell?.result?.error)}}
    ) } +/* + +*/ export function Notebook({api, datasource, show, data}) { const [state, setState] = useState({cells: {}}) @@ -180,15 +305,19 @@ export function Notebook({api, datasource, show, data}) { }})})) } useEffect(() => { - if(data && data.cells) { - console.log(Object.fromEntries(data.cells.map(cell => [cell.id, cell]))) - setState(Object.assign({}, data, {cells: Object.fromEntries(data.cells.map(cell => [cell.id, cell]))})) - } - - }, [data]) + console.log('datasource', datasource) + setState(Object.assign({}, data, {datasource_id: datasource?.datasource_id, cells: Object.fromEntries((data?.cells || []).map(cell => [cell.id, cell]))})) + }, [data, datasource]) + console.log('state@Notebook', state) if(!show) return return (
    + { + api.userdata.notebooks.write(Object.assign({}, state, {cells: Object.values(state.cells)})) + }} + /> {false &&