-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
CellSidebar.tsx
137 lines (133 loc) 路 4.85 KB
/
CellSidebar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* Copyright (c) 2022-2023 Datalayer Inc. All rights reserved.
*
* MIT License
*/
import { useState } from 'react';
import { useDispatch } from 'react-redux';
import { PanelLayout } from '@lumino/widgets';
import { ActionMenu, Button, Box } from "@primer/react";
import { ChevronRightIcon, XIcon, ChevronUpIcon, ChevronDownIcon, SquareIcon } from "@primer/octicons-react";
import { notebookActions, selectActiveCell } from '../../NotebookRedux';
import { CellSidebarProps } from './CellSidebarWidget';
import CellMetadataEditor from '../metadata/CellMetadataEditor';
import { DATALAYER_CELL_HEADER_CLASS } from './CellSidebarWidget';
export const CellSidebar = (props: CellSidebarProps) => {
const { notebookId, cellId, nbgrader } = props;
const [visible, setVisible] = useState(false);
const dispatch = useDispatch();
const activeCell = selectActiveCell(notebookId);
const layout = (activeCell?.layout);
if (layout) {
const cellWidget = (layout as PanelLayout).widgets[0];
if (cellWidget?.node.id === cellId) {
if (!visible) {
setVisible(true);
}
}
if (cellWidget?.node.id !== cellId) {
if (visible) {
setVisible(false);
}
}
}
if (!visible) {
return <div></div>
}
return activeCell ?
(
<Box
className={DATALAYER_CELL_HEADER_CLASS}
sx={{
'& p': {
marginBottom: '0 !important',
}
}}
>
<span style={{ display: "flex" }}>
<Button title="Run cell" leadingVisual={ChevronRightIcon} variant="invisible" size="small" onClick={(e: any) => {
e.preventDefault();
dispatch(notebookActions.run.started(notebookId));
}}>
Run
</Button>
</span>
<span style={{ display: "flex" }}>
<Button title="Insert code cell above" leadingVisual={ChevronUpIcon} variant="invisible" size="small" onClick={(e: any) => {
e.preventDefault();
dispatch(notebookActions.insertAbove.started({ uid: notebookId, cellType: "code" }));
}}>
Code
</Button>
</span>
<span style={{ display: "flex" }}>
<Button title="Insert markdown cell above" leadingVisual={ChevronUpIcon} variant="invisible" size="small" onClick={(e: any) => {
e.preventDefault();
dispatch(notebookActions.insertAbove.started({ uid: notebookId, cellType: "markdown" }));
}}>
Markdown
</Button>
</span>
<span style={{ display: "flex" }}>
{ activeCell.model.type === "code" ?
<Button title="Convert to markdow cell" leadingVisual={SquareIcon} variant="invisible" size="small" onClick={(e: any) => {
e.preventDefault();
dispatch(notebookActions.changeCellType.started({ uid: notebookId, cellType: "markdown" }));
}}>
To Markdown
</Button>
:
<Button title="Convert to code cell" leadingVisual={SquareIcon} variant="invisible" size="small" onClick={(e: any) => {
e.preventDefault();
dispatch(notebookActions.changeCellType.started({ uid: notebookId, cellType: "code" }));
}}>
To Code
</Button>
}
</span>
<span style={{ display: "flex" }}>
<Button title="Insert markdown cell below" leadingVisual={ChevronDownIcon} variant="invisible" size="small" onClick={(e: any) => {
e.preventDefault();
dispatch(notebookActions.insertBelow.started({ uid: notebookId, cellType: "markdown" }));
}}>
Markdown
</Button>
</span>
<span style={{ display: "flex" }}>
<Button title="Insert code cell below" leadingVisual={ChevronDownIcon} variant="invisible" size="small" onClick={(e: any) => {
e.preventDefault();
dispatch(notebookActions.insertBelow.started({ uid: notebookId, cellType: "code" }));
}}>
Code
</Button>
</span>
<span style={{ display: "flex" }}>
<Button title="Delete cell" leadingVisual={XIcon} variant="invisible" size="small" onClick={(e: any) => {
e.preventDefault();
dispatch(notebookActions.delete.started(notebookId));
}}>
Delete
</Button>
</span>
{nbgrader &&
<ActionMenu>
{/*
<ActionMenu.Anchor>
<IconButton icon={KebabHorizontalIcon} variant="invisible" aria-label="Open column options" />
</ActionMenu.Anchor>
<ActionMenu.Overlay>
*/}
<CellMetadataEditor notebookId={notebookId} cell={activeCell} nbgrader={nbgrader}/>
{/*
</ActionMenu.Overlay>
*/}
</ActionMenu>
}
</Box>
)
:
(
<></>
)
}
export default CellSidebar;