Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented May 3, 2025

BREAKING CHANGES: some enums have been removed. Use the string counterparts from related types:

  • constants.DIRECTION --> DirectionValue
  • constants.TEXT_DIRECTION --> TextDirectionValue

Notes

Covers #378

Summary by CodeRabbit

  • Refactor

    • Replaced direction and text direction enums with string literals throughout the codebase for consistency and simplicity.
    • Updated type annotations, default values, and constructor parameters to use string-based direction types.
    • Improved inline documentation for text direction type values.
  • Documentation

    • Updated changelog to reflect removal of direction-related enums and their string replacements.
    • Enhanced code comments for clarity on direction and text direction values.
  • Tests

    • Updated tests to use string literals for directions instead of enums.

BREAKING CHANGES: some enums have been removed. Use the string counterparts from related types:
  - `constants.DIRECTION` --> `DirectionValue`
  - `constants.TEXT_DIRECTION` --> `TextDirectionValue`
@tbouffard tbouffard added the refactor Code refactoring label May 3, 2025
@coderabbitai
Copy link

coderabbitai bot commented May 3, 2025

Walkthrough

This change set removes the DIRECTION and TEXT_DIRECTION enums and replaces all their usages throughout the codebase with corresponding string literal values (e.g., 'north', 'south', 'east', 'west', 'auto', 'ltr', 'rtl', and ''). All type annotations, default values, comparisons, and assignments that previously referenced these enums are updated to use string literals or a type alias (DirectionValue or TextDirectionValue). Related documentation, imports, and tests are updated accordingly. No logic or control flow is changed; only the representation of direction and text direction values is modified.

Changes

File(s) Change Summary
CHANGELOG.md Updated "Breaking Changes" section to mention removal of constants.DIRECTION and constants.TEXT_DIRECTION enums, replaced by DirectionValue and TextDirectionValue.
packages/core/src/util/Constants.ts Removed exported enums: DIRECTION (NORTH, SOUTH, EAST, WEST) and TEXT_DIRECTION (DEFAULT, AUTO, LTR, RTL).
packages/core/src/types.ts Updated TextDirectionValue type alias to include inline documentation for each value; no change in allowed values.
packages/core/src/util/mathUtils.ts
packages/core/tests/util/mathUtils.test.ts
Replaced all references to DIRECTION constants with string literals; removed DIRECTION import. No logic changes.
packages/core/src/view/geometry/Shape.ts Replaced all references and initializations using DIRECTION with string literals. Properties gradientDirection, direction, and indicatorDirection now default to 'east'.
packages/core/src/view/geometry/node/SwimlaneShape.ts Replaced DIRECTION enum usage with string literals in direction checks.
packages/core/src/view/geometry/node/TextShape.ts Replaced TEXT_DIRECTION enum usage with string literals. getAutoDirection() now returns string literals. Updated all direction normalization and attribute setting.
packages/core/src/view/geometry/stencil/StencilShape.ts Replaced DIRECTION and TEXT_DIRECTION enum usage with string literals in direction checks and canvas drawing calls.
packages/core/src/view/canvas/AbstractCanvas2D.ts
packages/core/src/view/canvas/SvgCanvas2D.ts
Removed DIRECTION import; replaced enum usage with string literals for gradient direction defaults and comparisons.
packages/core/src/view/layout/HierarchicalLayout.ts
packages/core/src/view/layout/SwimlaneLayout.ts
Changed orientation type from DIRECTION enum to DirectionValue type alias; default value now 'north'. Updated documentation and constructor signatures.
packages/core/src/view/layout/hierarchical/CoordinateAssignment.ts Changed orientation type from DIRECTION enum to DirectionValue; replaced all enum comparisons with string literals. Updated constructor and property types.
packages/core/src/view/style/config.ts Removed DIRECTION import; added allDirections helper returning direction string array. Updated connector config to use string arrays. Cleaned up JSDoc.
packages/core/src/view/style/edge/Loop.ts
packages/core/src/view/style/edge/Manhattan.ts
Replaced all DIRECTION enum usage with string literals in direction checks and defaults.
packages/core/src/view/style/perimeter/HexagonPerimeter.ts
packages/core/src/view/style/perimeter/TrianglePerimeter.ts
Replaced all DIRECTION enum usage with string literals for direction checks and assignments.
packages/core/src/view/mixins/CellsMixin.ts
packages/core/src/view/mixins/ConnectionsMixin.ts
packages/core/src/view/mixins/SwimlaneMixin.ts
Removed DIRECTION import; replaced all references with string literals in direction checks and logic.
packages/core/tests/view/style/config.test.ts Removed DIRECTION import; replaced direction constants with string literals in tests.
packages/html/stories/AutoLayout.stories.ts Removed constants import; replaced constants.DIRECTION.WEST with 'west' in layout instantiation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Shape
    participant Layout
    participant StyleConfig
    participant Canvas2D
    participant TextShape

    User->>Shape: Set direction ('north' | 'south' | 'east' | 'west')
    User->>Layout: Set orientation ('north' | 'south' | 'east' | 'west')
    User->>StyleConfig: Configure connector with directions (string array)
    User->>Canvas2D: Render with gradientDirection ('north' | ...)
    User->>TextShape: Set textDirection ('' | 'auto' | 'ltr' | 'rtl')
    Note right of Shape: All direction logic uses string literals
    Note right of TextShape: All text direction logic uses string literals
Loading
sequenceDiagram
    participant MathUtils
    participant Geometry
    participant Mixins
    participant Tests

    MathUtils->>MathUtils: getPortConstraints(direction: string)
    Geometry->>Geometry: getLabelBounds(direction: string)
    Mixins->>Mixins: getSwimlaneDirection() returns string
    Tests->>Tests: Use string literals in assertions and setup
    Note right of MathUtils: No enums, only string values for directions
Loading

📜 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 01f5667 and 3743f10.

📒 Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • packages/core/__tests__/util/mathUtils.test.ts (13 hunks)
  • packages/core/src/types.ts (1 hunks)
  • packages/core/src/util/Constants.ts (0 hunks)
  • packages/core/src/view/geometry/Shape.ts (9 hunks)
  • packages/core/src/view/geometry/node/TextShape.ts (3 hunks)
💤 Files with no reviewable changes (1)
  • packages/core/src/util/Constants.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/core/tests/util/mathUtils.test.ts
  • CHANGELOG.md
  • packages/core/src/types.ts
  • packages/core/src/view/geometry/Shape.ts
  • packages/core/src/view/geometry/node/TextShape.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (macos-14)
  • GitHub Check: build (ubuntu-22.04)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 3, 2025

@tbouffard tbouffard merged commit 5f0b2f3 into main May 3, 2025
7 checks passed
@tbouffard tbouffard deleted the refactor/378_remove_DIRECTION_and_TEXT_DIRECTION_enums branch May 3, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant