Skip to content

Commit 0e26000

Browse files
committed
lockdown frontend readonly UI for jupyter far more
1 parent 1505a0b commit 0e26000

File tree

6 files changed

+97
-12
lines changed

6 files changed

+97
-12
lines changed

src/packages/frontend/frame-editors/frame-tree/commands/generic-commands.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ addCommands({
208208
}),
209209
},
210210
undo: {
211+
disabled: ({ readOnly }) => readOnly,
211212
stayOpenOnClick: true,
212213
group: "undo-redo",
213214
pos: 0,
@@ -225,6 +226,7 @@ addCommands({
225226
},
226227
},
227228
redo: {
229+
disabled: ({ readOnly }) => readOnly,
228230
stayOpenOnClick: true,
229231
group: "undo-redo",
230232
pos: 1,
@@ -560,6 +562,7 @@ addCommands({
560562
},
561563

562564
delete: {
565+
disabled: ({ readOnly }) => readOnly,
563566
group: "delete",
564567
icon: "trash",
565568
title: "Delete this file",
@@ -568,6 +571,7 @@ addCommands({
568571
},
569572

570573
rename: {
574+
disabled: ({ readOnly }) => readOnly,
571575
pos: 0,
572576
group: "misc-file-actions",
573577
icon: "swap",
@@ -600,6 +604,7 @@ addCommands({
600604
...fileAction("copy"),
601605
},
602606
move_file: {
607+
disabled: ({ readOnly }) => readOnly,
603608
pos: 4,
604609
group: "misc-file-actions",
605610
icon: "move",
@@ -687,6 +692,7 @@ addCommands({
687692
},
688693
save: {
689694
pos: 0,
695+
disabled: ({ readOnly }) => readOnly,
690696
group: "save",
691697
icon: "save",
692698
title: "Save this file to disk",
@@ -709,7 +715,7 @@ addCommands({
709715
pos: 5,
710716
group: "help-link",
711717
icon: "comment",
712-
label: "Chat With People or AI",
718+
label: "Chat With Collaborators or AI",
713719
button: "Chat",
714720
title:
715721
"Open chat on the side of this file for chatting with project collaborators or AI about this file.",

src/packages/frontend/frame-editors/frame-tree/commands/manage.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ export class ManageCommands {
501501
}
502502
// TODO: handle when cmd.confirm is defined.
503503
return {
504-
disabled: cmd.disabled?.(this),
504+
disabled: cmd.disabled?.(this) || allChildrenAreDisabled(children),
505505
label,
506506
onClick,
507507
key: cmd.stayOpenOnClick ? `${key}-${STAY_OPEN_ON_CLICK}` : key,
@@ -651,3 +651,15 @@ export class ManageCommands {
651651
return ManageCommands.allCommandPositions;
652652
};
653653
}
654+
655+
function allChildrenAreDisabled(children) {
656+
if (children == null || children.length == 0) {
657+
return false;
658+
}
659+
for(const child of children) {
660+
if(!child.disabled) {
661+
return false;
662+
}
663+
}
664+
return true;
665+
}

src/packages/frontend/frame-editors/jupyter-editor/cell-notebook/cell-notebook.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Frame that display a Jupyter notebook in the traditional way with input and outp
88
*/
99

1010
import { Map } from "immutable";
11-
1211
import { Component, Rendered } from "@cocalc/frontend/app-framework";
1312
import { JupyterActions } from "@cocalc/frontend/jupyter/browser-actions";
1413
import { JupyterEditor } from "@cocalc/frontend/jupyter/main";

src/packages/frontend/frame-editors/jupyter-editor/editor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ const JUPYTER_MENUS = {
474474
// title: `Select the ${display_name} Jupyter kernel for writing code in ${Language}.`,
475475
label: Language,
476476
children: [menuItem],
477+
disabled: ({ readOnly }) => readOnly,
477478
});
478479
}
479480
};
@@ -517,6 +518,7 @@ function initMenus() {
517518
throw Error(`invalid Jupyter command name "${name}"`);
518519
}
519520
return {
521+
disabled: cmd.r ? undefined : ({ readOnly }) => readOnly,
520522
button: cmd.b,
521523
title: cmd.t,
522524
label: cmd.m,

0 commit comments

Comments
 (0)