ls1intum / Apollon

UML Modeling Editor written in React
https://apollon-library.readthedocs.io
MIT License
61 stars 21 forks source link

add support for remote selection #323

Closed loreanvictor closed 7 months ago

loreanvictor commented 7 months ago

Checklist

Motivation and Context

A common feature of realtime collaboration is highlighting elements and relationships selected by some other collaborator. Currently this is implemented via a selectedBy property on elements, which has the downside that this ephemeral state will be persisted alongside the diagram, potentially leading to corrupt diagram data (a collaborator marked as selecting an element might not be present anymore).

It is notable that currently highlighting relationships selected by a remote collaborator is not possible as well.

Description

This PR will add a property to model state, independent of the exported diagram, called remoteSelection, alongside two new APIs for Apollon:

remoteSelect(selectorName: string, selectorColor: string, select: string[], deselect?: string[])

👆 This method highlights given elements and relationships, for given collaborator (marked by their name and color), or removes their corresponding highlighting from given deselected elements.

pruneRemoteSelectors(allowedSelectors: { name: string; color: string }[])

👆 This method removes any remote selector not in the allowed list.

Steps for Testing

  1. Clone Apollon_standalone and switch to this PR
  2. Ensure /diagrams folder exists (btw this should be added to the README of standalone).
  3. Link local Apollon
  4. Run Apollon_standalone and test realtime collaboration.

You should:

Test Coverage

File Branch Line
apollon-editor.ts 80.39% 84%
components/model-state.ts 97.05% 90.86%
components/uml-element/canvas-element.tsx 40% 76.12%
components/uml-element/canvas-relationship.tsx 55% 67.63%
services/uml-element/remote-selectable/remote-selection-reducer.ts 100% 100%
services/uml-element/remote-selectable/remote-selection-repository.ts 100% 100%

Screenshots

ezgif com-video-to-gif-3

matthiaslehnertum commented 7 months ago

Nice Documentation! Could you update the base branch just to make sure Tests still go through then? Otherwise good to go from my side!