Skip to content

Commit 69362c1

Browse files
committed
widgets: make alert to run it clickable
1 parent 05e5f74 commit 69362c1

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/packages/frontend/jupyter/output-messages/ipywidget.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ ipywidgets rendering using @cocalc/widgets
33
*/
44

55
import { useEffect, useRef, useState } from "react";
6-
import { Alert } from "antd";
6+
import { Icon } from "@cocalc/frontend/components/icon";
7+
import { Alert, Button } from "antd";
78
import type { JupyterActions } from "../browser-actions";
89
import { Map } from "immutable";
910
require("@jupyter-widgets/controls/css/widgets.css");
@@ -26,9 +27,10 @@ interface WidgetProps {
2627
actions?: JupyterActions;
2728
directory?: string;
2829
trust?: boolean;
30+
id?: string;
2931
}
3032

31-
export function IpyWidget({ value, actions }: WidgetProps) {
33+
export function IpyWidget({ id: cell_id, value, actions }: WidgetProps) {
3234
// console.log("IpyWidget", { value: value.toJS(), actions });
3335
const [unknown, setUnknown] = useState<boolean>(false);
3436
const divRef = useRef<any>(null);
@@ -65,12 +67,27 @@ export function IpyWidget({ value, actions }: WidgetProps) {
6567
}, []);
6668

6769
if (unknown) {
70+
const msg = "Run cell to load widget.";
6871
return (
6972
<Alert
7073
showIcon
7174
style={{ margin: "15px" }}
7275
type="warning"
73-
message="Run this cell to load this widget."
76+
message={
77+
actions != null && cell_id ? (
78+
<Button
79+
type="link"
80+
onClick={() => {
81+
console.log("hi", cell_id);
82+
actions.run_cell(cell_id);
83+
}}
84+
>
85+
<Icon name="step-forward" /> {msg}
86+
</Button>
87+
) : (
88+
<span>{msg}</span>
89+
)
90+
}
7491
/>
7592
);
7693
}

src/packages/frontend/jupyter/output-messages/mime-types/widget.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { IpyWidget } from "../ipywidget";
55
register(
66
"application/vnd.jupyter.widget-view+json",
77
10,
8-
({ value, actions }) => {
8+
({ value, actions, id }) => {
99
return (
1010
<div style={{ margin: "15px 0" }}>
11-
<IpyWidget value={value} actions={actions} />
11+
<IpyWidget value={value} actions={actions} id={id} />
1212
</div>
1313
);
1414

0 commit comments

Comments
 (0)