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

feat(web): plugin playground / display console #1263

Merged
merged 64 commits into from
Nov 28, 2024
Merged

Conversation

devshun
Copy link
Contributor

@devshun devshun commented Nov 20, 2024

Overview

I have added a process to display logs in the console during code execution, referring to the sandbox of Cesium.

What I've done

What I haven't done

How I tested

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • New Features

    • Introduced a new state variable to capture outputs from executed JavaScript files.
    • Enhanced error handling for code execution failures.
    • Added a new fileOutputs prop to the Console component for displaying execution results.
    • Created a styled Wrapper component for improved output display.
  • Bug Fixes

    • Simplified checks for YAML file extensions to improve error handling.
  • Refactor

    • Updated the structure and logic of the useCode hook and related components for better data flow.

devshun and others added 30 commits October 22, 2024 14:42
Copy link

coderabbitai bot commented Nov 20, 2024

Walkthrough

The changes in this pull request enhance the functionality of the PluginPlayground feature by introducing a new state variable fileOutputs to capture the results of executing JavaScript files. The executeCode function is updated to filter and execute JavaScript files, storing their outputs and handling errors more effectively. The Console component is modified to accept and display these outputs, and related components are updated to ensure proper data flow and rendering.

Changes

File Path Change Summary
web/src/beta/features/PluginPlayground/Code/hook.ts - Added state variable fileOutputs to store execution results.
- Updated executeCode function to filter and execute JavaScript files, capturing outputs.
- Modified return statement to include fileOutputs.
web/src/beta/features/PluginPlayground/Console/index.tsx - Introduced new prop type for Console to accept fileOutputs.
- Updated rendering logic to display outputs if provided.
- Added styled component Wrapper for layout management.
web/src/beta/features/PluginPlayground/hooks.tsx - Expanded useCode hook return value to include fileOutputs.
- Updated BottomAreaTabs to re-render based on fileOutputs.

Possibly related PRs

Suggested reviewers

  • mkumbobeaty
  • airslice
  • mulengawilfred
  • ZTongci

🐇 In the playground where code does play,
Outputs are captured in a brand new way.
With hooks and props, we dance and twirl,
JavaScript magic in our rabbit world!
Errors are tamed, and results are bright,
Hopping through code, what a joyful sight! 🌟


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 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 Nov 20, 2024

Deploy Preview for reearth-web canceled.

Name Link
🔨 Latest commit 7fbc0aa
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/6748f56154264f0008d03090

@devshun devshun marked this pull request as ready for review November 24, 2024 13:51
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: 5

🧹 Outside diff range and nitpick comments (5)
web/src/beta/features/PluginPlayground/Console/index.tsx (3)

4-10: Consider enhancing type definitions for better type safety.

The type definition is good, but could be improved for better maintainability and type safety.

Consider this enhancement:

 type Props = {
   fileOutputs:
     | {
+        id: string; // Add unique identifier for React keys
         title: string;
-        output: string;
+        output: string | Error; // Support error objects
+        timestamp?: number; // Add timestamp for sorting
       }[]
     | undefined;
 };

26-32: Enhance console styling for better usability.

The current styling could be improved for better readability and cross-browser compatibility.

Consider these style enhancements:

 const Wrapper = styled.div(() => ({
   display: "flex",
   flexDirection: "column",
   maxHeight: "100%",
   height: "100%",
-  overflow: "auto"
+  overflow: "auto",
+  padding: "8px",
+  wordBreak: "break-word",
+  fontFamily: "monospace",
+  backgroundColor: "#f5f5f5",
+  "&::-webkit-scrollbar": {
+    width: "8px",
+  },
+  "&::-webkit-scrollbar-thumb": {
+    backgroundColor: "#888",
+    borderRadius: "4px",
+  }
 }));

1-33: Consider adding common console features.

To better align with typical development consoles (like the Cesium sandbox mentioned in PR objectives), consider adding these features:

  1. Log levels (info, warn, error)
  2. Clear console button
  3. Filter by log type
  4. Copy output to clipboard
  5. Console command input
  6. Collapsible output groups

Would you like me to provide implementation examples for any of these features?

