Skip to content

Commit 35e2984

Browse files
committed
fix #8300 -- readonly code cells in jupyter notebooks should still have button bar (since you can run them, ask ai about them, etc.)
1 parent 1fce0df commit 35e2984

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

src/packages/frontend/jupyter/cell-buttonbar.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ interface Props {
4141
haveLLMCellTools: boolean; // decides if we show the LLM Tools, depends on student project in a course, etc.
4242
index: number;
4343
is_readonly: boolean;
44+
input_is_readonly?: boolean;
4445
}
4546

4647
function areEqual(prev: Props, next: Props): boolean {
@@ -67,9 +68,11 @@ export const CellButtonBar: React.FC<Props> = React.memo(
6768
llmTools,
6869
index,
6970
is_readonly,
71+
input_is_readonly,
7072
haveLLMCellTools,
7173
}: Props) => {
7274
const intl = useIntl();
75+
console.log("CellButtonBar", { is_readonly, input_is_readonly });
7376

7477
const { project_id, path } = useFrameContext();
7578
const frameActions = useNotebookFrameActions();

src/packages/frontend/jupyter/cell-input.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export interface CellInputProps {
6565
cell_toolbar?: string;
6666
trust?: boolean;
6767
is_readonly: boolean;
68+
input_is_readonly: boolean;
6869
is_scrolling?: boolean;
6970
id: string;
7071
index: number;
@@ -103,14 +104,14 @@ export const CellInput: React.FC<CellInputProps> = React.memo(
103104
actions={props.actions}
104105
id={props.id}
105106
dragHandle={props.dragHandle}
106-
read_only={props.is_readonly}
107+
read_only={props.input_is_readonly}
107108
/>
108109
</HiddenXS>
109110
);
110111
}
111112

112113
function handle_md_double_click(): void {
113-
if (props.is_readonly) {
114+
if (props.input_is_readonly) {
114115
return;
115116
}
116117
frameActions.current?.switch_md_cell_to_edit(props.cell.get("id"));
@@ -132,7 +133,7 @@ export const CellInput: React.FC<CellInputProps> = React.memo(
132133
opt = opt.set("foldGutter", false);
133134
break;
134135
}
135-
if (props.is_readonly) {
136+
if (props.input_is_readonly) {
136137
opt = opt.set("readOnly", true);
137138
}
138139
if (props.cell.get("line_numbers") != null) {
@@ -152,7 +153,7 @@ export const CellInput: React.FC<CellInputProps> = React.memo(
152153
return (
153154
<CodeMirror
154155
actions={
155-
props.is_readonly ? undefined : props.actions
156+
props.input_is_readonly ? undefined : props.actions
156157
/* Do NOT pass in actions when read only, since having any actions *defines*
157158
not read only for the codemirror editor; also, it will get created with
158159
potentially the same id as a normal cell, hence get linked to it, and
@@ -189,7 +190,7 @@ export const CellInput: React.FC<CellInputProps> = React.memo(
189190
if (
190191
props.actions == null ||
191192
props.cell.getIn(["metadata", "editable"]) === false ||
192-
props.is_readonly
193+
props.input_is_readonly
193194
) {
194195
return;
195196
}
@@ -244,7 +245,7 @@ export const CellInput: React.FC<CellInputProps> = React.memo(
244245
<MostlyStaticMarkdown
245246
value={value}
246247
onChange={(value) => {
247-
if (props.is_readonly) {
248+
if (props.input_is_readonly) {
248249
return;
249250
}
250251
// user checked a checkbox.
@@ -430,6 +431,7 @@ export const CellInput: React.FC<CellInputProps> = React.memo(
430431
cell={props.cell}
431432
is_current={props.is_current}
432433
is_readonly={props.is_readonly}
434+
input_is_readonly={props.input_is_readonly}
433435
computeServerId={props.computeServerId}
434436
llmTools={props.llmTools}
435437
haveLLMCellTools={haveLLMCellTools}
@@ -490,6 +492,7 @@ export const CellInput: React.FC<CellInputProps> = React.memo(
490492
next.font_size !== cur.font_size ||
491493
next.complete !== cur.complete ||
492494
next.is_readonly !== cur.is_readonly ||
495+
next.input_is_readonly !== cur.input_is_readonly ||
493496
next.is_scrolling !== cur.is_scrolling ||
494497
next.cell_toolbar !== cur.cell_toolbar ||
495498
(next.llmTools?.model ?? "") !== (cur.llmTools?.model ?? "") ||

src/packages/frontend/jupyter/cell.tsx

+13-18
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@ export const Cell: React.FC<Props> = React.memo((props: Props) => {
105105
return <></>;
106106
}
107107

108-
function is_editable(): boolean {
109-
return (
110-
!props.read_only &&
111-
(props.cell.getIn(["metadata", "editable"], true) as any)
112-
);
113-
}
114-
115108
function is_deletable(): boolean {
116109
return props.cell.getIn(["metadata", "deletable"], true) as any;
117110
}
@@ -138,7 +131,8 @@ export const Cell: React.FC<Props> = React.memo((props: Props) => {
138131
complete={props.is_current ? props.complete : undefined}
139132
cell_toolbar={props.cell_toolbar}
140133
trust={props.trust}
141-
is_readonly={!is_editable()}
134+
is_readonly={!!props.read_only}
135+
input_is_readonly={!props.cell.getIn(["metadata", "editable"], true)}
142136
is_scrolling={props.is_scrolling}
143137
llmTools={props.llmTools}
144138
computeServerId={props.computeServerId}
@@ -211,16 +205,17 @@ export const Cell: React.FC<Props> = React.memo((props: Props) => {
211205
}
212206

213207
function render_not_editable(): Rendered {
214-
if (is_editable()) return;
215-
return (
216-
<Tip
217-
title={"Protected from modifications"}
218-
placement={"right"}
219-
size={"small"}
220-
>
221-
<Icon name="lock" />
222-
</Tip>
223-
);
208+
if (props.read_only || !props.cell.getIn(["metadata", "editable"], true)) {
209+
return (
210+
<Tip
211+
title={"Protected from modifications"}
212+
placement={"right"}
213+
size={"small"}
214+
>
215+
<Icon name="lock" />
216+
</Tip>
217+
);
218+
}
224219
}
225220

226221
function render_nbgrader(): Rendered {

0 commit comments

Comments
 (0)