Skip to content

Commit

Permalink
invalidate selected node IDs when loading
Browse files Browse the repository at this point in the history
  • Loading branch information
sc420 committed Mar 4, 2024
1 parent 2eb8486 commit ead602f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ const GraphContainer: FunctionComponent<GraphContainerProps> = ({

const selectedNodeIds = params.nodes.map((node) => node.id);

coreGraphAdapter.updateSelectedNodes(selectedNodeIds);
coreGraphAdapter.updateSelectedNodeIds(selectedNodeIds);

setReactFlowNodes((nodes) =>
updateReactFlowNodeHighlighted(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ describe("events", () => {

adapter.onExplainDerivativeDataUpdated(explainDerivativeDataUpdated);

adapter.updateSelectedNodes(["1"]);
adapter.updateSelectedNodeIds(["1"]);

const firstCallArgs = explainDerivativeDataUpdated.mock.calls[0];
const data = firstCallArgs[0];
Expand All @@ -435,7 +435,7 @@ describe("events", () => {

adapter.onExplainDerivativeDataUpdated(explainDerivativeDataUpdated);

adapter.updateSelectedNodes(["1"]);
adapter.updateSelectedNodeIds(["1"]);

const expectedData: ExplainDerivativeData[] = [];
expect(explainDerivativeDataUpdated).toHaveBeenCalledWith(expectedData);
Expand All @@ -451,7 +451,7 @@ describe("behavior", () => {
addConnection(adapter, "1", "2", "a");

adapter.setTargetNode("1");
adapter.updateSelectedNodes(["1"]);
adapter.updateSelectedNodeIds(["1"]);

const edges = buildReactFlowEdges([["1", "2", "a"]]);
// Should remove edge first
Expand Down
21 changes: 11 additions & 10 deletions interactive-computational-graph/src/features/CoreGraphAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ cycle`;

if (hasRemovedNodes) {
this.updateTargetNode();
this.updateSelectedNodeIds();
this.selectedNodeIds = this.getExistingSelectedNodeIdsByGraph();

this.updateOutputs();
}
Expand Down Expand Up @@ -334,12 +334,6 @@ cycle`;
this.emitTargetNodeUpdated();
}

private updateSelectedNodeIds(): void {
this.selectedNodeIds = this.selectedNodeIds.filter((selectedNodeId) =>
this.graph.hasNode(selectedNodeId),
);
}

changeEdges(changes: EdgeChange[], edges: Edge[]): void {
const removeEdges = this.findEdgesToRemove(changes, edges);

Expand Down Expand Up @@ -447,7 +441,7 @@ cycle`;
);
}

updateSelectedNodes(selectedNodeIds: string[]): void {
updateSelectedNodeIds(selectedNodeIds: string[]): void {
this.selectedNodeIds = selectedNodeIds;

this.updateExplainDerivativeData();
Expand All @@ -459,7 +453,8 @@ cycle`;
if (targetNodeId === null) {
explainDerivativeData = [];
} else {
explainDerivativeData = this.selectedNodeIds.map(
const existingSelectedNodeIds = this.getExistingSelectedNodeIdsByGraph();
explainDerivativeData = existingSelectedNodeIds.map(
(nodeId): ExplainDerivativeData => {
const nodeName = this.getNodeNameById(nodeId);
const explainDerivativeType = this.getExplainDerivativeType(nodeId);
Expand Down Expand Up @@ -511,6 +506,12 @@ cycle`;
return "someValueBecauseChainRule";
}

private getExistingSelectedNodeIdsByGraph(): string[] {
return this.selectedNodeIds.filter((selectedNodeId) =>
this.graph.hasNode(selectedNodeId),
);
}

getVisibleNodeNames(): string[] {
return this.getVisibleNodeIds().map((nodeId) =>
this.getNodeNameById(nodeId),
Expand Down Expand Up @@ -569,6 +570,7 @@ cycle`;
this.dummyInputNodeIdToNodeIds = new Map(
Object.entries(state.dummyInputNodeIdToNodeIds),
);
this.selectedNodeIds = [];
}

private connectDummyInputNode(nodeId: string, portId: string): void {
Expand Down Expand Up @@ -726,7 +728,6 @@ cycle`;

this.graph.updateFValues();
this.graph.updateDerivatives();
this.updateExplainDerivativeData();
}

private loadGraphNodes(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type ReactFlowJsonObject } from "reactflow";
import type CoreGraphAdapterState from "./CoreGraphAdapterState";
import type FeatureOperationState from "./FeatureOperationState";
import type NodeNameBuilderState from "./NodeNameBuilderState";
Expand All @@ -18,7 +19,7 @@ interface GraphContainerState {
operationIdsAddedAtLeastOnce: string[];

// React Flow states
reactFlowState: object;
reactFlowState: ReactFlowJsonObject;
}

export default GraphContainerState;

0 comments on commit ead602f

Please sign in to comment.