Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Mar 20, 2025

Previously, the properties only accept a single DIRECTION enum value. It wasn't possible to pass a string related to the DirectionValue type, it generated a TypeScript error.
In addition, it is now possible to pass several values, as this was possible in mxGraph. This is what the Orthogonal story requires for example.

For backward compatibility, the implementation still supports the former mxGraph configuration where the directions were passed as a concatenated string. This ensures that the mxGraph XML models can be correctly loaded.

About 20 tests have been added to validate the existing implementation.

Tasks

  • update the mxGraph migration guide

Summary by CodeRabbit

  • Enhancements
    • Improved graph styling with enhanced configuration options for connection constraints, offering more flexible visual customization.
  • Documentation
    • Updated the migration guide to reflect the new approach for specifying port constraints using arrays instead of strings.

Previously, the properties only accept a single DIRECTION enum value. It wasn't possible to pass a string related to
the DirectionValue type, it generated a TS error.
In addition, it is now possible to pass several values, as this was possible in mxGraph. This is what the Orthogonal
story requires for example.

For backward compatibility, the implementation still support the former mxGraph configuration where the directions were
passed as a concatenated string. This ensures that the mxGraph XML models can be correctly loaded.

About 20 tests have been added to validate the implementation.
@tbouffard tbouffard added the enhancement New feature or request label Mar 20, 2025
@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2025

Walkthrough

This pull request updates the XML serialization tests by adding a new edge element and enhancing vertex styling with a portConstraint attribute. A new test suite for the getPortConstraints function has been introduced to cover various constraint scenarios and rotations. Additionally, type definitions in CellStateStyle have been updated to use a new flexible type for port constraints, and the implementation of getPortConstraints has been refined with improved documentation, corrected parameter types, and streamlined logic.

Changes

File(s) Change Summary
packages/core/__tests__/serialization/serialization.xml.mxGraph.test.ts Updated XML structure in tests: added portConstraint to vertex (id "2"), introduced new edge element (id "3") with specified style properties, increased expected cell count, and added corresponding assertions.
packages/core/__tests__/util/mathUtils.test.ts Added a comprehensive test suite for getPortConstraints covering scenarios for null constraints, precedence between terminal and edge styles, array handling, rotation cases, and legacy support for mxGraph models.
packages/core/src/types.ts Updated type definition: changed portConstraint, sourcePortConstraint, and targetPortConstraint from DIRECTION to StylePortConstraint; added new type StylePortConstraint to allow a single or array of DirectionValue.
packages/core/src/util/mathUtils.ts Refined getPortConstraints: revised documentation, corrected parameter types from CelState to CellState, removed unnecessary null coalescing, and streamlined the initialization of the rotation variable.
packages/website/docs/usage/migrate-from-mxgraph.md Updated documentation on "port constraint" properties to clarify that they should now be passed as arrays instead of strings.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Suite
    participant F as getPortConstraints Function
    participant Term as Terminal State
    participant Edge as Edge State

    T->>F: Invoke getPortConstraints(terminal, edge, source, defaultValue)
    F->>Term: Retrieve port constraint from terminal
    F->>Edge: Retrieve port constraint from edge
    F-->>T: Return computed port constraint mask based on constraints and rotation settings
Loading

Suggested labels

refactor


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e63348f and a9763de.

📒 Files selected for processing (4)
  • packages/core/__tests__/util/mathUtils.test.ts (1 hunks)
  • packages/core/src/types.ts (4 hunks)
  • packages/core/src/util/mathUtils.ts (2 hunks)
  • packages/website/docs/usage/migrate-from-mxgraph.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/core/src/util/mathUtils.ts
  • packages/core/src/types.ts
🧰 Additional context used
🧬 Code Definitions (1)
packages/core/__tests__/util/mathUtils.test.ts (2)
packages/core/src/util/mathUtils.ts (1)
  • getPortConstraints (216-323)
packages/core/src/types.ts (1)
  • DirectionValue (906-906)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (windows-2022)
🔇 Additional comments (8)
packages/website/docs/usage/migrate-from-mxgraph.md (1)

558-561: Documentation clearly explains the port constraints change.

The documentation effectively explains that port constraint properties now accept arrays instead of strings for specifying multiple constraints, which aligns with the implementation changes. This is important for users migrating from mxGraph to maxGraph.

packages/core/__tests__/util/mathUtils.test.ts (7)

18-21: Proper imports for the new test suite.

The imports correctly include all necessary dependencies for testing the getPortConstraints function.


23-38: Good baseline tests for null constraints.

The initial tests correctly verify the function's behavior when port constraints are null, ensuring the default value is properly returned.


40-74: Tests verify correct constraint precedence.

These tests effectively validate that:

  1. Terminal constraints take precedence over edge constraints
  2. The function correctly falls back to source/target port constraints when needed

This ensures proper behavior in various scenarios when constraints are defined at different levels.


76-89: Good use of parameterized tests for single directions.

The test.each approach is efficient for testing all individual direction values and their corresponding masks.


90-145: Comprehensive tests for array-based constraints.

These tests thoroughly verify the new functionality of using arrays for port constraints:

  1. On terminal styles
  2. On edge source/target styles
  3. Precedence rules with arrays

This is a core part of the PR implementation and these tests ensure it works correctly.


147-251: Rotation tests cover all important cases.

The rotation tests thoroughly validate:

  1. Basic 90° rotation behavior
  2. Default rotation handling (0°)
  3. Disabling rotation with portConstraintRotation=false
  4. 180° rotation
  5. Negative rotations (-90°, -135°, -180°)

These tests ensure port constraints work correctly with different rotation angles, which is important for UI elements that can be rotated.


253-277: Good backward compatibility tests.

The legacy support tests verify that the implementation maintains compatibility with mxGraph XML models, where directions were specified as concatenated strings (e.g., "northsouth"). This ensures existing models can be loaded without issues.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tbouffard tbouffard marked this pull request as draft March 20, 2025 08:17
@tbouffard tbouffard marked this pull request as ready for review March 25, 2025 15:35
@sonarqubecloud
Copy link

@tbouffard tbouffard merged commit 86b3d18 into main Mar 25, 2025
7 checks passed
@tbouffard tbouffard deleted the feat/type_cellstyle_portConstraint_allow_multiple_directions branch March 25, 2025 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant