mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): delete edges when their source or target no longer exists
This commit is contained in:
@ -93,6 +93,16 @@ export const nodesSlice = createSlice({
|
|||||||
reducers: {
|
reducers: {
|
||||||
nodesChanged: (state, action: PayloadAction<NodeChange[]>) => {
|
nodesChanged: (state, action: PayloadAction<NodeChange[]>) => {
|
||||||
state.nodes = applyNodeChanges(action.payload, state.nodes);
|
state.nodes = applyNodeChanges(action.payload, state.nodes);
|
||||||
|
// Remove edges that are no longer valid, due to a removed or otherwise changed node
|
||||||
|
const edgeChanges: EdgeChange[] = [];
|
||||||
|
state.edges.forEach((e) => {
|
||||||
|
const sourceExists = state.nodes.some((n) => n.id === e.source);
|
||||||
|
const targetExists = state.nodes.some((n) => n.id === e.target);
|
||||||
|
if (!(sourceExists && targetExists)) {
|
||||||
|
edgeChanges.push({ type: 'remove', id: e.id });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
state.edges = applyEdgeChanges(edgeChanges, state.edges);
|
||||||
},
|
},
|
||||||
edgesChanged: (state, action: PayloadAction<EdgeChange[]>) => {
|
edgesChanged: (state, action: PayloadAction<EdgeChange[]>) => {
|
||||||
const changes = deepClone(action.payload);
|
const changes = deepClone(action.payload);
|
||||||
|
Reference in New Issue
Block a user