Skip to content

Commit 2ae8543

Browse files
authored
Merge pull request #7788 from sagemathinc/fix-i18n-timetravel
frontend/frame-editors: nail down type of each frame editor spec + translation fix
2 parents c2c9744 + 1fc9999 commit 2ae8543

File tree

34 files changed

+2631
-1273
lines changed

34 files changed

+2631
-1273
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ export const SHELLS = {
3131
ml: "ocaml",
3232
pl: "perl",
3333
rb: "ruby",
34-
};
34+
} as const;
3535

36-
export const cm = {
36+
export const cm: EditorDescription = {
37+
type: "cm",
3738
short: "Code",
3839
name: "Source Code",
3940
icon: "code",
@@ -65,13 +66,13 @@ export const cm = {
6566
},
6667
},
6768
},
68-
} as EditorDescription;
69+
} as const;
6970

7071
const EDITOR_SPEC = {
7172
cm,
7273
terminal,
7374
time_travel,
74-
};
75+
} as const;
7576

7677
export const Editor = createEditor({
7778
format_bar: false,

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

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
Students,
1919
Handouts,
2020
} from "./course-panels";
21+
import { EditorDescription } from "../frame-tree/types";
2122

2223
const commands = set([
2324
// commented out for now since broken: See https://github.com/sagemathinc/cocalc/issues/7235
@@ -30,47 +31,62 @@ const commands = set([
3031
//const buttons = set(["decrease_font_size", "increase_font_size"]);
3132
const buttons = undefined;
3233

34+
const course_students: EditorDescription = {
35+
type: "course-students",
36+
short: "Students",
37+
name: "Students",
38+
icon: "users",
39+
component: Students,
40+
commands,
41+
buttons,
42+
} as const;
43+
44+
const course_assignments: EditorDescription = {
45+
type: "course-assignments",
46+
short: "Assignments",
47+
name: "Assignments",
48+
icon: "share-square",
49+
component: Assignments,
50+
commands,
51+
buttons,
52+
} as const;
53+
54+
const course_handouts: EditorDescription = {
55+
type: "course-handouts",
56+
short: "Handouts",
57+
name: "Handouts",
58+
icon: "copy",
59+
component: Handouts,
60+
commands,
61+
buttons,
62+
} as const;
63+
64+
const course_configuration: EditorDescription = {
65+
type: "course-configuration",
66+
short: "Config",
67+
name: "Configuration",
68+
icon: "cogs",
69+
component: Configuration,
70+
commands,
71+
buttons,
72+
} as const;
73+
74+
const course_shared_project: EditorDescription = {
75+
type: "course-shared_project",
76+
short: "Shared",
77+
name: "Shared Project",
78+
icon: "share-square",
79+
component: SharedProject,
80+
commands,
81+
buttons,
82+
} as const;
83+
3384
export const EDITOR_SPEC = {
34-
course_students: {
35-
short: "Students",
36-
name: "Students",
37-
icon: "users",
38-
component: Students,
39-
commands,
40-
buttons,
41-
},
42-
course_assignments: {
43-
short: "Assignments",
44-
name: "Assignments",
45-
icon: "share-square",
46-
component: Assignments,
47-
commands,
48-
buttons,
49-
},
50-
course_handouts: {
51-
short: "Handouts",
52-
name: "Handouts",
53-
icon: "copy",
54-
component: Handouts,
55-
commands,
56-
buttons,
57-
},
58-
course_configuration: {
59-
short: "Config",
60-
name: "Configuration",
61-
icon: "cogs",
62-
component: Configuration,
63-
commands,
64-
buttons,
65-
},
66-
course_shared_project: {
67-
short: "Shared",
68-
name: "Shared Project",
69-
icon: "share-square",
70-
component: SharedProject,
71-
commands,
72-
buttons,
73-
},
85+
course_students,
86+
course_assignments,
87+
course_handouts,
88+
course_configuration,
89+
course_shared_project,
7490
terminal,
7591
time_travel,
7692
} as const;

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,28 @@ import { time_travel } from "@cocalc/frontend/frame-editors/time-travel-editor/e
1111
import TableEditor from "./table-editor";
1212
import Users from "./users";
1313

14+
const tables: EditorDescription = {
15+
type: "crm-tables",
16+
short: "Tables",
17+
name: "Tables",
18+
icon: "database",
19+
component: TableEditor,
20+
commands: set(["save", "undo", "redo"]),
21+
} as const;
22+
23+
const account: EditorDescription = {
24+
type: "crm-account",
25+
short: "Users",
26+
name: "User Search",
27+
icon: "users",
28+
component: Users,
29+
} as const;
30+
1431
const EDITOR_SPEC = {
15-
tables: {
16-
short: "Tables",
17-
name: "Tables",
18-
icon: "database",
19-
component: TableEditor,
20-
commands: set(["save", "undo", "redo"]),
21-
},
22-
account: {
23-
short: "Users",
24-
name: "User Search",
25-
icon: "users",
26-
component: Users,
27-
},
32+
tables,
33+
account,
2834
time_travel,
29-
} as { [name: string]: EditorDescription };
35+
} as const;
3036

3137
export const Editor = createEditor({
3238
format_bar: false,

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

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,51 @@
77
Top-level react component for editing CSV files
88
*/
99

10-
import { createEditor } from "../frame-tree/editor";
1110
import { set } from "@cocalc/util/misc";
1211
import { CodemirrorEditor } from "../code-editor/codemirror-editor";
12+
import { createEditor } from "../frame-tree/editor";
13+
import { EditorDescription } from "../frame-tree/types";
1314
import { terminal } from "../terminal-editor/editor";
1415
import { time_travel } from "../time-travel-editor/editor";
1516
import Grid from "./grid";
1617

17-
const EDITOR_SPEC = {
18-
grid: {
19-
short: "Grid",
20-
name: "Grid",
21-
icon: "table",
22-
component: Grid,
23-
commands: set(["decrease_font_size", "increase_font_size", "chatgpt"]),
24-
},
18+
const grid: EditorDescription = {
19+
type: "csv-grid",
20+
short: "Grid",
21+
name: "Grid",
22+
icon: "table",
23+
component: Grid,
24+
commands: set(["decrease_font_size", "increase_font_size", "chatgpt"]),
25+
} as const;
2526

26-
cm: {
27-
short: "Raw",
28-
name: "Raw Data",
29-
icon: "code",
30-
component: CodemirrorEditor,
31-
commands: set([
32-
"chatgpt",
33-
"print",
34-
"decrease_font_size",
35-
"increase_font_size",
36-
"save",
37-
"time_travel",
38-
"replace",
39-
"find",
40-
"goto_line",
41-
"cut",
42-
"paste",
43-
"copy",
44-
"undo",
45-
"redo",
46-
]),
47-
},
27+
const cm: EditorDescription = {
28+
type: "cm",
29+
short: "Raw",
30+
name: "Raw Data",
31+
icon: "code",
32+
component: CodemirrorEditor,
33+
commands: set([
34+
"chatgpt",
35+
"print",
36+
"decrease_font_size",
37+
"increase_font_size",
38+
"save",
39+
"time_travel",
40+
"replace",
41+
"find",
42+
"goto_line",
43+
"cut",
44+
"paste",
45+
"copy",
46+
"undo",
47+
"redo",
48+
]),
49+
} as const;
4850

51+
const EDITOR_SPEC = {
52+
grid,
53+
cm,
4954
terminal,
50-
5155
time_travel,
5256
} as const;
5357

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { copy, hidden_meta_file, is_different } from "@cocalc/util/misc";
3232
import { delay } from "awaiting";
3333
import { Map, Set } from "immutable";
3434
import React from "react";
35+
3536
import {
3637
ReactDOM,
3738
redux,
@@ -290,8 +291,7 @@ export const FrameTree: React.FC<FrameTreeProps> = React.memo(
290291
let name_leaf = name;
291292
let actions_leaf = actions;
292293
if (
293-
typeof spec.name != "string" &&
294-
spec.name?.id === "labels.timetravel" &&
294+
spec.type === "timetravel" &&
295295
!(actions instanceof TimeTravelActions)
296296
) {
297297
if (path_leaf.slice(path_leaf.length - 12) != ".time-travel") {

src/packages/frontend/frame-editors/frame-tree/types.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,68 @@ export type ErrorStyles = undefined | "monospace";
3535

3636
export type ConnectionStatus = "disconnected" | "connected" | "connecting";
3737

38+
// Each editor gets its own unique type. This is useful to check which editor it is.
39+
// e.g. #7787 was caused by merely checking on the name, which had changed.
40+
type EditorType =
41+
| "chat"
42+
| "cm-lean"
43+
| "cm"
44+
| "course-assignments"
45+
| "course-configuration"
46+
| "course-handouts"
47+
| "course-shared_project"
48+
| "course-students"
49+
| "crm-account"
50+
| "crm-tables"
51+
| "csv-grid"
52+
| "errors"
53+
| "iframe"
54+
| "jupyter_json_edit"
55+
| "jupyter_json_view"
56+
| "jupyter-introspect"
57+
| "jupyter-toc"
58+
| "jupyter"
59+
| "latex-build"
60+
| "latex-toc"
61+
| "latex-word_count"
62+
| "latex"
63+
| "lean-help"
64+
| "lean-info"
65+
| "lean-messages"
66+
| "markdown-rendered"
67+
| "markdown-toc"
68+
| "markdown"
69+
| "pdfjs-canvas"
70+
| "preview-html"
71+
| "preview-pdf-canvas"
72+
| "preview-pdf-native"
73+
| "qmd-log"
74+
| "rmd-build"
75+
| "rst-view"
76+
| "sagews-cells"
77+
| "sagews-document"
78+
| "settings"
79+
| "slate"
80+
| "slides-notes"
81+
| "slides-slideshow"
82+
| "slides"
83+
| "slideshow-revealjs"
84+
| "snippets"
85+
| "tasks"
86+
| "terminal-guide"
87+
| "terminal"
88+
| "timetravel"
89+
| "whiteboard-overview"
90+
| "whiteboard-pages"
91+
| "whiteboard-search"
92+
| "whiteboard"
93+
| "wiki"
94+
| "x11-apps"
95+
| "x11"
96+
3897
// Editor spec
3998
export interface EditorDescription {
99+
type: EditorType;
40100
short: string | IntlMessage; // short description of the editor
41101
name: string | IntlMessage; // slightly longer description
42102
icon: IconName;
@@ -67,6 +127,7 @@ export interface EditorDescription {
67127
hide_public?: boolean; // if true, do not show this editor option (in title bar dropdown) when viewing file publicly.
68128
clear_info?: { text: string; confirm: string };
69129
placeholder?: string; // placeholder text to use when empty.
130+
renderer?: "canvas"; // TODO: is this used at all?
70131
}
71132

72133
export interface EditorSpec {

0 commit comments

Comments
 (0)