Skip to content

Commit 010e4c1

Browse files
committed
Auto arrange node in the first time
1 parent 9fce42b commit 010e4c1

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
strategy:
3333
max-parallel: 4
3434
matrix:
35-
python-version: ['3.9', '3.10', '3.11']
35+
python-version: ['3.10', '3.11', '3.12']
3636

3737
steps:
3838
- uses: actions/checkout@v4

js/rete_utils.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ export async function loadJSON(editor, area, layout, workgraphData) {
8888
}
8989

9090
// Adding connections based on workgraphData
91-
workgraphData.links.forEach(async (link: LinkData) => { // Specify the type of link here
91+
for (const link of workgraphData.links) {
9292
await addLink(editor, area, layout, link);
93-
});
93+
}
9494

9595
// Add while zones
9696
console.log("Adding while zone: ");
@@ -172,6 +172,20 @@ export async function removeNode(editor, name) {
172172
});
173173
}
174174

175+
export async function clearEditor(editor) {
176+
const connections = editor.getConnections();
177+
for (const connection of connections) {
178+
await editor.removeConnection(connection.id);
179+
}
180+
181+
const nodes = editor.getNodes();
182+
for (const node of nodes) {
183+
await editor.removeNode(node.id);
184+
}
185+
186+
editor.nodeMap = {};
187+
}
188+
175189
/**
176190
* Defines custom padding for a scope layout.
177191
* The padding values are used by the ScopesPlugin to avoid node overlapping with the socket of the parent node.

js/widget.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from "react";
22
import { Button, Switch } from "antd";
33
import { createRender, useModel, useModelState } from "@anywidget/react";
4-
import { createEditor, loadJSON, removeNode, addNode, addLink, removeLink } from "./rete_utils";
4+
import { createEditor, loadJSON, removeNode, addNode, addLink, removeLink, clearEditor } from "./rete_utils";
55
import "./widget.css";
66

77
export function useRete<T extends { destroy(): void }>(
@@ -154,13 +154,20 @@ const render = createRender(() => {
154154
console.log("Editor not ready");
155155
return;
156156
};
157-
// same uuid skip
158-
if (editor.editor.uuid && editor.editor.uuid === value.uuid) {
159-
console.log("Same uuid, skip");
157+
if (!value) {
160158
return;
161159
}
162-
loadJSON(editor.editor, editor.area, editor.layout, value);
163-
}, [isInitialized, value]);
160+
const incomingUuid = value?.uuid;
161+
const applyValue = async () => {
162+
await clearEditor(editor.editor);
163+
await loadJSON(editor.editor, editor.area, editor.layout, value);
164+
if (incomingUuid) {
165+
editor.editor.uuid = incomingUuid;
166+
}
167+
await editor.layout(true);
168+
};
169+
applyValue();
170+
}, [editor, isInitialized, value]);
164171

165172
return (
166173
<div className="App">

tests/notebooks/tests/widgets.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ test.describe('Widget Visual Regression', () => {
2929

3030
await page.notebook.runCellByCell({
3131
onAfterCellRun: async (cellIndex: number) => {
32+
await page.waitForTimeout(3000); // Wait for 3 second before retrying
3233
let cell = await page.notebook.getCellOutput(cellIndex);
3334
const startTime = Date.now();
3435
const timeout = 60000; // Timeout in milliseconds, adjust as necessary

0 commit comments

Comments
 (0)