Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Jul 16, 2025

These legacy methods have a large number of parameters, are hard to read and hard to evolve.

So, to prepare the deprecation of these methods, use the new methods that take a single object parameter in code, examples and documentation.
The storybook stories will be updated later.

Also simplify some calls by not always setting the parent when it was set to the default parent (this is the default
value, so no need to pass it in this case), nor setting an empty string value (same result as not setting it).

In addition, apply various JSDoc improvements.

Notes

Covers #856

Summary by CodeRabbit

  • Documentation

    • Updated all code examples and documentation to use a new object-based parameter style for insertVertex and insertEdge methods, replacing the previous positional argument approach.
    • Clarified npm package compatibility, specifying ES2020 standard and support for both CommonJS and ES Module formats.
    • Enhanced documentation on default cell styles and introduced the ignoreDefaultStyle flag.
    • Added important usage notes about vertex position and size requirements.
    • Improved and modernized code snippets, added important usage notes, and enhanced formatting for clarity.
  • Refactor

    • Refactored test and example code to adopt the new object-based API for graph element insertion, simplifying usage and improving consistency.
  • Style

    • Modernized example code syntax throughout documentation and comments for better readability and maintainability.

These legacy methods have a large number of parameters, are hard to read and hard to evolve.

So, to prepare the deprecation of these methods, use the new methods that take a single object parameter in code, examples and documentation.
The storybook stories will be updated later.

Also simplify some calls by not always setting the parent when it was set to the default parent (this is the default
value, so no need to pass it in this case), nor setting an empty string value (same result as not setting it).

In addition, apply various JSDoc improvements.
@tbouffard tbouffard added the refactor Code refactoring label Jul 16, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 16, 2025

Walkthrough

This update refactors the usage of insertVertex and insertEdge methods throughout the codebase, tests, and documentation to use a new object-based parameter style instead of legacy positional arguments. It also modernizes example code syntax, clarifies documentation, and updates type comments for improved clarity and consistency without changing core logic or exported APIs.

Changes

File(s) Change Summary
README.md, packages/website/docs/getting-started.mdx, packages/website/docs/manual/model-and-transactions.md, packages/website/docs/tutorials/the-hello-world-example.md, packages/website/docs/manual/cells.md Updated documentation and code examples to use object-based parameter style for insertVertex/insertEdge, clarified compatibility, and modernized syntax.
packages/ts-example/src/main.ts Refactored all vertex and edge insertions to use object-based API, removed explicit parent management.
packages/core/tests/view/layout/HierarchicalLayout.test.ts, packages/core/tests/view/image/ImageExport.test.ts Updated tests to use object-based API for inserting vertices and edges.
packages/core/tests/view/mixins/EdgeMixin.test.ts, packages/core/tests/view/mixins/VertexMixin.test.ts Clarified test descriptions to indicate legacy method coverage, no logic change.
packages/core/src/editor/Editor.ts, packages/core/src/view/cell/Cell.ts, packages/core/src/util/gestureUtils.ts, packages/core/src/view/mixins/CellsMixin.type.ts, packages/core/src/view/mixins/VertexMixin.type.ts, packages/core/src/view/handler/VertexHandler.ts Updated documentation comments and examples to use object-based API and modern JavaScript syntax.
packages/core/src/types.ts Clarified type comments for VertexParameters regarding fallback behavior for position and size properties.
packages/core/src/view/layout/SwimlaneLayout.ts Refactored dummy vertex insertion to use object-based API.
packages/core/src/view/plugins/ConnectionHandler.ts Updated JSDoc links and changed edge insertion to object-based API in implementation.
packages/core/src/view/GraphDataModel.ts Improved JSDoc with @default, made types explicit, and improved type safety in method implementations.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Graph
  participant Model

  User->>Graph: insertVertex({ value, position, size, ... })
  Graph->>Model: add vertex with parameters from object
  Model-->>Graph: vertex instance
  Graph-->>User: created vertex

  User->>Graph: insertEdge({ value, source, target, ... })
  Graph->>Model: add edge with parameters from object
  Model-->>Graph: edge instance
  Graph-->>User: created edge
Loading
sequenceDiagram
  participant Docs
  participant Developer

  Docs-->>Developer: Example: insertVertex({ value, position, size, style })
  Docs-->>Developer: Example: insertEdge({ value, source, target, style })
  Developer->>Graph: Uses new object-based API as per documentation
Loading

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-16T17_02_26_600Z-debug-0.log


📜 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 a35f512 and 812e883.

📒 Files selected for processing (3)
  • packages/core/src/editor/Editor.ts (1 hunks)
  • packages/core/src/view/mixins/CellsMixin.type.ts (1 hunks)
  • packages/website/docs/manual/cells.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/website/docs/manual/cells.md
  • packages/core/src/editor/Editor.ts
  • packages/core/src/view/mixins/CellsMixin.type.ts
✨ 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.
    • 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.

@tbouffard tbouffard marked this pull request as ready for review July 16, 2025 16:24
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: 1

🧹 Nitpick comments (2)
packages/core/src/editor/Editor.ts (1)

286-294: Showcase the leaner call by omitting parent when it’s the default.

Since the surrounding paragraph explains that the new API relieves the caller from passing the default parent, the example could be further simplified:

-const parent = editor.graph.getDefaultParent();
 ...
-editor.graph.insertVertex({parent, value: userObject, position: [20, 20], size: [80, 30]});
+editor.graph.insertVertex({value: userObject, position: [20, 20], size: [80, 30]});

Not critical, but it keeps the documentation perfectly aligned with the stated goal of the refactor.

packages/website/docs/manual/cells.md (1)

112-120: Typo: replace “ommited” with “omitted”.

-    baseStyleNames: ['defaultVertex'], // This can be ommited, as it is the default style applied for vertices
+    baseStyleNames: ['defaultVertex'], // This can be omitted, as it is the default style applied for vertices

@sonarqubecloud
Copy link

@tbouffard tbouffard merged commit af6c3be into main Jul 20, 2025
7 checks passed
@tbouffard tbouffard deleted the refactor/remove_ref_to_legacy_insert_cell_methods branch July 20, 2025 15:09
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