Skip to content

Commit 86e375c

Browse files
author
shuzarevich
committed
chore(connection): implement removal of connection waypoints
- Added RemoveConnectionWaypoint class to handle waypoint removal. - Created RemoveConnectionWaypointRequest class for request structure. - Implemented logic to find connections and update waypoints accordingly. - Emitted connection waypoints changed event after removal.
1 parent cad83b7 commit 86e375c

File tree

4 files changed

+48
-43
lines changed

4 files changed

+48
-43
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export class RemoveConnectionWaypointRequest {
2+
static readonly fToken = Symbol('RemoveConnectionWaypointRequest');
3+
constructor(
4+
public readonly waypointIndex: number,
5+
public readonly connectionId: string,
6+
) {}
7+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { inject, Injectable } from '@angular/core';
2+
import { RemoveConnectionWaypointRequest } from './remove-connection-waypoint-request';
3+
import { FExecutionRegister, IExecution } from '@foblex/mediator';
4+
import { FComponentsStore } from '../../../f-storage';
5+
import { FConnectionBase, FConnectionWaypointsChangedEvent } from '../../../f-connection-v2';
6+
7+
@Injectable()
8+
@FExecutionRegister(RemoveConnectionWaypointRequest)
9+
export class RemoveConnectionWaypoint implements IExecution<RemoveConnectionWaypointRequest, void> {
10+
private readonly _store = inject(FComponentsStore);
11+
12+
public handle({ waypointIndex, connectionId }: RemoveConnectionWaypointRequest): void {
13+
const connection = this._findConnection(connectionId);
14+
15+
const current = connection.fWaypoints()?.waypoints().slice();
16+
if (!current) {
17+
throw new Error('Connection waypoints not found');
18+
}
19+
current.splice(waypointIndex, 1);
20+
21+
connection.fWaypoints()?.waypoints.set(current);
22+
23+
this._store.fDraggable?.fConnectionWaypointsChanged.emit(this._changeEvent(connection));
24+
}
25+
26+
private _findConnection(id: string): FConnectionBase {
27+
const result = this._store.fConnections.find((x) => x.fId() === id);
28+
if (!result) {
29+
throw new Error(`Cannot find connection with id ${id}`);
30+
}
31+
32+
return result;
33+
}
34+
35+
private _changeEvent(connection: FConnectionBase): FConnectionWaypointsChangedEvent {
36+
return new FConnectionWaypointsChangedEvent(
37+
connection.fId(),
38+
connection.fWaypoints()?.waypoints() || [],
39+
);
40+
}
41+
}

projects/f-flow/src/f-draggable/f-connection/move-connection-waypoint/remove-connection-waypoint/remove-connection-waypoint-request.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

projects/f-flow/src/f-draggable/f-connection/move-connection-waypoint/remove-connection-waypoint/remove-connection-waypoint.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)