🧰 Tools
🪛 Biome (1.9.4)

[error] 18-18: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

web/src/beta/features/PluginPlayground/hooks.tsx (1)

Line range hint 27-52: Consider implementing output management strategies

For a robust plugin playground implementation, consider:

  1. Implementing output size limits to prevent memory issues
  2. Adding output clearing functionality
  3. Adding timestamp information to outputs
  4. Implementing output persistence across sessions

Would you like me to provide specific implementation suggestions for any of these improvements?

web/src/beta/features/PluginPlayground/Code/hook.ts (1)

96-113: Improve error handling specificity

The current error handling could be more specific about different types of errors that might occur during execution.

Consider this enhanced error handling:

try {
  return {
    title: file.title,
    output: fn()
  };
} catch (error) {
  if (error instanceof SyntaxError) {
    return {
      title: file.title,
      output: `Syntax Error: ${error.message}`
    };
  } else if (error instanceof ReferenceError) {
    return {
      title: file.title,
      output: `Reference Error: ${error.message}`
    };
  } else if (error instanceof Error) {
    return {
      title: file.title,
      output: `Runtime Error: ${error.message}`
    };
  }
  return {
    title: file.title,
    output: "Unknown execution error occurred"
  };
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 69b1cd7 and df82880.

📒 Files selected for processing (3)
  • web/src/beta/features/PluginPlayground/Code/hook.ts (3 hunks)
  • web/src/beta/features/PluginPlayground/Console/index.tsx (1 hunks)
  • web/src/beta/features/PluginPlayground/hooks.tsx (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
web/src/beta/features/PluginPlayground/Console/index.tsx

[error] 18-18: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

🔇 Additional comments (5)
web/src/beta/features/PluginPlayground/hooks.tsx (3)

49-49: LGTM: Console component integration

The fileOutputs prop is correctly passed to the Console component, implementing the core feature for log display.


52-52: LGTM: Proper React hooks usage

The dependency array is correctly updated to include fileOutputs, ensuring the component re-renders when outputs change.


27-29: Verify error handling in useCode hook

The integration looks correct, but let's ensure proper error handling for the file execution outputs.

✅ Verification successful

Error handling is properly implemented in the codebase

The verification shows comprehensive error handling in the code execution flow:

  • The useCode hook and related components have proper error handling:
    • YAML parsing errors are caught and provide user-friendly messages
    • Code execution errors are caught and displayed in file outputs
    • Console errors are properly captured and displayed
  • Error states are properly propagated through notifications
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check error handling implementation in useCode hook
# Look for try-catch blocks and error state management

ast-grep --pattern 'try {
  $$$
} catch (error) {
  $$$
}'

# Check for error-related state management
rg -A 3 'error|Error' ./web/src/beta/features/PluginPlayground/Code/hook.ts

Length of output: 18043

web/src/beta/features/PluginPlayground/Code/hook.ts (2)

54-59: LGTM! Well-structured state definition.

The type definition for fileOutputs is clear and appropriate for storing console outputs with their associated file titles.


182-183: LGTM! Proper exposure of the new state.

The addition of fileOutputs to the return object is consistent with React hooks pattern and allows parent components to access the console output data.

web/src/beta/features/PluginPlayground/Console/index.tsx Outdated Show resolved Hide resolved
web/src/beta/features/PluginPlayground/Console/index.tsx Outdated Show resolved Hide resolved
web/src/beta/features/PluginPlayground/Code/hook.ts Outdated Show resolved Hide resolved
web/src/beta/features/PluginPlayground/Code/hook.ts Outdated Show resolved Hide resolved
web/src/beta/features/PluginPlayground/Code/hook.ts Outdated Show resolved Hide resolved
@devshun devshun requested a review from airslice November 28, 2024 00:58
@devshun
Copy link
Contributor Author

devshun commented Nov 28, 2024

Thank you for the review. I'll merge it.

@devshun devshun enabled auto-merge (squash) November 28, 2024 22:57
@devshun devshun merged commit 3444abd into main Nov 28, 2024
10 checks passed
@devshun devshun deleted the playground/display-console branch November 28, 2024 23:00
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