[v2] Connection endpoints: colliding derived ids and no public endpoint/port-owner API

Đang mở
#416 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript

Hướng nghiên cứu

Start with packages/graph/src/store/connection/ConnectionState.ts and ConnectionList.getOrCreateConnection to trace derived IDs and connection reuse. Then inspect the port and connection store APIs and their tests. Done means adding documented, tested endpoint and port-owner APIs and deterministic IDs that distinguish anchor connections across blocks and keep port-only IDs stable; the acceptance criteria also call for follow-up package limitations to be lifted.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

proposal

Problem

TConnection has two addressing modes:

  • Block-based: sourceBlockId / targetBlockId, optionally sourceAnchorId / targetAnchorId. Core resolves these to ports: "<blockId>_output" / "<blockId>_input" for block points, "<blockId>/<anchorId>" for anchors.
  • Port-based: sourcePortId / targetPortId.

Core has two gaps around these modes. Because of them, the extracted packages (#396) cannot treat both modes the same way.

1. Derived connection ids collide

ConnectionState.getConnectionId (packages/graph/src/store/connection/ConnectionState.ts, getConnectionId) builds the id of a connection that has no explicit id:

if (hasId(connection.sourceAnchorId) && hasId(connection.targetAnchorId)) {
  return [connection.sourceAnchorId, connection.targetAnchorId].join(":"); // no block ids
}
return [connection.sourceBlockId, connection.targetBlockId].join(":");

ConnectionList.getOrCreateConnection then reuses whatever state already has that id and calls updateConnection on it.

  • Anchor connections: two connections between different blocks that use the same anchor names get the same id ("out:in"). The second one rewires the first instead of creating a new connection. This happens routinely after duplicating blocks (#408 had to give every copy an explicit id to avoid it).
  • Parallel block connections: they collapse into one ("a:b").
  • Port-only connections: they get a random id, so they cannot be addressed deterministically.
2. No public API to resolve endpoints

Given a ConnectionState or a PortState, there is no public, serializable way to get:

  • the resolved source and target port ids together with the owning block id and anchor id, regardless of which mode the connection was declared in;
  • the block that owns a port. PortState.owner / component is a view component, not store data, and it is absent until the view exists.
  • a connection by its endpoints (store lookup).

Impact

  • @gravity-ui/graph-layered, @gravity-ui/graph-elk: port-only connections are skipped and documented as unsupported, because there is no port → block resolution. Anchor endpoints are not taken into account in layout.
  • @gravity-ui/graph-duplicate-block: port-based connections are copied only when the port id can be derived from block or anchor ids, and copies need explicit ids (see 1).
  • @gravity-ui/graph-connection-editing: decides between block and port mode by comparing port ids with createBlockPointPortId / createAnchorPortId, and dedupes custom-port connections by scanning $connectionsMap.
  • @gravity-ui/graph-playwright: cannot find connections by endpoints or reliably tell apart connections between the same blocks on different anchors. Related: #409.

Proposal (to be refined)

  • Deterministic derived ids that include block ids for anchor connections, e.g. "<sourceBlockId>/<sourceAnchorId>:<targetBlockId>/<targetAnchorId>", and that are stable for port-based connections, e.g. built from the port ids. This is a breaking change for consumers that rely on today's derived ids; it needs a migration note.
  • ConnectionState.getEndpoints(): a serializable { source: { portId, blockId?, anchorId? }, target: { … } }, available without the view.
  • Port owner as store data: a public port → owner block/anchor helper, e.g. connectionsList.getPortOwner(portId) or owner info on PortState.
  • connectionsList.findByEndpoints(...), accepting either mode.

Acceptance criteria

  • Unit tests:
    • two anchor connections with the same anchor names on different blocks stay distinct;
    • parallel connections behave as documented;
    • port-only connections get a stable id.
  • The endpoint and owner APIs work for block, anchor and custom ports, are covered by tests for each mode separately, and are documented.
  • Follow-ups listed for the packages above: lift the documented port-only limitations where the new API makes it possible.
Ngôn ngữ chính
TypeScript
Star
145
Fork
12
Merge trung bình
1 ngày 14 giờ
Pull request đã merge (30 ngày)
43

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của gravity-ui/graph

Tất cả issue của gravity-ui/graph

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.