Skip to content

Commit 8270138

Browse files
committed
frontend/i18n: something is off with the types or assignments of AllActions, FrameActions, etc. in Jupyter
1 parent 4f39fb9 commit 8270138

File tree

6 files changed

+52
-24
lines changed

6 files changed

+52
-24
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,7 @@ export class Actions<
19941994
// Do a formatting action to whatever code editor
19951995
// is currently active, or the main document if none is
19961996
// focused or force_main is true.
1997-
async format_action(cmd, args, force_main: boolean = false): Promise<void> {
1997+
async format_action(cmd, args?, force_main: boolean = false): Promise<void> {
19981998
if (!force_main) {
19991999
const id = this._get_active_id();
20002000
const editor = this.get_code_editor(id);

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import type { MenuItem } from "@cocalc/frontend/components/dropdown-menu";
1313
import { STAY_OPEN_ON_CLICK } from "@cocalc/frontend/components/dropdown-menu";
1414
import { Icon, IconName } from "@cocalc/frontend/components/icon";
1515
import { IS_MOBILE } from "@cocalc/frontend/feature";
16-
import { isIntlMessage } from "@cocalc/frontend/i18n";
16+
import { IntlMessage, isIntlMessage } from "@cocalc/frontend/i18n";
1717
import { cmp, filename_extension, trunc_middle } from "@cocalc/util/misc";
18+
// import { FrameTitleBarProps } from "../title-bar";
19+
import { EditorDescription } from "../types";
1820
import { COMMANDS } from "./commands";
1921
import { APPLICATION_MENU, SEARCH_COMMANDS } from "./const";
2022
import { GROUPS, MENUS } from "./menus";
@@ -25,7 +27,9 @@ const MAX_SEARCH_RESULTS = 10;
2527
const ICON_WIDTH = "24px";
2628

2729
export class ManageCommands {
28-
readonly props;
30+
// TODO: setting this to FrameTitleBarProps causes type issues in frame-editors/jupyter-editor/editor.ts
31+
// So, there is probably a fundamental problem with that mapping into "AllActions"
32+
readonly props; // FrameTitleBarProps;
2933
readonly studentProjectFunctionality;
3034
readonly setShowAI: (val: boolean) => void;
3135
readonly setShowNewAI: (val: boolean) => void;
@@ -58,7 +62,7 @@ export class ManageCommands {
5862
this.readOnly = readOnly;
5963
this.editorSettings = editorSettings;
6064
this.intl = intl;
61-
this.formatMessageValues = { br: <br />, ...this.props };
65+
this.formatMessageValues = { br: <br /> };
6266
//window.x = { manage: this };
6367
}
6468

@@ -171,6 +175,19 @@ export class ManageCommands {
171175
return v;
172176
};
173177

178+
spec2display = (
179+
spec: EditorDescription,
180+
aspect: "name" | "short",
181+
): string => {
182+
const label: string | IntlMessage | undefined = spec[aspect];
183+
if (isIntlMessage(label)) {
184+
return this.intl.formatMessage(label);
185+
} else if (typeof label === "string") {
186+
return label;
187+
}
188+
return "";
189+
};
190+
174191
applicationMenuTitle = () => {
175192
let title: string = "Application";
176193
let icon: IconName | undefined = undefined;
@@ -179,9 +196,9 @@ export class ManageCommands {
179196
if (spec != null) {
180197
icon = spec.icon;
181198
if (spec.short) {
182-
title = spec.short;
199+
title = this.spec2display(spec, "short");
183200
} else if (spec.name) {
184-
title = spec.name;
201+
title = this.spec2display(spec, "name");
185202
}
186203
}
187204
}
@@ -243,11 +260,11 @@ export class ManageCommands {
243260
`BUG -- ${type} must be defined by the editor_spec, but is not`,
244261
);
245262
}
246-
const search = spec.name?.toLowerCase();
247-
let label = spec.name;
263+
const label = this.spec2display(spec, "name");
264+
const search = label.toLowerCase();
248265
items.push({
249266
search,
250-
label: selected_type == type ? <b>{label}</b> : label,
267+
label: selected_type === type ? <b>{label}</b> : label,
251268
icon: spec.icon ? spec.icon : "file",
252269
onClick: () => {
253270
if (createNew) {

src/packages/frontend/frame-editors/frame-tree/title-bar.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ import { StandaloneComputeServerDocStatus } from "@cocalc/frontend/compute/stand
3636
import { useStudentProjectFunctionality } from "@cocalc/frontend/course";
3737
import { IS_MOBILE } from "@cocalc/frontend/feature";
3838
import { excludeFromComputeServer } from "@cocalc/frontend/file-associations";
39+
import { NotebookFrameActions } from "@cocalc/frontend/frame-editors/jupyter-editor/cell-notebook/actions";
3940
import { IntlMessage, isIntlMessage, labels } from "@cocalc/frontend/i18n";
41+
import { JupyterActions } from "@cocalc/frontend/jupyter/browser-actions";
4042
import { AIGenerateDocumentModal } from "@cocalc/frontend/project/page/home-page/ai-generate-document";
4143
import { isSupportedExtension } from "@cocalc/frontend/project/page/home-page/ai-generate-examples";
4244
import { AvailableFeatures } from "@cocalc/frontend/project_configuration";
@@ -68,7 +70,7 @@ import { ConnectionStatus, EditorDescription, EditorSpec } from "./types";
6870
// actions that are not defined in the base code editor actions.
6971
// In all cases, we check these are actually defined before calling
7072
// them to avoid a runtime stacktrace.
71-
interface FrameActions extends Actions {
73+
export interface FrameActions extends Actions {
7274
zoom_page_width?: (id: string) => void;
7375
zoom_page_height?: (id: string) => void;
7476
sync?: (id: string, editor_actions: EditorActions) => void;
@@ -79,6 +81,10 @@ interface FrameActions extends Actions {
7981
word_count?: (time: number, force: boolean) => void;
8082
close_and_halt?: (id: string) => void;
8183
stop_build?: (id: string) => void;
84+
85+
// optional, set in frame-editors/jupyter-editor/editor.ts → initMenus
86+
jupyter_actions?: JupyterActions;
87+
frame_actions?: NotebookFrameActions;
8288
}
8389

8490
interface EditorActions extends Actions {
@@ -148,7 +154,7 @@ export function ConnectionStatusIcon({ status }: { status: ConnectionStatus }) {
148154
);
149155
}
150156

151-
interface Props {
157+
export interface FrameTitleBarProps {
152158
actions: FrameActions;
153159
editor_actions: EditorActions;
154160
path: string;
@@ -173,7 +179,7 @@ interface Props {
173179
tab_is_visible?: boolean;
174180
}
175181

176-
export function FrameTitleBar(props: Props) {
182+
export function FrameTitleBar(props: FrameTitleBarProps) {
177183
// Whether this is *the* active currently focused frame:
178184
const is_active = props.active_id === props.id;
179185
const track = useMemo(() => {

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,24 @@ Jupyter Frame Editor Actions
88
*/
99

1010
import { delay } from "awaiting";
11-
import { FrameTree } from "../frame-tree/types";
11+
12+
import { syncAllComputeServers } from "@cocalc/frontend/compute/sync-all";
13+
import { markdown_to_slate } from "@cocalc/frontend/editors/slate/markdown-to-slate";
14+
import { JupyterActions } from "@cocalc/frontend/jupyter/browser-actions";
15+
import { toFragmentId } from "@cocalc/frontend/jupyter/heading-tag";
16+
import { open_new_tab } from "@cocalc/frontend/misc";
17+
import type { FragmentId } from "@cocalc/frontend/misc/fragment-id";
1218
import {
1319
Actions as BaseActions,
1420
CodeEditorState,
1521
} from "../code-editor/actions";
16-
import { revealjs_slideshow_html } from "./slideshow-revealjs/nbconvert";
22+
import { FrameTree } from "../frame-tree/types";
23+
import { NotebookFrameActions } from "./cell-notebook/actions";
1724
import {
18-
create_jupyter_actions,
1925
close_jupyter_actions,
26+
create_jupyter_actions,
2027
} from "./jupyter-actions";
21-
import type { FragmentId } from "@cocalc/frontend/misc/fragment-id";
22-
import { markdown_to_slate } from "@cocalc/frontend/editors/slate/markdown-to-slate";
23-
import { toFragmentId } from "@cocalc/frontend/jupyter/heading-tag";
24-
import { JupyterActions } from "../../jupyter/browser-actions";
25-
import { NotebookFrameActions } from "./cell-notebook/actions";
26-
import { open_new_tab } from "../../misc";
27-
import { syncAllComputeServers } from "@cocalc/frontend/compute/sync-all";
28+
import { revealjs_slideshow_html } from "./slideshow-revealjs/nbconvert";
2829

2930
export interface JupyterEditorState extends CodeEditorState {
3031
slideshow?: {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type { Command } from "@cocalc/frontend/frame-editors/frame-tree/commands
1313
import { addEditorMenus } from "@cocalc/frontend/frame-editors/frame-tree/commands";
1414
import { FORMAT_SOURCE_ICON } from "@cocalc/frontend/frame-editors/frame-tree/config";
1515
import { labels, menu } from "@cocalc/frontend/i18n";
16+
import { editor } from "@cocalc/frontend/i18n/common";
1617
import { AllActions, commands } from "@cocalc/frontend/jupyter/commands";
1718
import { shortcut_to_string } from "@cocalc/frontend/jupyter/keyboard-shortcuts";
1819
import { capitalize, field_cmp, set } from "@cocalc/util/misc";
@@ -28,7 +29,6 @@ import { RawIPynb } from "./raw-ipynb";
2829
import { Slideshow } from "./slideshow-revealjs/slideshow";
2930
import { JupyterSnippets } from "./snippets";
3031
import { TableOfContents } from "./table-of-contents";
31-
import { editor } from "@cocalc/frontend/i18n/common";
3232

3333
const {
3434
ICON_NAME: SNIPPET_ICON_NAME,
@@ -542,7 +542,7 @@ function initMenus() {
542542
onClick: ({ props }) => {
543543
allActions.frame_actions = props.actions.frame_actions?.[props.id];
544544
allActions.jupyter_actions = props.actions.jupyter_actions;
545-
allActions.editor_actions = props.actions;
545+
allActions.editor_actions = props.actions; // TODO should this be props.editor_actions ?
546546
cmd.f();
547547
},
548548
};

src/packages/frontend/i18n/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ Ref:
3838
- https://simplelocalize.io/docs/integrations/format-js/
3939
- https://simplelocalize.io/docs/integrations/format-js-cli/
4040

41+
### Issues
42+
43+
In dev mode, there are warnings like `"defaultRichTextElements" was specified but "message" was not pre-compiled.`. I don't understand why. These simple json messages for translations are fine (at least there is no way to compile them) and they also seem to work. It's probably a matter of fixing the top level "render.tsx" components – i.e. when to prevent a rendering, because of incomplete data, or something like that.
44+
4145
## Specifics
4246

4347
CoCalc specific rules for implementing translations, of which I think are good to follow in CoCalc's environment:

0 commit comments

Comments
 (0)