Skip to content

Commit 670e094

Browse files
Merge pull request #4 from devsentient/fix-jupyter-tab
Fix jupyter tab
2 parents 9f7a68c + 9644e5c commit 670e094

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

frontend/src/routes/jupyter-tab.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,36 @@ function Jupyter() {
77

88
// This is a hack to prevent the editor from overflowing
99
// Should be removed after revising the parent and containers
10+
// Use ResizeObserver to properly track parent width changes
1011
React.useEffect(() => {
12+
let resizeObserver: ResizeObserver | null = null;
13+
14+
resizeObserver = new ResizeObserver((entries) => {
15+
for (const entry of entries) {
16+
// Use contentRect.width for more accurate measurements
17+
const { width } = entry.contentRect;
18+
if (width > 0) {
19+
setParentWidth(width);
20+
}
21+
}
22+
});
23+
1124
if (parentRef.current) {
12-
setParentWidth(parentRef.current.offsetWidth);
25+
resizeObserver.observe(parentRef.current);
1326
}
27+
28+
return () => {
29+
resizeObserver?.disconnect();
30+
};
1431
}, []);
1532

33+
// Provide a fallback width to prevent the editor from being hidden
34+
// Use parentWidth if available, otherwise use a large default
35+
const maxWidth = parentWidth > 0 ? parentWidth : 9999;
36+
1637
return (
1738
<div ref={parentRef} className="h-full">
18-
<JupyterEditor maxWidth={parentWidth} />
39+
<JupyterEditor maxWidth={maxWidth} />
1940
</div>
2041
);
2142
}

frontend/src/services/actions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "#/types/message";
1212
import { handleObservationMessage } from "./observations";
1313
import { appendInput } from "#/state/command-slice";
14+
import { appendJupyterInput } from "#/state/jupyter-slice";
1415
import { queryClient } from "#/query-client-config";
1516

1617
export function handleActionMessage(message: ActionMessage) {
@@ -31,6 +32,10 @@ export function handleActionMessage(message: ActionMessage) {
3132
store.dispatch(appendInput(message.args.command));
3233
}
3334

35+
if (message.action === ActionType.RUN_IPYTHON) {
36+
store.dispatch(appendJupyterInput(message.args.code));
37+
}
38+
3439
if ("args" in message && "security_risk" in message.args) {
3540
store.dispatch(appendSecurityAnalyzerInput(message));
3641
}

0 commit comments

Comments
 (0)