Skip to content

Commit

Permalink
implement custom trigger for rerendering, use it in attach and dettac…
Browse files Browse the repository at this point in the history
…h literals
  • Loading branch information
MFA-X-AI committed Nov 19, 2024
1 parent 2f391ca commit 350257b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/XircuitsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class XircuitsFactory extends ABCWidgetFactory<DocumentWidget> {
runXircuitSignal: Signal<this, any>;
runTypeXircuitSignal: Signal<this, any>;
lockNodeSignal: Signal<this, any>;
triggerCanvasUpdateSignal: Signal<this, any>;
triggerLoadingAnimationSignal: Signal<this, any>;
reloadAllNodesSignal: Signal<this, any>;
toggleAllLinkAnimationSignal: Signal<this, any>;
Expand All @@ -68,6 +69,7 @@ export class XircuitsFactory extends ABCWidgetFactory<DocumentWidget> {
this.runXircuitSignal = new Signal<this, any>(this);
this.runTypeXircuitSignal = new Signal<this, any>(this);
this.lockNodeSignal = new Signal<this, any>(this);
this.triggerCanvasUpdateSignal = new Signal<this, any>(this);
this.triggerLoadingAnimationSignal = new Signal<this, any>(this);
this.reloadAllNodesSignal = new Signal<this, any>(this);
this.toggleAllLinkAnimationSignal = new Signal<this, any>(this);
Expand All @@ -90,6 +92,7 @@ export class XircuitsFactory extends ABCWidgetFactory<DocumentWidget> {
runXircuitSignal: this.runXircuitSignal,
runTypeXircuitSignal: this.runTypeXircuitSignal,
lockNodeSignal: this.lockNodeSignal,
triggerCanvasUpdateSignal: this.triggerCanvasUpdateSignal,
triggerLoadingAnimationSignal: this.triggerLoadingAnimationSignal,
reloadAllNodesSignal: this.reloadAllNodesSignal,
toggleAllLinkAnimationSignal: this.toggleAllLinkAnimationSignal,
Expand Down
3 changes: 3 additions & 0 deletions src/XircuitsWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class XircuitsPanel extends ReactWidget {
runXircuitSignal: Signal<this, any>;
runTypeXircuitSignal: Signal<this, any>;
lockNodeSignal: Signal<this, any>;
triggerCanvasUpdateSignal: Signal<this, any>;
triggerLoadingAnimationSignal: Signal<this, any>;
reloadAllNodesSignal: Signal<this, any>;
toggleAllLinkAnimationSignal: Signal<this, any>;
Expand All @@ -45,6 +46,7 @@ export class XircuitsPanel extends ReactWidget {
this.runXircuitSignal = options.runXircuitSignal;
this.runTypeXircuitSignal = options.runTypeXircuitSignal;
this.lockNodeSignal = options.lockNodeSignal;
this.triggerCanvasUpdateSignal = options.triggerCanvasUpdateSignal;
this.triggerLoadingAnimationSignal = options.triggerLoadingAnimationSignal;
this.reloadAllNodesSignal = options.reloadAllNodesSignal;
this.toggleAllLinkAnimationSignal = options.toggleAllLinkAnimationSignal;
Expand Down Expand Up @@ -97,6 +99,7 @@ export class XircuitsPanel extends ReactWidget {
runXircuitSignal={this.runXircuitSignal}
runTypeXircuitSignal={this.runTypeXircuitSignal}
lockNodeSignal={this.lockNodeSignal}
triggerCanvasUpdateSignal={this.triggerCanvasUpdateSignal}
triggerLoadingAnimationSignal={this.triggerLoadingAnimationSignal}
reloadAllNodesSignal={this.reloadAllNodesSignal}
toggleAllLinkAnimationSignal={this.toggleAllLinkAnimationSignal}
Expand Down
1 change: 1 addition & 0 deletions src/commands/CommandIDs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const commandIDs = {
attachNode: "Xircuit-editor:attach-node",
attachAllNodes: "Xircuit-editor:attach-all-nodes",
detachAllNodes: "Xircuit-editor:detach-all-nodes",
triggerCanvasUpdate: "Xircuit-editor:trigger-canvas-update",
triggerLoadingAnimation: "Xircuit-editor:trigger-loading-animation",
reloadNode: "Xircuit-editor:reload-node",
reloadAllNodes: "Xircuit-editor:reload-all-nodes",
Expand Down
10 changes: 7 additions & 3 deletions src/commands/NodeActionCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1011,9 +1011,11 @@ export function addNodeActionCommands(
node.getOptions().extras.attached = true;
let parameterOutPort = node.getOutPorts()[0] as CustomPortModel;
let connectedNodes = parameterOutPort.getTargetNodes();
connectedNodes.forEach((node: CustomNodeModel) => node.setSelected(true))
connectedNodes.forEach((node: CustomNodeModel) => node.setSelected(true));

});
widget.xircuitsApp.getDiagramEngine().repaintCanvas();
widget.triggerCanvasUpdateSignal.emit(null);
},
label: trans.__('attach node')
});
Expand Down Expand Up @@ -1044,10 +1046,11 @@ export function addNodeActionCommands(
literal_nodes.forEach(node => {
let parameterOutPort = node.getOutPorts()[0] as CustomPortModel;
let connectedNodes = parameterOutPort.getTargetNodes();
connectedNodes.forEach((node: CustomNodeModel) => node.setSelected(true))
connectedNodes.forEach((node: CustomNodeModel) => node.setSelected(true));
});

widget.xircuitsApp.getDiagramEngine().repaintCanvas();
widget.triggerCanvasUpdateSignal.emit(null);
},
label: trans.__('attach all nodes')
});
Expand Down Expand Up @@ -1078,10 +1081,11 @@ export function addNodeActionCommands(
literal_nodes.forEach(node => {
let parameterOutPort = node.getOutPorts()[0] as CustomPortModel;
let connectedNodes = parameterOutPort.getTargetNodes();
connectedNodes.forEach((node: CustomNodeModel) => node.setSelected(true))
connectedNodes.forEach((node: CustomNodeModel) => node.setSelected(true));
});

widget.xircuitsApp.getDiagramEngine().repaintCanvas();
widget.triggerCanvasUpdateSignal.emit(null);
},
label: trans.__('detach all nodes')
});
Expand Down
9 changes: 9 additions & 0 deletions src/components/XircuitsBodyWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface BodyWidgetProps {
runXircuitSignal: Signal<XircuitsPanel, any>;
runTypeXircuitSignal: Signal<XircuitsPanel, any>;
lockNodeSignal: Signal<XircuitsPanel, any>;
triggerCanvasUpdateSignal: Signal<XircuitsPanel, any>;
triggerLoadingAnimationSignal: Signal<XircuitsPanel, any>;
reloadAllNodesSignal: Signal<XircuitsPanel, any>;
toggleAllLinkAnimationSignal: Signal<XircuitsPanel, any>;
Expand Down Expand Up @@ -88,6 +89,7 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
runXircuitSignal,
runTypeXircuitSignal,
lockNodeSignal,
triggerCanvasUpdateSignal,
triggerLoadingAnimationSignal,
reloadAllNodesSignal,
toggleAllLinkAnimationSignal,
Expand Down Expand Up @@ -660,6 +662,12 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
}
});
}
const handleTriggerCanvasUpdate = async () => {
if (shell.currentWidget?.id !== widgetId) {
return;
}
onChange();
};

const handleReloadAll = async () => {
if (shell.currentWidget?.id !== widgetId) {
Expand Down Expand Up @@ -868,6 +876,7 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
[runXircuitSignal, handleRunClick],
[fetchRemoteRunConfigSignal, getRemoteRunTypeFromConfig],
[lockNodeSignal, handleLockClick],
[triggerCanvasUpdateSignal, handleTriggerCanvasUpdate],
[triggerLoadingAnimationSignal, triggerLoadingAnimation],
[reloadAllNodesSignal, handleReloadAll],
[toggleAllLinkAnimationSignal, handleToggleAllLinkAnimation],
Expand Down
3 changes: 0 additions & 3 deletions src/context-menu/CanvasContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@ export class CanvasContextMenu extends React.Component<CanvasContextMenuProps> {

const handleAttachNode = async () => {
await this.props.app.commands.execute(commandIDs.attachNode);
await this.props.app.commands.execute(commandIDs.reloadNode);
};

const handleAllAttachNodes = async () => {
await this.props.app.commands.execute(commandIDs.attachAllNodes);
await this.props.app.commands.execute(commandIDs.reloadNode);
};

const handleDetachAllNodes = async () => {
await this.props.app.commands.execute(commandIDs.detachAllNodes);
await this.props.app.commands.execute(commandIDs.reloadNode);
};

return (
Expand Down
4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ const xircuits: JupyterFrontEndPlugin<void> = {
{execute: emitSignal(widgetFactory.compileXircuitSignal)}],
[commandIDs.fetchRemoteRunConfig,
{execute: emitSignal(widgetFactory.fetchRemoteRunConfigSignal)}],
[commandIDs.lockXircuit,
[commandIDs.lockXircuit,
{execute: emitSignal(widgetFactory.lockNodeSignal)}],
[commandIDs.triggerCanvasUpdate,
{execute: emitSignal(widgetFactory.triggerCanvasUpdateSignal)}],
[commandIDs.triggerLoadingAnimation,
{execute: emitSignal(widgetFactory.triggerLoadingAnimationSignal)}],
[commandIDs.reloadAllNodes,
Expand Down

0 comments on commit 350257b

Please sign in to comment.