fix: delete connectors by ID instead of index in scene

This fixes a critical bug where connectors weren't being properly removed from the scene when deleted, as the code was using array index instead of connector ID as the key.
This commit is contained in:
Stan
2025-09-07 09:31:00 +01:00
parent 70b1f560a2
commit 67f0dde932
2 changed files with 4 additions and 7 deletions

View File

@@ -97,10 +97,8 @@ describe('connector reducer', () => {
// Check connector is removed from model
expect(result.model.views[0].connectors).toHaveLength(0);
// Check connector is removed from scene
// NOTE: The implementation uses connector.index instead of connector.id
// This appears to be a bug - it should delete by ID not index
expect(result.scene.connectors[0]).toBeUndefined();
// Check connector is removed from scene by ID
expect(result.scene.connectors['connector1']).toBeUndefined();
});
it('should throw error when connector does not exist', () => {
@@ -144,8 +142,7 @@ describe('connector reducer', () => {
expect(result.model.views[0].connectors).toHaveLength(1);
expect(result.model.views[0].connectors![0].id).toBe('connector2');
expect(result.scene.connectors['connector2']).toBeDefined();
// NOTE: Bug - implementation deletes by index (0) not ID
expect(result.scene.connectors[0]).toBeUndefined();
expect(result.scene.connectors['connector1']).toBeUndefined();
});
});

View File

@@ -12,7 +12,7 @@ export const deleteConnector = (
const newState = produce(state, (draft) => {
draft.model.views[view.index].connectors?.splice(connector.index, 1);
delete draft.scene.connectors[connector.index];
delete draft.scene.connectors[id];
});
return newState;