Skip to content

feat: add web zoom to help widget #1893

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

Merged
merged 1 commit into from
Feb 1, 2025
Merged

feat: add web zoom to help widget #1893

merged 1 commit into from
Feb 1, 2025

Conversation

oneirocosm
Copy link
Member

The web widget already had a zoom feature, but the help widget did not. This change ports the zoom feature so it is available on the help widget as well.

The web widget already had a zoom feature, but the help widget did not.
This change ports the zoom feature so it is available on the help widget
as well.
Copy link
Contributor

coderabbitai bot commented Feb 1, 2025

Walkthrough

The pull request introduces enhancements to the HelpViewModel class in the helpview.tsx file, focusing on zoom functionality for a web view. A new method setZoomFactor is implemented to manage the zoom level, allowing dynamic adjustment within a range of 0.1 to 5. The method handles setting zoom levels, including a null input which resets to a default zoom level.

The getSettingsMenuItems method is updated to include a zoom factor submenu with options ranging from 25% to 200%. This modification enables users to interactively adjust the web view's zoom level through a context menu. The implementation checks the current zoom level and marks the corresponding menu item as selected.

The changes involve updating import statements to include necessary types and clients, likely supporting the new zoom functionality in the help view interface.


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.

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/app/view/helpview/helpview.tsx (2)

64-81: LGTM with a minor suggestion for readability.

The zoom factor implementation is robust with proper input validation, DOM readiness check, and persistence.

Consider extracting the zoom limits as named constants for better readability and maintainability:

+const MIN_ZOOM_FACTOR = 0.1;
+const MAX_ZOOM_FACTOR = 5;
+const DEFAULT_ZOOM_FACTOR = 1;

 setZoomFactor(factor: number | null) {
     // null is ok (will reset to default)
-    if (factor != null && factor < 0.1) {
-        factor = 0.1;
+    if (factor != null && factor < MIN_ZOOM_FACTOR) {
+        factor = MIN_ZOOM_FACTOR;
     }
-    if (factor != null && factor > 5) {
-        factor = 5;
+    if (factor != null && factor > MAX_ZOOM_FACTOR) {
+        factor = MAX_ZOOM_FACTOR;
     }
     const domReady = globalStore.get(this.domReady);
     if (!domReady) {
         return;
     }
-    this.webviewRef.current?.setZoomFactor(factor || 1);
+    this.webviewRef.current?.setZoomFactor(factor || DEFAULT_ZOOM_FACTOR);
     RpcApi.SetMetaCommand(TabRpcClient, {
         oref: WOS.makeORef("block", this.blockId),
         meta: { "web:zoom": factor }, // allow null so we can remove the zoom factor here
     });
 }

Line range hint 84-135: LGTM with a minor suggestion for maintainability.

The zoom menu implementation is well-structured with a good range of zoom levels and proper handling of the current zoom state.

Consider extracting the zoom levels into a configuration array for better maintainability:

+const ZOOM_LEVELS = [
+    { label: "25%", factor: 0.25 },
+    { label: "50%", factor: 0.5 },
+    { label: "70%", factor: 0.7 },
+    { label: "80%", factor: 0.8 },
+    { label: "90%", factor: 0.9 },
+    { label: "100%", factor: 1 },
+    { label: "110%", factor: 1.1 },
+    { label: "120%", factor: 1.2 },
+    { label: "130%", factor: 1.3 },
+    { label: "150%", factor: 1.5 },
+    { label: "175%", factor: 1.75 },
+    { label: "200%", factor: 2 },
+];

 getSettingsMenuItems(): ContextMenuItem[] {
     const zoomSubMenu: ContextMenuItem[] = [];
     let curZoom = 1;
     if (globalStore.get(this.domReady)) {
         curZoom = this.webviewRef.current?.getZoomFactor() || 1;
     }
     const model = this;
     function makeZoomFactorMenuItem(label: string, factor: number): ContextMenuItem {
         return {
             label: label,
             type: "checkbox",
             click: () => {
                 model.setZoomFactor(factor);
             },
             checked: curZoom == factor,
         };
     }
     zoomSubMenu.push({
         label: "Reset",
         click: () => {
             model.setZoomFactor(null);
         },
     });
-    zoomSubMenu.push(makeZoomFactorMenuItem("25%", 0.25));
-    zoomSubMenu.push(makeZoomFactorMenuItem("50%", 0.5));
-    zoomSubMenu.push(makeZoomFactorMenuItem("70%", 0.7));
-    zoomSubMenu.push(makeZoomFactorMenuItem("80%", 0.8));
-    zoomSubMenu.push(makeZoomFactorMenuItem("90%", 0.9));
-    zoomSubMenu.push(makeZoomFactorMenuItem("100%", 1));
-    zoomSubMenu.push(makeZoomFactorMenuItem("110%", 1.1));
-    zoomSubMenu.push(makeZoomFactorMenuItem("120%", 1.2));
-    zoomSubMenu.push(makeZoomFactorMenuItem("130%", 1.3));
-    zoomSubMenu.push(makeZoomFactorMenuItem("150%", 1.5));
-    zoomSubMenu.push(makeZoomFactorMenuItem("175%", 1.75));
-    zoomSubMenu.push(makeZoomFactorMenuItem("200%", 2));
+    ZOOM_LEVELS.forEach(({ label, factor }) => {
+        zoomSubMenu.push(makeZoomFactorMenuItem(label, factor));
+    });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8cd35c4 and 379466f.

📒 Files selected for processing (1)
  • frontend/app/view/helpview/helpview.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Build for TestDriver.ai
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
frontend/app/view/helpview/helpview.tsx (1)

5-7: LGTM!

The new imports are necessary for the RPC functionality used in the zoom feature implementation.

@oneirocosm oneirocosm merged commit 1a70c83 into main Feb 1, 2025
8 checks passed
@oneirocosm oneirocosm deleted the sylvie/help-zoom branch February 1, 2025 02:11
xxyy2024 pushed a commit to xxyy2024/waveterm_aipy that referenced this pull request Jun 24, 2025
The web widget already had a zoom feature, but the help widget did not.
This change ports the zoom feature so it is available on the help widget
as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant