Skip to content

Commit 8403f6c

Browse files
committed
add terminal settings menu
1 parent db2bcf1 commit 8403f6c

File tree

9 files changed

+107
-7
lines changed

9 files changed

+107
-7
lines changed

src/packages/frontend/account/terminal-settings.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import { useIntl } from "react-intl";
7-
87
import { Panel } from "@cocalc/frontend/antd-bootstrap";
98
import { useTypedRedux } from "@cocalc/frontend/app-framework";
109
import {
@@ -23,7 +22,7 @@ declare global {
2322
}
2423
}
2524

26-
export const TerminalSettings: React.FC = () => {
25+
export function TerminalSettings() {
2726
const intl = useIntl();
2827

2928
const terminal = useTypedRedux("account", "terminal");
@@ -56,4 +55,4 @@ export const TerminalSettings: React.FC = () => {
5655
</LabeledRow>
5756
</Panel>
5857
);
59-
};
58+
}

src/packages/frontend/app/actions.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class PageActions extends Actions<PageState> {
2222
private active_key_handler?: any;
2323
private suppress_key_handlers: boolean = false;
2424
private popconfirmIsOpen: boolean = false;
25+
private settingsModalIsOpen: boolean = false;
2526

2627
/* Expects a func which takes a browser keydown event
2728
Only allows one keyhandler to be active at a time.
@@ -421,6 +422,27 @@ export class PageActions extends Actions<PageState> {
421422
this.setState({ popconfirm: { open: false } });
422423
}
423424
};
425+
426+
settings = async (name) => {
427+
if (!name) {
428+
this.setState({ settingsModal: "" });
429+
this.settingsModalIsOpen = false;
430+
return;
431+
}
432+
const store = redux.getStore("page");
433+
while (this.settingsModalIsOpen) {
434+
await once(store, "change");
435+
}
436+
try {
437+
this.settingsModalIsOpen = true;
438+
this.setState({ settingsModal: name });
439+
while (store.get("settingsModal")) {
440+
await once(store, "change");
441+
}
442+
} finally {
443+
this.settingsModalIsOpen = false;
444+
}
445+
};
424446
}
425447

426448
export function init_actions() {

src/packages/frontend/app/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ everything on *desktop*, once the user has signed in.
1111
declare var DEBUG: boolean;
1212

1313
import { useIntl } from "react-intl";
14-
1514
import { Avatar } from "@cocalc/frontend/account/avatar/avatar";
1615
import { alert_message } from "@cocalc/frontend/alerts";
1716
import { Button } from "@cocalc/frontend/antd-bootstrap";
@@ -45,6 +44,7 @@ import PopconfirmModal from "./popconfirm-modal";
4544
import { HIDE_LABEL_THRESHOLD, NAV_CLASS } from "./top-nav-consts";
4645
import { CookieWarning, LocalStorageWarning, VersionWarning } from "./warnings";
4746
import { I18NBanner, useShowI18NBanner } from "./i18n-banner";
47+
import SettingsModal from "./settings-modal";
4848

4949
// ipad and ios have a weird trick where they make the screen
5050
// actually smaller than 100vh and have it be scrollable, even
@@ -110,7 +110,7 @@ export const Page: React.FC = () => {
110110
);
111111
const when_account_created = useTypedRedux("account", "created");
112112
const groups = useTypedRedux("account", "groups");
113-
const show_i18n = useShowI18NBanner()
113+
const show_i18n = useShowI18NBanner();
114114

115115
const is_commercial = useTypedRedux("customize", "is_commercial");
116116

@@ -401,6 +401,7 @@ export const Page: React.FC = () => {
401401
<ActiveContent />
402402
<PayAsYouGoModal />
403403
<PopconfirmModal />
404+
<SettingsModal />
404405
</div>
405406
);
406407
};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Easily show a global settings modal at any point in cocalc by doing
3+
4+
await redux.getActions("page").settings(name)
5+
6+
This should be used only for various types of configuration that is not
7+
specific to a particular project. E.g., many of the panels in the Account
8+
tab could also be accessed this way.
9+
*/
10+
11+
import { Modal } from "antd";
12+
import { useActions, useRedux } from "@cocalc/frontend/app-framework";
13+
14+
import { TerminalSettings } from "@cocalc/frontend/account/terminal-settings";
15+
16+
// Ensure the billing Actions and Store are created, which are needed for purchases, etc., to work...
17+
import "@cocalc/frontend/billing/actions";
18+
19+
export default function SettingsModal({}) {
20+
const actions = useActions("page");
21+
const name = useRedux("page", "settingsModal");
22+
23+
if (!name) {
24+
return null;
25+
}
26+
27+
const { Component, title } = getDescription(name);
28+
29+
const close = () => {
30+
actions.settings("");
31+
};
32+
33+
// destroyOnClose so values in quota input, etc. get updated
34+
return (
35+
<Modal
36+
key="settings-modal"
37+
width={"600px"}
38+
destroyOnClose
39+
open
40+
title={title}
41+
onOk={close}
42+
onCancel={close}
43+
cancelButtonProps={{ style: { display: "none" } }}
44+
okText="Close"
45+
>
46+
<br />
47+
{Component != null ? <Component /> : undefined}
48+
</Modal>
49+
);
50+
}
51+
52+
function getDescription(name: string): { Component?; title? } {
53+
switch (name) {
54+
case "terminal-settings":
55+
return { Component: TerminalSettings };
56+
default:
57+
return {
58+
title: <div>Unknown component {name}</div>,
59+
};
60+
}
61+
}

src/packages/frontend/app/store.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export interface PageState {
5050
cancelText?: string;
5151
okText?: string;
5252
};
53+
54+
settingsModal?: string;
5355
}
5456

5557
export class PageStore extends Store<PageState> {}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,17 @@ addCommands({
11231123
}),
11241124
...fileAction("close"),
11251125
},
1126+
settings: {
1127+
pos: 10,
1128+
group: "settings",
1129+
icon: "gear",
1130+
title: "Settings",
1131+
label: "Settings",
1132+
button: "Settings",
1133+
onClick: ({ props }) => {
1134+
props.actions.settings?.();
1135+
},
1136+
},
11261137
new_frame_of_type: {
11271138
alwaysShow: true,
11281139
icon: "plus-square",

src/packages/frontend/frame-editors/frame-tree/commands/generic-menus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ addMenus({
66
app: {
77
label: APPLICATION_MENU,
88
pos: -10,
9-
groups: ["about", "frame_types", "quit"],
9+
groups: ["about", "frame_types", "quit", "settings"],
1010
},
1111
file: {
1212
label: menu.file,

src/packages/frontend/frame-editors/terminal-editor/actions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ export class TerminalActions extends Actions {
115115
compute_server() {
116116
// this is here just so the dropdown gets enabled
117117
}
118+
119+
settings = () => {
120+
this.redux.getActions("page").settings("terminal-settings");
121+
};
118122
}
119123

120124
// Also useful to import as just "Actions" for our editor reg system

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const terminal: EditorDescription = {
3838
"chatgpt",
3939
// "tour", -- temporarily disabled until I figure out how to to do editor tours again (fallout from pr 7180)
4040
"compute_server",
41-
/*"reload" */
41+
"settings",
4242
]),
4343
buttons: set([
4444
"decrease_font_size",

0 commit comments

Comments
 (0)