Skip to content

Resize panel#42

Open
six7 wants to merge 2 commits intomasterfrom
resize-panel
Open

Resize panel#42
six7 wants to merge 2 commits intomasterfrom
resize-panel

Conversation

@six7
Copy link
Owner

@six7 six7 commented Jan 21, 2025

Related to #39


For more details, open the Copilot Workspace session.

Summary by Sourcery

New Features:

  • Allow users to resize the plugin panel and the style selector panels.

Important

Adds resizing functionality to plugin and style selector panels, with mouse event handling in PluginUI.svelte, Selector.svelte, and code.ts.

  • Behavior:
    • Adds resizing functionality to plugin panel in PluginUI.svelte and style selector in Selector.svelte using mouse events.
    • Updates figma.ui.onmessage in code.ts to handle "resize" messages and adjust UI size.
  • UI Components:
    • Adds .resize-handle div to PluginUI.svelte and Selector.svelte for user interaction.
    • Implements handleMouseDown, handleMouseMove, and handleMouseUp functions in both PluginUI.svelte and Selector.svelte to manage resizing logic.
  • Misc:
    • Fixes typo in PluginUI.svelte by renaming Bxxxutton to Button.

This description was created by Ellipsis for 5c7b14f. It will automatically update as commits are pushed.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 21, 2025

Reviewer's Guide by Sourcery

This pull request implements panel resizing functionality for the plugin's UI. It allows users to adjust the height and width of the plugin panel by dragging a resize handle.

Sequence diagram for panel resize interaction

sequenceDiagram
    actor User
    participant UI as Plugin UI
    participant Figma as Figma API

    User->>UI: Mousedown on resize handle
    activate UI
    Note right of UI: Store initial dimensions and mouse position
    UI->>UI: Add mousemove listener
    UI->>UI: Add mouseup listener
    deactivate UI

    User->>UI: Mousemove
    activate UI
    UI->>UI: Calculate new dimensions
    UI->>UI: Update panel size
    deactivate UI

    User->>UI: Mouseup
    activate UI
    UI->>UI: Remove mousemove listener
    UI->>UI: Remove mouseup listener
    UI->>Figma: Resize UI message
    Figma->>Figma: Update plugin window size
    deactivate UI
Loading

Class diagram for updated UI components

classDiagram
    class PluginUI {
        -boolean isResizing
        -number startX
        -number startY
        -number startWidth
        -number startHeight
        +handleMouseDown(event)
        +handleMouseMove(event)
        +handleMouseUp()
    }

    class Selector {
        -boolean isResizing
        -number startY
        -number startHeight
        +handleMouseDown(event)
        +handleMouseMove(event)
        +handleMouseUp()
    }

    note for PluginUI "Added resize functionality"
    note for Selector "Added vertical resize capability"
Loading

File-Level Changes

Change Details Files
Added resizing functionality to the main plugin UI panel.
  • Added event listeners for mouse down, mouse move, and mouse up events to handle resizing.
  • Implemented logic to calculate and apply new width and height to the panel during resizing.
  • Added a resize handle element to the bottom of the panel.
  • Added a bind:this={panel} to the outer wrapper div to get a reference to the panel element.
src/PluginUI.svelte
Added resizing functionality to the style selector panel.
  • Added event listeners for mouse down, mouse move, and mouse up events to handle resizing.
  • Implemented logic to calculate and apply new height to the panel during resizing.
  • Added a resize handle element to the bottom of the panel.
  • Added a bind:this={panel} to the outer wrapper div to get a reference to the panel element.
src/Selector.svelte
Added a message listener in the code.ts file to handle resize events from the UI.
  • Added an event listener for messages from the UI.
  • Implemented logic to resize the plugin UI based on the message received.
src/code.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to ab2252c in 54 seconds

