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

Abierto
#416 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
typescript

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
TypeScript
Estrellas
145
Forks
12
Merge medio
1 d 14 h
PR fusionados (30 d)
43

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de gravity-ui/graph

Todos los issues de gravity-ui/graph

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.