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(web): plugin playground presets - camera position #1415

Merged
merged 3 commits into from
Feb 10, 2025

Conversation

OpeDada
Copy link
Contributor

@OpeDada OpeDada commented Feb 10, 2025

Overview

I added a show Info section to this plugin to guide user on how to use the plugin

What I've done

Screenshot 2025-02-10 at 9 52 11 AM

What I haven't done

How I tested

Locally

Which point I want you to review particularly

If this feature is necessary or not

Memo

Summary by CodeRabbit

  • New Features
     - Introduced an enhanced information panel that provides clear usage instructions and offers toggle functionality for a more intuitive experience.

  • Style
     - Updated the visual layout with a sticky information section and refined control styling, including optimized spacing, to improve overall usability.

  • Functionality
     - Improved interaction behavior, ensuring action buttons are enabled only when appropriate inputs are provided.

Copy link

coderabbitai bot commented Feb 10, 2025

Walkthrough

This change refactors the camera position plugin in the web application. The YAML-defined widget layout is removed and replaced with an HTML info-section that provides user instructions. CSS adjustments introduce a sticky info-section, reduced padding for camera controls, and new styles for the info-toggle and info-content. JavaScript logic now adds a checkInputs function with event listeners to control the apply button state and refines message handling by verifying camera position changes before triggering a fly-to action. New variables (yamlFile and widgetFile) have been introduced, and the exported cameraPosition entity is updated.

Changes

File(s) Summary
web/.../cameraPosition.ts Removed widgetLayout from YAML; added an HTML info-section with sticky CSS; adjusted .camera-controls padding; introduced #info-toggle and #info-content styles; implemented checkInputs for apply-btn state; refined extension message handling; added new variables (yamlFile, widgetFile) and updated export of cameraPosition.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant IF as Input Field
    participant CI as checkInputs Function
    participant AB as Apply Button
    U->>IF: Enter camera position
    IF->>CI: Trigger input event
    CI->>AB: Enable/disable based on input values
Loading
sequenceDiagram
    participant E as Extension
    participant CP as Camera Plugin
    participant IF as Input Field
    participant FT as Fly-to Action
    E->>CP: Send new camera position message
    CP->>IF: Update input fields (if manual input inactive)
    CP->>CP: Validate position change
    CP->>FT: Trigger fly-to action (if changed)
Loading

Possibly related PRs

Suggested labels

web

Suggested reviewers

  • mkumbobeaty
  • airslice
  • mulengawilfred

Poem

I'm a rabbit on a code-filled spree,
Hopping through changes with glee.
The info-section sticks up high,
While inputs and toggles smoothly fly.
With a joyful skip, the changes sing—
Code bounces and leaps, let the fun begin!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

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

netlify bot commented Feb 10, 2025

Deploy Preview for reearth-web ready!

Name Link
🔨 Latest commit 111ce65
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/67a94de39852d80008bad289
😎 Deploy Preview https://deploy-preview-1415--reearth-web.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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 (4)
web/src/beta/features/PluginPlayground/Plugins/presets/camera/cameraPosition.ts (4)

34-39: Consider improving info section contrast.

The info section uses a light gray background (#eee) which might not provide sufficient contrast for optimal readability.

    #info-section {
      position: sticky;
      top: 0;
-     background: #eee;
+     background: #e0e0e0;
      text-align: left;
    }

100-105: Improve status message flexibility.

The fixed height of 4px might truncate longer status messages. Consider using min-height instead.

    .status-message {
      text-align: center;
      color: #666;
-     height: 4px;
+     min-height: 4px;
      padding: 4px;
    }

297-300: Extract position change threshold as a constant.

The floating-point comparison threshold should be defined as a named constant for better maintainability.

+    const POSITION_CHANGE_THRESHOLD = 0.0001;
     const isPositionChanged = Object.keys(params).some(key =>
     //Use a tolerance threshold to compare floating-point values
-      Math.abs((currentPosition[key] || 0) - (params[key] || 0)) > 0.0001
+      Math.abs((currentPosition[key] || 0) - (params[key] || 0)) > POSITION_CHANGE_THRESHOLD

302-309: Consider adding a small transition duration.

A duration of 0 results in an instant camera movement which might be disorienting. Consider adding a small duration for smoother transitions.

     if (isPositionChanged) {
       reearth.camera.flyTo(
         params,
         {
-          duration: 0,
+          duration: 0.3, // Add a short duration for smoother transition
           easing: (t) => t * t
         }
       );
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7b5acd and 111ce65.

📒 Files selected for processing (1)
  • web/src/beta/features/PluginPlayground/Plugins/presets/camera/cameraPosition.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Redirect rules - reearth-web
  • GitHub Check: Header rules - reearth-web
  • GitHub Check: ci-server / ci-server-test
  • GitHub Check: Pages changed - reearth-web
  • GitHub Check: ci-server / ci-server-lint
  • GitHub Check: ci-web / ci
🔇 Additional comments (2)
web/src/beta/features/PluginPlayground/Plugins/presets/camera/cameraPosition.ts (2)

1-2: LGTM! Well-structured plugin configuration.

The file structure follows TypeScript best practices with proper typing and clear organization of plugin components.

Also applies to: 4-18, 20-24, 320-324


7-15: LGTM! Clear and concise plugin metadata.

The YAML configuration provides essential plugin information with appropriate versioning and description.

Comment on lines +229 to 235
// Collect ALL input values
Object.keys(inputs).forEach(key => {
const value = inputs[key].value.trim();
if (value !== '') {
cameraParams[key] = Number(value);
}
});
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation for numeric input values.

The code should validate that the parsed numbers are finite and within acceptable ranges.

     // Collect ALL input values
     Object.keys(inputs).forEach(key => {
       const value = inputs[key].value.trim();
       if (value !== '') {
-        cameraParams[key] = Number(value);
+        const num = Number(value);
+        if (isFinite(num)) {
+          cameraParams[key] = num;
+        } else {
+          statusMessage.textContent = `Invalid value for ${key}`;
+          return;
+        }
       }
     });
📝 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
// Collect ALL input values
Object.keys(inputs).forEach(key => {
const value = inputs[key].value.trim();
if (value !== '') {
cameraParams[key] = Number(value);
}
});
// Collect ALL input values
Object.keys(inputs).forEach(key => {
const value = inputs[key].value.trim();
if (value !== '') {
const num = Number(value);
if (isFinite(num)) {
cameraParams[key] = num;
} else {
statusMessage.textContent = `Invalid value for ${key}`;
return;
}
}
});

@OpeDada OpeDada merged commit 98a374b into main Feb 10, 2025
19 of 20 checks passed
@OpeDada OpeDada deleted the refactor/plugin-playground-presets-camera-position branch February 10, 2025 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants