Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented May 3, 2025

Introduce the DialectValue type.

BREAKING CHANGES: the DIALECT enum has been removed. Use the DialectValue type instead.

Notes

Covers #378

Summary by CodeRabbit

  • Breaking Changes
    • Removed the DIALECT enum constant. All dialect assignments and checks now use string literals (e.g., 'svg', 'strictHtml').
  • New Features
    • Introduced a new type, DialectValue, representing valid dialect string values.
  • Refactor
    • Updated all references to dialects throughout the application to use string literals or the new DialectValue type.
    • Improved type annotations for dialect properties in several classes for better type safety.
  • Documentation
    • Updated the changelog to reflect the removal of constants.DIALECT and its replacement with DialectValue.

Introduce the `DialectValue` type.

BREAKING CHANGES: the DIALECT enum has been removed. Use the `DialectValue` type instead.
@tbouffard tbouffard added the refactor Code refactoring label May 3, 2025
@coderabbitai
Copy link

coderabbitai bot commented May 3, 2025

Walkthrough

The changes remove the DIALECT enum and its usage throughout the codebase, replacing all references to dialect values with string literals. A new type alias, DialectValue, is introduced to represent the set of allowed dialect strings. All type annotations and assignments that previously used the DIALECT enum are updated to use either the DialectValue type or direct string literals. Documentation and comments referencing the removed enum are also updated. No changes are made to logic, control flow, or exported function signatures, except for type annotation updates to use DialectValue.

Changes

File(s) Change Summary
CHANGELOG.md Updated the "Unreleased" section to note the removal of constants.DIALECT, instructing to use DialectValue instead. Minor formatting adjustments.
packages/core/src/types.ts Added exported type alias DialectValue representing the allowed dialect string literals.
packages/core/src/util/Constants.ts Removed the exported DIALECT enum and its string constants.
packages/core/src/view/AbstractGraph.ts Replaced explicit union type for dialect property with imported DialectValue type; updated JSDoc.
packages/core/src/view/geometry/Shape.ts Changed type annotation of dialect property from `string
packages/core/src/view/geometry/node/TextShape.ts Removed DIALECT import; replaced all DIALECT.STRICTHTML references with 'strictHtml' string literal in dialect checks.
packages/core/src/util/xmlUtils.ts Removed DIALECT import; replaced DIALECT.SVG with 'svg' in conditional checks.
packages/core/src/view/cell/CellHighlight.ts Removed DIALECT import; replaced DIALECT.SVG with 'svg' in assignments and checks.
packages/core/src/view/cell/CellRenderer.ts Removed DIALECT import; replaced all enum references with equivalent string literals ('svg', 'strictHtml', 'preferHtml').
packages/core/src/view/cell/VertexHandle.ts Removed DIALECT import; replaced enum values with string literals ('strictHtml', 'mixedHtml', 'svg') in shape dialect assignments.
packages/core/src/view/handler/ConstraintHandler.ts Removed DIALECT import; replaced enum values with string literals ('svg', 'mixedHtml') in highlight and icon shape assignments.
packages/core/src/view/handler/EdgeHandler.ts Removed DIALECT import; replaced enum values with string literals ('svg', 'mixedHtml', 'strictHtml') in shape dialect assignments.
packages/core/src/view/handler/VertexHandler.ts Removed DIALECT import; replaced enum values with string literals ('svg', 'strictHtml', 'mixedHtml') in selection, sizer, preview, and highlight shape assignments.
packages/core/src/view/other/Guide.ts Removed DIALECT import; replaced DIALECT.SVG with 'svg' in guide shape dialect assignments.
packages/core/src/view/other/PrintPreview.ts Removed DIALECT import; replaced dialect check with direct string comparison to 'svg'.
packages/core/src/view/plugins/CellEditorHandler.ts Removed DIALECT import; replaced DIALECT.STRICTHTML with 'strictHtml' in dialect check.
packages/core/src/view/plugins/ConnectionHandler.ts Removed DIALECT import; replaced enum values with string literals ('svg', 'strictHtml') in shape and icon dialect assignments.
packages/core/src/view/plugins/SelectionHandler.ts Removed DIALECT import; replaced enum values with string literals ('strictHtml', 'svg') in preview shape dialect assignments.
packages/html/stories/SecondLabel.stories.js Replaced constants.DIALECT.STRICTHTML with 'strictHtml' in dialect assignment for secondLabel TextShape.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant AbstractGraph
    participant Shape

    Client->>AbstractGraph: Set dialect property (DialectValue)
    AbstractGraph->>Shape: Pass dialect as DialectValue string
    Shape-->>Client: Uses dialect for rendering logic
Loading
sequenceDiagram
    participant Renderer
    participant Shape

    Renderer->>Shape: Assign dialect ('svg', 'strictHtml', etc. as string)
    Shape->>Renderer: Render shape based on dialect string
Loading
✨ 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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/core/src/view/handler/EdgeHandler.ts (1)

674-674: Consistent mixed/html dialect logic
The bend initialization uses the same ternary expression as the main selection shape. Consider extracting this into a helper if used frequently.

packages/core/src/view/handler/VertexHandler.ts (1)

488-488: Consistent mixedHtml/svg logic for sizers
Uses the same ternary as elsewhere: graph.dialect !== 'svg' ? 'mixedHtml' : 'svg'. Consider DRYing this up into a helper.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between be08b14 and 11c1c12.

📒 Files selected for processing (19)
  • CHANGELOG.md (1 hunks)
  • packages/core/src/types.ts (1 hunks)
  • packages/core/src/util/Constants.ts (0 hunks)
  • packages/core/src/util/xmlUtils.ts (2 hunks)
  • packages/core/src/view/AbstractGraph.ts (2 hunks)
  • packages/core/src/view/cell/CellHighlight.ts (1 hunks)
  • packages/core/src/view/cell/CellRenderer.ts (6 hunks)
  • packages/core/src/view/cell/VertexHandle.ts (1 hunks)
  • packages/core/src/view/geometry/Shape.ts (2 hunks)
  • packages/core/src/view/geometry/node/TextShape.ts (7 hunks)
  • packages/core/src/view/handler/ConstraintHandler.ts (2 hunks)
  • packages/core/src/view/handler/EdgeHandler.ts (3 hunks)
  • packages/core/src/view/handler/VertexHandler.ts (5 hunks)
  • packages/core/src/view/other/Guide.ts (3 hunks)
  • packages/core/src/view/other/PrintPreview.ts (1 hunks)
  • packages/core/src/view/plugins/CellEditorHandler.ts (1 hunks)
  • packages/core/src/view/plugins/ConnectionHandler.ts (2 hunks)
  • packages/core/src/view/plugins/SelectionHandler.ts (1 hunks)
  • packages/html/stories/SecondLabel.stories.js (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/core/src/util/Constants.ts
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/core/src/view/geometry/Shape.ts (1)
packages/core/src/types.ts (1)
  • DialectValue (1454-1462)
packages/core/src/view/geometry/node/TextShape.ts (1)
packages/core/src/util/domUtils.ts (1)
  • isNode (223-238)
packages/core/src/view/AbstractGraph.ts (1)
packages/core/src/types.ts (1)
  • DialectValue (1454-1462)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build
  • GitHub Check: build (macos-14)
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (ubuntu-22.04)
🔇 Additional comments (47)
packages/core/src/view/other/PrintPreview.ts (1)

805-805: String literal replaces DIALECT enum value correctly.

The string literal 'svg' is now directly used for the dialect check instead of the removed DIALECT.SVG enum value. This change aligns with the broader refactoring of removing the DIALECT enum throughout the codebase.

packages/core/src/view/plugins/CellEditorHandler.ts (1)

731-731: String literal 'strictHtml' replaces DIALECT enum value correctly.

The string literal 'strictHtml' is properly used for dialect comparison instead of the removed DIALECT.STRICTHTML enum value. This maintains the same functionality while adhering to the new type system using string literals.

packages/core/src/util/xmlUtils.ts (2)

19-19: DIALECT import correctly removed.

The import statement has been updated to remove the DIALECT import, keeping only the necessary constants. This helps clean up imports as part of the enum removal refactoring.


66-66: String literal replaces DIALECT enum value correctly.

The dialect check now uses the string literal 'svg' instead of the enum value, maintaining the same conditional logic while adhering to the refactoring approach.

packages/core/src/view/other/Guide.ts (3)

19-19: DIALECT import correctly removed.

The import statement has been properly updated to remove the DIALECT enum import, keeping only the necessary constants from the Constants file.


186-186: String literal used for dialect assignment.

The direct string literal 'svg' is now used for setting the dialect property instead of using the enum value. This implementation is consistent with the broader refactoring to remove the DIALECT enum.


225-225: String literal used for dialect assignment.

Similar to the previous instance, the string literal 'svg' is correctly used to set the dialect property on the vertical guide shape, maintaining consistency across the codebase.

packages/html/stories/SecondLabel.stories.js (1)

135-135: Dialect replacement correctly implemented.

The change from constants.DIALECT.STRICTHTML to the string literal 'strictHtml' properly implements the refactoring to remove the DIALECT enum as described in the PR objectives.

CHANGELOG.md (1)

14-17: Appropriate documentation of breaking changes.

The changelog has been properly updated to inform users about the removal of the DIALECT enum and its replacement with the new DialectValue type. This documentation is essential for users to migrate their code correctly.

packages/core/src/view/cell/CellHighlight.ts (2)

171-171: Correctly replaced enum with string literal.

The DIALECT.SVG enum usage has been appropriately replaced with the string literal 'svg'.


175-175: Dialect comparison properly updated.

The conditional check comparing this.graph.dialect to DIALECT.SVG has been correctly updated to use the string literal 'svg'.

packages/core/src/view/plugins/SelectionHandler.ts (2)

709-709: Enum replaced with appropriate string literal.

The DIALECT.STRICTHTML enum value has been correctly replaced with the string literal 'strictHtml'.


715-715: SVG dialect reference properly updated.

The DIALECT.SVG enum value has been correctly replaced with the string literal 'svg'.

packages/core/src/view/cell/VertexHandle.ts (2)

207-207: String literal 'strictHtml' replaces DIALECT enum usage.

The code now uses the string literal 'strictHtml' instead of the removed DIALECT.STRICTHTML enum value. This change aligns with the new DialectValue type introduced in the types.ts file.


210-210: String literals replace DIALECT enum in conditional assignment.

The code now uses string literals 'svg' and 'mixedHtml' instead of DIALECT.SVG and DIALECT.MIXEDHTML enum values in this conditional expression. This change is consistent with the PR objective of removing the DIALECT enum.

packages/core/src/view/handler/ConstraintHandler.ts (2)

323-323: String literal 'svg' replaces DIALECT.SVG enum usage.

The code now correctly uses the string literal 'svg' instead of the removed DIALECT.SVG enum value when setting the dialect property on the highlight shape.


418-418: String literals replace DIALECT enum in conditional assignment for icon dialect.

The code now uses string literals 'svg' and 'mixedHtml' instead of DIALECT.SVG and DIALECT.MIXEDHTML enum values when determining the icon dialect. This change is consistent with the removal of the DIALECT enum.

packages/core/src/types.ts (1)

1451-1462: Good addition of DialectValue type alias to replace DIALECT enum.

The new DialectValue type alias is well-documented with appropriate JSDoc comments for each variant. This type alias provides a clear replacement for the removed DIALECT enum, making it a type-safe alternative that uses string literals.

The values 'mixedHtml', 'preferHtml', 'strictHtml', and 'svg' correctly match the string literals now being used throughout the codebase. This creates a centralized type definition that can be imported where needed.

packages/core/src/view/geometry/Shape.ts (2)

42-42: Import DialectValue type from types module.

The code correctly imports the new DialectValue type from the types module. This import is necessary to apply the type to the dialect property.


149-149: Update dialect property type to use DialectValue.

The type annotation for the dialect property has been updated from string | null to DialectValue | null. This improves type safety by ensuring only valid dialect values can be assigned to this property.

packages/core/src/view/handler/EdgeHandler.ts (3)

245-245: Ensure valid dialect assignment
Replaces the old DIALECT enum with string literals. Confirm that 'mixedHtml' and 'svg' are included in the new DialectValue union so there are no type errors.


362-362: Verify parent highlight dialect
The parentHighlight is now forced to 'svg'. Ensure this matches the intended behavior for event transparency in IE and that no VML fallback is needed.


671-671: Use new string literal for HTML dialect
Assigning 'strictHtml' directly replaces the former enum constant. Confirm that this value is accepted by Shape.dialect and aligns with other HTML-rendered handles.

packages/core/src/view/cell/CellRenderer.ts (6)

379-379: Replace enum with string literal for text dialect
Assigns state.text.dialect to either 'strictHtml' or the current graph.dialect. Confirm that both branches satisfy the new DialectValue type.


420-420: Updated forceGetCell conditional
Switches from enum comparison to string literal check (graph.dialect !== 'svg'). Verify this logic covers all previous enum cases and doesn’t introduce regressions in touch handling.


461-461: Preserve SVG vs HTML label initialization
Replaces enum check with a literal comparison on shape.dialect. Behavior is unchanged; approve.


655-655: Removed enum in isForceHtml check
Uses graph.dialect === 'svg' instead of DIALECT.SVG. Confirm no side effects in environments where VML was previously used.


658-658: Use 'preferHtml' literal for control dialect
Assigns the new DialectValue 'preferHtml' to the folding icon. Ensure this matches the type alias and is handled correctly in rendering.


841-841: Standardize label redraw dialect
Replaces enum with literal in the label redraw path. Logical behavior remains the same.

packages/core/src/view/handler/VertexHandler.ts (6)

20-20: Removed DIALECT import; using literals
Now imports only CURSOR and NONE. All dialect references use string literals, so the enum is no longer needed.


228-228: Force selection border to use SVG dialect
Sets selectionBorder.dialect = 'svg' for IE transparency. Verify that IE support is still appropriate and that no VML case is required.


485-485: Assign strictHtml to sizer when using HTML labels
Replaces the enum constant for HTML mode with 'strictHtml'. Confirm HandleConfig interactions remain correct.


697-697: Use strictHtml for preview when required
Switches from enum to 'strictHtml'. Approved as equivalent behavior.


700-700: Default preview dialect to SVG
Sets preview.dialect = 'svg' in the non-HTML branch. Matches prior logic.


1983-1983: Replace enum in parent highlight with string literal
Sets parentHighlight.dialect = 'svg' for IE. Ensure this change continues to meet the original requirement.

packages/core/src/view/plugins/ConnectionHandler.ts (3)

506-506: String literal replaces enum constant.

The use of the string literal 'svg' directly instead of DIALECT.SVG is part of the broader refactor to remove the DIALECT enum. This ensures consistency with the new approach using the DialectValue type.


637-637: String literal replaces enum constant for HTML dialect.

Using 'strictHtml' directly in place of DIALECT.STRICTHTML aligns with the refactoring approach. This change maintains the same functionality while simplifying the code.


640-640: String literal replaces enum constant for SVG dialect.

Similar to the other dialect changes, using 'svg' directly here is consistent with the PR's overall goal of removing the DIALECT enum.

packages/core/src/view/geometry/node/TextShape.ts (7)

252-252: String literal replaces enum reference for HTML dialect check.

Using the string literal 'strictHtml' directly instead of the DIALECT.STRICTHTML enum value maintains the same functionality while simplifying the code.


310-310: String literal replaces enum reference in caching condition.

The condition now uses the string literal 'strictHtml' directly, which is consistent with the refactoring approach to remove the DIALECT enum.


330-330: String literal replaces enum reference in value caching check.

The condition logic remains the same while using the string literal 'strictHtml' instead of the enum value, aligning with the refactoring approach.


576-576: String literal replaces enum reference in HTML encoding condition.

The negation check now uses the string literal 'strictHtml' directly, maintaining the same functionality as before.


700-700: String literal replaces enum reference in HTML value update condition.

The condition uses 'strictHtml' directly, maintaining the same encoding logic as before.


726-726: String literal replaces enum reference in HTML entity encoding condition.

The condition now uses the string literal 'strictHtml' directly while maintaining the same logic for determining when to apply HTML entity encoding.


772-772: String literal replaces enum reference in text direction condition.

The condition for determining text direction now uses the string literal 'strictHtml' directly, maintaining the same logic as before.

packages/core/src/view/AbstractGraph.ts (2)

48-48: Import type alias instead of using direct string union.

The code now imports the DialectValue type from the types file, which is a more maintainable approach than using inline string unions.


146-146: Use type alias for dialect property.

The dialect property's type annotation has been updated to use the imported DialectValue type alias instead of an inline string union. This improves code maintainability and consistency across the codebase.

@tbouffard tbouffard merged commit 0557ca6 into main May 3, 2025
7 checks passed
@tbouffard tbouffard deleted the refactor/378-remove_DIALECT_enum branch May 3, 2025 17:50
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