Skip to content

Add Custom BrowserAction Component#16

Merged
iamEvanYT merged 4 commits intomainfrom
evan/custom-browser-action
Mar 29, 2025
Merged

Add Custom BrowserAction Component#16
iamEvanYT merged 4 commits intomainfrom
evan/custom-browser-action

Conversation

@iamEvanYT
Copy link
Member

@iamEvanYT iamEvanYT commented Mar 29, 2025

closes #14

Summary by CodeRabbit

  • New Features

    • Introduced a responsive browser action interface featuring dynamic icons, badges, and real-time updates.
    • Enhanced the sidebar with streamlined navigation controls, including integrated address bar behavior.
    • Added customizable popover elements for enriched user interaction.
  • Chores

    • Updated version control settings to exclude extension files.
    • Included an additional UI library dependency for advanced popover support.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 29, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces several UI enhancements and component additions. The changes include updating the .gitignore file to ignore all files in the extensions directory, adding a new Radix UI dependency for popover support, and creating new browser action components that manage state and events. Additionally, sidebar components have been refactored for improved organization and state handling, and a new popover component has been added to wrap Radix UI primitives.

Changes

File(s) Change Summary
.gitignore Added an "Others" section with the entry extensions/* to ignore all files in the extensions directory.
vite/package.json Added new dependency @radix-ui/react-popover with version ^1.1.6.
vite/src/components/browser-ui/browser-action.tsx New file introducing browser action components: BrowserActionList, BrowserAction, BrowserActionIcon, and Badge for managing actions.
vite/src/components/browser-ui/sidebar/* Modified sidebar components: Updated action button signatures to use SidebarMenuButton, added NavigationControls, and adjusted address bar state handling.
vite/src/components/ui/popover.tsx New file with popover component wrappers (Popover, PopoverTrigger, PopoverContent, PopoverAnchor) leveraging Radix UI primitives.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BrowserActionList
    participant BrowserAction
    participant GlobalBrowserAction

    User->>BrowserActionList: Request to load browser actions
    BrowserActionList->>GlobalBrowserAction: Fetch current state
    GlobalBrowserAction-->>BrowserActionList: Return state
    BrowserActionList->>BrowserAction: Render action component
    User->>BrowserAction: Click action to activate
    BrowserAction->>GlobalBrowserAction: Process activation event
Loading
sequenceDiagram
    participant User
    participant NavigationControls
    participant SidebarMenu
    participant SidebarActionButton

    User->>NavigationControls: Click sidebar button
    NavigationControls->>SidebarMenu: Request sidebar rendering
    SidebarMenu-->>NavigationControls: Display menu options
    SidebarActionButton->>NavigationControls: Trigger sidebar state change
Loading
sequenceDiagram
    participant User
    participant PopoverTrigger
    participant PopoverContent

    User->>PopoverTrigger: Interact with trigger
    PopoverTrigger->>PopoverContent: Display popover
    PopoverContent-->>User: Show popover details
Loading

Assessment against linked issues

Objective Addressed Explanation
Group extension icons and prevent toolbar overflow (#14)

Possibly related PRs

  • Add Custom BrowserAction Component #16: The changes in the main PR are directly related to those in the retrieved PR, as both involve the addition of the same entry extensions/* in the .gitignore file.

Poem

I'm a rabbit coding fast and free,
With sidebar hops and popover glee,
My browser actions now align in neat array,
Extensions tucked nicely—no clutter in the way,
In every commit, I bounce with cheer,
Celebrating changes that make our UI clear!
🐰🚀


📜 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 c6c0656 and af2fa04.

📒 Files selected for processing (1)
  • vite/src/components/browser-ui/browser-action.tsx (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@iamEvanYT iamEvanYT added bug Something isn't working enhancement New feature or request labels Mar 29, 2025
@iamEvanYT iamEvanYT self-assigned this Mar 29, 2025
@iamEvanYT iamEvanYT marked this pull request as ready for review March 29, 2025 23:28
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 (6)
vite/src/components/ui/popover.tsx (1)

14-34: Good implementation of PopoverContent with default values.

The PopoverContent component is well structured with sensible defaults for alignment and offset. The component properly wraps the content in a portal for correct rendering in the DOM hierarchy.

One suggestion for improvement would be to break up the long className string into multiple lines for better readability.

className={cn(
-          "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
+          [
+            "bg-popover text-popover-foreground",
+            "data-[state=open]:animate-in data-[state=closed]:animate-out",
+            "data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
+            "data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
+            "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2",
+            "data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
+            "z-50 w-72 origin-(--radix-popover-content-transform-origin)",
+            "rounded-md border p-4 shadow-md outline-hidden"
+          ].join(" "),
          className
        )}
vite/src/components/browser-ui/browser-action.tsx (5)

7-7: Consider removing the eslint-disable for @typescript-eslint/no-explicit-any.
Although convenient for rapid prototyping, using any can introduce type-safety gaps and obscure potential bugs. Consider defining more precise types for event listeners and method signatures to aid maintainability and reduce runtime errors.


68-70: Optional: Provide a more descriptive fallback or alt text for accessibility.
Displaying a puzzle icon (<PuzzleIcon />) on error is helpful visually, but it would be more accessible to include a descriptive alt text or screen-reader-only text for users relying on screen readers.


73-75: Add alt text or aria-label for the SVG image.
Consider adding an alt text or aria-label for the <image> element to ensure accessibility compliance.

- <image href={iconUrl} className="size-4 object-contain shrink-0" onError={() => setIsError(true)} />
+ <image
+   href={iconUrl}
+   className="size-4 object-contain shrink-0"
+   onError={() => setIsError(true)}
+   aria-label="Extension Icon"
+ />

164-166: Address the pinned extensions TODO.
A pinned action would likely enhance the user experience and keep critical extensions readily accessible.

Would you like me to help implement a pin/unpin mechanism and open an issue to track it?


212-212: Check for zero or negative tab IDs.
Returning null when activeTabId is falsy might exclude a valid tab with ID 0. Consider checking for activeTabId === undefined || activeTabId < 0 instead, if tab ID 0 is intended to be valid.

- if (!activeTabId) return null;
+ if (typeof activeTabId === "undefined" || activeTabId < 0) {
+   return null;
+ }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1836261 and 96b13bd.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • .gitignore (1 hunks)
  • vite/package.json (1 hunks)
  • vite/src/components/browser-ui/browser-action.tsx (1 hunks)
  • vite/src/components/browser-ui/sidebar/action-buttons.tsx (4 hunks)
  • vite/src/components/browser-ui/sidebar/address-bar.tsx (1 hunks)
  • vite/src/components/ui/popover.tsx (1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
vite/src/components/browser-ui/browser-action.tsx (1)
vite/src/components/ui/popover.tsx (3)
  • Popover (40-40)
  • PopoverTrigger (40-40)
  • PopoverContent (40-40)
vite/src/components/browser-ui/sidebar/action-buttons.tsx (2)
vite/src/components/ui/resizable-sidebar.tsx (4)
  • SidebarMenuButton (730-730)
  • SidebarMenu (727-727)
  • SidebarMenuItem (731-731)
  • SidebarGroup (720-720)
vite/src/components/browser-ui/browser-action.tsx (1)
  • BrowserActionList (172-236)
🔇 Additional comments (10)
.gitignore (1)

138-139: Good addition to ignore extension files.

Adding the extensions/* pattern to gitignore is appropriate for a browser project that might work with or generate extension-related files. This prevents extension files from being tracked in version control.

vite/package.json (1)

16-16: Good addition of the Radix UI popover dependency.

Adding @radix-ui/react-popover is consistent with the project's existing use of Radix UI components and will enable the implementation of popover UI elements needed for browser actions.

vite/src/components/browser-ui/sidebar/address-bar.tsx (1)

46-48: Good improvement to SidebarAddressBar visibility handling.

Moving the open state check from FakeAddressBar to SidebarAddressBar is a better separation of concerns. Now the parent component correctly handles when to render its children based on the sidebar state.

vite/src/components/ui/popover.tsx (4)

6-8: Well-implemented Popover root component.

Good implementation of the Popover wrapper component with appropriate data attributes for styling and testing.


10-12: Well-implemented PopoverTrigger component.

The PopoverTrigger wrapper correctly passes props to the underlying Radix UI primitive while adding a helpful data attribute.


36-38: Well-implemented PopoverAnchor component.

The PopoverAnchor wrapper correctly passes props to the underlying Radix UI primitive while adding a helpful data attribute.


40-40: Good component exports.

Clear export of all the popover-related components, making them easily importable by other parts of the application.

vite/src/components/browser-ui/sidebar/action-buttons.tsx (3)

17-30: Usage of SidebarMenuButton for SidebarActionButton looks good.
Extending ComponentProps<typeof SidebarMenuButton> is a clear approach to maintain consistency. Overall, this layout fosters composability in the sidebar.


56-67: Clean separation for the closed sidebar UI.
Returning a condensed sidebar menu with a single button for reopening is an elegant way to handle collapsed state. Good work!


79-96: Well-structured open sidebar layout.
Organizing the browser actions and navigation buttons into separate <SidebarMenuItem> blocks improves clarity. The injection of <BrowserActionList> here fits naturally.

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 (7)
vite/src/components/browser-ui/sidebar/tab.tsx (1)

55-55: Double-check the removal of "select-none".
By removing "select-none", text selection on the tab might be inadvertently enabled. Confirm whether this change is intended or if you still want to prevent text selection.

vite/src/components/browser-ui/browser-action.tsx (6)

7-12: Consider limiting or documenting alignment options.
The alignmentX and alignmentY props are restricted to specific literal types. If these might change or expand in the future, you could introduce an enum or provide docstrings clarifying the possible values.


39-42: Rename the generic "State" for clarity.
Consider using a more descriptive name like BrowserActionState if this type is exported or used broadly.


44-52: Refine type definition for __browserAction__.
The methods in this type rely heavily on any. Stronger type definitions would improve maintainability and catch inconsistencies.


54-77: Fallback icon usage in BrowserActionIcon.
Currently, a failed icon load displays the PuzzleIcon. This is user-friendly. If desired, consider making the fallback icon more indicative of the extension's nature or brand.


101-170: Refactor repeated event logic in BrowserAction.
Both onClick and onContextMenu trigger the same final call. If needed, you could centralize to a single handler to reduce duplication. Also, there is a TODO for pin functionality. Let me know if you'd like help implementing it.


172-236: Consider adding error handling to fetchState().
Currently, if browserAction.getState rejects or returns an unexpected shape, the UI could remain blank. Adding a catch block or fallback UI would improve robustness.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 96b13bd and c6c0656.

📒 Files selected for processing (5)
  • vite/src/components/browser-ui/browser-action.tsx (1 hunks)
  • vite/src/components/browser-ui/browser-sidebar.tsx (1 hunks)
  • vite/src/components/browser-ui/sidebar/address-bar.tsx (1 hunks)
  • vite/src/components/browser-ui/sidebar/tab.tsx (1 hunks)
  • vite/src/components/browser-ui/sidebar/tabs.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • vite/src/components/browser-ui/sidebar/tabs.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • vite/src/components/browser-ui/sidebar/address-bar.tsx
🧰 Additional context used
🧬 Code Definitions (1)
vite/src/components/browser-ui/browser-action.tsx (1)
vite/src/components/ui/popover.tsx (3)
  • Popover (40-40)
  • PopoverTrigger (40-40)
  • PopoverContent (40-40)
🔇 Additional comments (5)
vite/src/components/browser-ui/browser-sidebar.tsx (1)

65-65: Verify the global application of "select-none".
Introducing "select-none" at the sidebar level will disable text selection across all nested elements. Ensure this aligns with the desired UX for sidebar content.

vite/src/components/browser-ui/browser-action.tsx (4)

1-6: Imports look consistent.
All imported modules appear relevant, and there are no apparent unused imports or mismatches.


14-20: Interface structure appears solid.
The ActivateDetails interface captures all required properties for browser action activation.


22-37: Interfaces for extension actions and tabs look correct.
The ExtensionAction and Action interfaces sufficiently describe the shape of the browser action data. Consider adding jsdoc comments if these interfaces will see wider usage.


79-99: Check for potential user input.
Ensure that the Badge's text and color values cannot introduce unwanted rendering or XSS. If they originate from untrusted sources, you might need sanitization or limits on length.

@iamEvanYT iamEvanYT merged commit f7d46c8 into main Mar 29, 2025
1 check was pending
@iamEvanYT iamEvanYT deleted the evan/custom-browser-action branch March 29, 2025 23:38
@coderabbitai coderabbitai bot mentioned this pull request Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extension icons overlap with page content

1 participant