More details
  • Looked at 139 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. src/PluginUI.svelte:100
  • Draft comment:
    Consider refactoring the resizing logic into a reusable component or utility function to avoid code duplication. This logic is repeated in both PluginUI.svelte and Selector.svelte.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The code for resizing the panel in both PluginUI.svelte and Selector.svelte is almost identical. This duplication can be avoided by creating a reusable component or utility function for resizing, which would make the codebase cleaner and easier to maintain.
2. src/PluginUI.svelte:113
  • Draft comment:
    Consider using requestAnimationFrame for updating the panel's dimensions in handleMouseMove to improve performance and avoid layout thrashing. This is applicable in both PluginUI.svelte and Selector.svelte.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The handleMouseMove function in both PluginUI.svelte and Selector.svelte directly manipulates the DOM by setting the style properties. This can lead to layout thrashing if not handled properly. Consider using requestAnimationFrame to batch these updates for better performance.
3. src/PluginUI.svelte:103
  • Draft comment:
    Ensure that event listeners added in handleMouseDown are always removed in handleMouseUp to prevent memory leaks. This is correctly implemented here and in Selector.svelte.
  • Reason this comment was not posted:
    Confidence changes required: 20%
    The handleMouseDown function in both PluginUI.svelte and Selector.svelte adds event listeners to the document. It's important to ensure these listeners are removed to prevent memory leaks. The current implementation does this correctly, but it's worth noting as a best practice.

Workflow ID: wflow_mpit7ukP1QUPbyJh


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @six7 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider extracting the resize logic into a reusable component or directive since it's duplicated between PluginUI.svelte and Selector.svelte
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

document.documentElement.addEventListener('mouseup', handleMouseUp);
}

function handleMouseMove(event) {
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider adding minimum/maximum size constraints to prevent invalid dimensions

The panel could be resized to very small or very large dimensions. Consider adding bounds checking like: const newWidth = Math.max(MIN_WIDTH, Math.min(MAX_WIDTH, startWidth + event.clientX - startX));

Suggested implementation:

  const MIN_WIDTH = 200; // Minimum width in pixels
  const MAX_WIDTH = 800; // Maximum width in pixels
  const MIN_HEIGHT = 100; // Minimum height in pixels
  const MAX_HEIGHT = 600; // Maximum height in pixels

  function handleMouseMove(event) {
    if (!isResizing) return;
    const newWidth = Math.max(MIN_WIDTH, Math.min(MAX_WIDTH, startWidth + event.clientX - startX));
    const newHeight = Math.max(MIN_HEIGHT, Math.min(MAX_HEIGHT, startHeight + event.clientY - startY));

The specific MIN/MAX values I've suggested (200/800px for width, 100/600px for height) should be adjusted based on your application's specific needs and design requirements. You may want to:

  1. Consider making these constants configurable via props if this is a reusable component
  2. Adjust the values based on the viewport size or other UI constraints in your application

@@ -96,6 +96,33 @@
trackData(event.data.pluginMessage.data);
}
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider extracting resize functionality into a reusable component or utility

This resize logic is duplicated in Selector.svelte. Consider creating a shared component or utility function to handle resize behavior.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 5c7b14f in 32 seconds

More details
  • Looked at 13 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. src/PluginUI.svelte:12
  • Draft comment:
    Typo in import statement. Replace Bxxxutton with Button.
    Button,
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    While this is a clear typo that would break the build, one of our rules explicitly states "Do NOT comment on anything that would be obviously caught by the build, such as variable renames, file renames, or changed imports." This is exactly that case - a broken import that would be immediately caught by the build system.
    The typo is very obvious and the suggestion is correct. Maybe build errors aren't always clear about the exact fix needed?
    While build errors might sometimes be cryptic, a missing import error would clearly point to this line, and the correct import name would be obvious given the context of the design system library.
    We should delete this comment because it violates our rule about not commenting on issues that would be caught by the build system.

Workflow ID: wflow_Ovccfn98tfTKGMr4


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

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