Skip to content

refactor: migrate the Orthogonal story to TypeScript#835

Merged
tbouffard merged 2 commits intomainfrom
refactor/story_orthogonal_to_TS
May 26, 2025
Merged

refactor: migrate the Orthogonal story to TypeScript#835
tbouffard merged 2 commits intomainfrom
refactor/story_orthogonal_to_TS

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented May 26, 2025

Ease the maintenance and detect errors earlier.
Add a description at the container to explain to the user what the story does.

Summary by CodeRabbit

  • Documentation
    • Updated the source code link in the orthogonal projection example to reference the TypeScript version.
  • Refactor
    • Improved code modularity and clarity in the orthogonal projection example, with enhanced handling of plugin behaviors and type safety.

Ease the maintenance and detect errors earlier.
Add a description at the container to explain to the user what the story does.
@tbouffard tbouffard added the refactor Code refactoring label May 26, 2025
@coderabbitai
Copy link

coderabbitai bot commented May 26, 2025

Walkthrough

The changes refactor the orthogonal projection story to improve modularity by introducing helper functions, explicit plugin handling, and safer type usage. The story's setup logic is restructured, and method overrides are made more robust. Documentation is updated to reference the TypeScript version of the source code for consistency.

Changes

File(s) Change Summary
packages/html/stories/Orthogonal.stories.ts Refactored for modularity: introduced helper functions, explicit plugin handling, method overrides, and improved type safety.
packages/website/docs/usage/perimeters.md Updated documentation link to point to the TypeScript source file instead of JavaScript.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Storybook
    participant Template
    participant Graph
    participant Plugins

    User->>Storybook: Select Orthogonal story
    Storybook->>Template: Render with args
    Template->>Graph: Initialize graph with helper functions
    Template->>Plugins: Retrieve and override plugin methods
    Plugins->>Graph: Modify behavior (guides, edge handling, snapping)
    Template->>Graph: Add vertices and edges with updated logic
    Graph-->>Template: Rendered graph with orthogonal projection
Loading

Possibly related PRs

  • maxGraph/maxGraph#681: Refactors code and updates configurations related to the Manhattan connector, involving similar modularity improvements.
  • maxGraph/maxGraph#656: Updates and clarifies orthogonal projection and perimeter handling, directly related to changes in the orthogonal story and documentation.
  • maxGraph/maxGraph#684: Extracts Orthogonal and Manhattan connectors and adjusts related properties, overlapping with edge style and connector logic refactoring.

📜 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 dc7939a and aa46f41.

📒 Files selected for processing (1)
  • packages/website/docs/usage/perimeters.md (1 hunks)
🔇 Additional comments (1)
packages/website/docs/usage/perimeters.md (1)

95-95: Correct link to TypeScript source
The URL now correctly points to Orthogonal.stories.ts, matching the migrated TypeScript story file.


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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

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: 2

🧹 Nitpick comments (2)
packages/html/stories/Orthogonal.stories.ts (2)

50-56: Good TypeScript migration with improved user context.

The function signature provides type safety and the description helps users understand the story's purpose, aligning with the PR objectives.

Consider defining a more specific interface for the args parameter in the future to improve type safety:

interface OrthogonalStoryArgs {
  label?: string;
  rubberBand?: boolean;
  // ... other specific properties
}

140-190: Consider safer geometry access patterns.

While geometry is typically set after vertex creation, using non-null assertions throughout could hide potential issues.

Consider adding runtime checks or using optional chaining for safer access:

if (v11.geometry) {
  v11.geometry.offset = new Point(-5, -5);
}
// or
v11.geometry?.offset = new Point(-5, -5);

This pattern would make the code more robust against unexpected null/undefined values.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c72ac6e and dc7939a.

📒 Files selected for processing (2)
  • packages/html/stories/Orthogonal.stories.ts (6 hunks)
  • packages/website/docs/usage/perimeters.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (windows-2022)
🔇 Additional comments (3)
packages/html/stories/Orthogonal.stories.ts (3)

19-35: Well-organized imports for TypeScript migration.

The imports are properly structured with all necessary types and utilities for the TypeScript implementation.


59-63: Excellent plugin management refactoring.

The explicit plugin handling with getDefaultPlugins() and conditional addition improves modularity and maintainability.


180-190: Good use of framework utilities.

Using cellArrayUtils.cloneCell instead of direct cloning follows framework patterns and improves maintainability.

Comment on lines +114 to 117
connectionHandler.createEdgeState = function (_me) {
const edge = graph.createEdge(null, null!, null, null, null);
return new CellState(this.graph.view, edge, this.graph.getCellStyle(edge));
};
Copy link

@coderabbitai coderabbitai bot May 26, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid using non-null assertion operator with null.

Using null! bypasses TypeScript's null safety checks and could lead to runtime errors if the method expects a non-null value.

Consider using undefined or providing a default value:

-    const edge = graph.createEdge(null, null!, null, null, null);
+    const edge = graph.createEdge(null, null, null, null, null);

If the second parameter truly cannot be null, investigate what value should be provided instead.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
connectionHandler.createEdgeState = function (_me) {
const edge = graph.createEdge(null, null!, null, null, null);
return new CellState(this.graph.view, edge, this.graph.getCellStyle(edge));
};
connectionHandler.createEdgeState = function (_me) {
const edge = graph.createEdge(null, null, null, null, null);
return new CellState(this.graph.view, edge, this.graph.getCellStyle(edge));
};
🤖 Prompt for AI Agents
In packages/html/stories/Orthogonal.stories.ts between lines 114 and 117, the
code uses the non-null assertion operator `null!` which bypasses TypeScript's
null safety checks and may cause runtime errors. Remove the `!` and replace
`null!` with an appropriate value such as `undefined` or a valid default that
aligns with the method's expected parameter type. If the parameter cannot be
null or undefined, determine the correct value to pass instead of `null!`.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thx, this will be managed later. Another story needs it too.

Copy link

Choose a reason for hiding this comment

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

@tbouffard Thanks for the clarification! Since this pattern affects multiple stories, would you like me to create a follow-up issue to track removing the null! assertions across all the affected stories? This would help ensure it gets addressed systematically in a future PR.


✏️ Learnings added
Learnt from: tbouffard
PR: maxGraph/maxGraph#835
File: packages/html/stories/Orthogonal.stories.ts:114-117
Timestamp: 2025-05-26T12:34:54.306Z
Learning: The `null!` assertion pattern exists across multiple stories in the TypeScript migration and should be addressed systematically rather than in individual PRs.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented May 26, 2025

Quality Gate Passed Quality Gate passed

Issues
0 New issues
3 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@tbouffard tbouffard merged commit d72c910 into main May 26, 2025
2 checks passed
@tbouffard tbouffard deleted the refactor/story_orthogonal_to_TS branch May 26, 2025 12: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