Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove useBpmnModeler #14464

Merged
merged 3 commits into from
Jan 21, 2025
Merged

refactor: Remove useBpmnModeler #14464

merged 3 commits into from
Jan 21, 2025

Conversation

TomasEng
Copy link
Contributor

@TomasEng TomasEng commented Jan 21, 2025

Description

The useBpmnModeler function is named and used as a React hook, although it's not a hook (it doesn't depend on any other hooks). It's just a wrapper around the static BpmnModelerInstance class, so we can just use the class directly. I have therefore deleted useBpmnModeler.

I have added the skip-manual-testing label since this is just a refactor and the automated tests should be sufficient to verify this change.

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)

Summary by CodeRabbit

  • Refactor

    • Updated BPMN modeler instance management to use a centralized singleton pattern
    • Removed useBpmnModeler hook and related test files
    • Simplified modeler initialization and destruction process
  • Breaking Changes

    • Components previously using useBpmnModeler hook will need to be updated
    • Modeler instance management now handled differently

Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Warning

Rate limit exceeded

@TomasEng has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 44 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d317919 and b8c0f88.

📒 Files selected for processing (1)
  • frontend/packages/process-editor/src/hooks/useBpmnEditor.ts (3 hunks)
📝 Walkthrough

Walkthrough

The pull request introduces significant changes to the BPMN modeler management in the process editor. The modifications involve removing the useBpmnModeler hook and its associated files, and updating the useBpmnEditor hook to use a centralized BpmnModelerInstance for managing the modeler lifecycle. The changes shift from a custom hook approach to a singleton pattern for handling BPMN modeler instances, potentially simplifying the overall instance management strategy.

Changes

File Change Summary
frontend/packages/process-editor/src/hooks/useBpmnEditor.ts Updated to use BpmnModelerInstance.getInstance(div) instead of getModeler(div), and BpmnModelerInstance.destroyInstance() for cleanup
frontend/.../useBpmnModeler/index.ts Deleted export file for useBpmnModeler hook
frontend/.../useBpmnModeler/useBpmnModeler.test.ts Deleted test file for useBpmnModeler hook
frontend/.../useBpmnModeler/useBpmnModeler.ts Deleted custom hook implementation

Possibly related PRs

Suggested reviewers

  • github-actions
  • ErlingHauan

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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

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. (Beta)
  • @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.

@github-actions github-actions bot added area/process Area: Related to app process (e.g. signing, receipt, fill inn, payment, etc). solution/studio/designer Issues related to the Altinn Studio Designer solution. frontend labels Jan 21, 2025
@TomasEng TomasEng added team/studio-domain1 team/studio-core skip-releasenotes Issues that do not make sense to list in our release notes skip-manual-testing PRs that do not need to be tested manually skip-documentation Issues where updating documentation is not relevant labels Jan 21, 2025
@TomasEng TomasEng added the quality/code Violations from current rules for code, best practices, etc. Or just bad code. label Jan 21, 2025
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.68%. Comparing base (3fabf1f) to head (b8c0f88).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14464      +/-   ##
==========================================
- Coverage   95.68%   95.68%   -0.01%     
==========================================
  Files        1891     1889       -2     
  Lines       24588    24579       -9     
  Branches     2822     2822              
==========================================
- Hits        23528    23519       -9     
  Misses        799      799              
  Partials      261      261              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TomasEng TomasEng marked this pull request as ready for review January 21, 2025 08:41
Copy link
Contributor

@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)
frontend/packages/process-editor/src/hooks/useBpmnEditor.ts (2)

101-101: Consider updating the comment to reflect the singleton pattern.

The change to use BpmnModelerInstance.getInstance is good, but the comment above could be updated to better explain the singleton pattern and why multiple instances should be avoided.

-    // GetModeler can only be fetched from this hook once since the modeler creates a
-    // new instance and will attach the same canvasRef container to all instances it fetches.
+    // BpmnModelerInstance follows the singleton pattern to ensure only one instance exists.
+    // Multiple instances would cause issues as they would attach to the same canvasRef container.

Line range hint 101-114: Well-structured refactoring to singleton pattern.

The transition from useBpmnModeler hook to BpmnModelerInstance singleton is well-executed. This architectural change:

  1. Better reflects the single-instance nature of the BPMN modeler
  2. Maintains the same initialization and cleanup flow
  3. Removes unnecessary React hook abstraction

The refactoring improves code clarity without changing the core functionality.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6ec1b07 and d317919.

📒 Files selected for processing (4)
  • frontend/packages/process-editor/src/hooks/useBpmnEditor.ts (3 hunks)
  • frontend/packages/process-editor/src/hooks/useBpmnModeler/index.ts (0 hunks)
  • frontend/packages/process-editor/src/hooks/useBpmnModeler/useBpmnModeler.test.ts (0 hunks)
  • frontend/packages/process-editor/src/hooks/useBpmnModeler/useBpmnModeler.ts (0 hunks)
💤 Files with no reviewable changes (3)
  • frontend/packages/process-editor/src/hooks/useBpmnModeler/index.ts
  • frontend/packages/process-editor/src/hooks/useBpmnModeler/useBpmnModeler.test.ts
  • frontend/packages/process-editor/src/hooks/useBpmnModeler/useBpmnModeler.ts
🔇 Additional comments (2)
frontend/packages/process-editor/src/hooks/useBpmnEditor.ts (2)

3-3: LGTM! Import statement aligns with the refactoring goal.

The import of BpmnModelerInstance from utils is properly structured and aligns with the PR's objective of removing the useBpmnModeler hook.


114-114: Verify cleanup implementation in BpmnModelerInstance.

The change to use BpmnModelerInstance.destroyInstance is appropriate. Let's verify the implementation ensures proper cleanup.

✅ Verification successful

✓ Cleanup implementation is correct

The destroyInstance() implementation properly cleans up resources by detaching the BPMN.js modeler and clearing the instance reference.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the destroyInstance implementation
ast-grep --pattern 'class BpmnModelerInstance {
  $$$
  static destroyInstance() {
    $$$
  }
  $$$
}'

Length of output: 105


Script:

#!/bin/bash
# Find the file containing BpmnModelerInstance
fd BpmnModelerInstance frontend/packages/process-editor/src

# Once found, examine its content
fd BpmnModelerInstance frontend/packages/process-editor/src -x cat {}

Length of output: 1597

Copy link
Contributor

@standeren standeren left a comment

Choose a reason for hiding this comment

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

👏

@TomasEng TomasEng merged commit 9aa2d6f into main Jan 21, 2025
11 checks passed
@TomasEng TomasEng deleted the remove-use-bpmn-modeler branch January 21, 2025 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/process Area: Related to app process (e.g. signing, receipt, fill inn, payment, etc). frontend quality/code Violations from current rules for code, best practices, etc. Or just bad code. skip-documentation Issues where updating documentation is not relevant skip-manual-testing PRs that do not need to be tested manually skip-releasenotes Issues that do not make sense to list in our release notes solution/studio/designer Issues related to the Altinn Studio Designer solution. team/studio-core team/studio-domain1
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants