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: The plugin fixed state is persisted using vueuse. #738

Merged

Conversation

STATICHIT
Copy link

@STATICHIT STATICHIT commented Aug 14, 2024

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

refactor: The plugin fixed state is persisted using vueuse.

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Introduced dynamic management of fixed panels in the user interface, allowing users to customize which plugins are fixed on the left and right sides of the layout.
    • Added functionality to toggle fixed panel states easily through new controls.
  • Bug Fixes

    • Improved performance and clarity in managing fixed panel states across components.
  • Refactor

    • Enhanced modularity by encapsulating state management logic into dedicated functions for better maintenance and readability.

Copy link
Contributor

coderabbitai bot commented Aug 14, 2024

Walkthrough

The recent changes enhance the management of fixed panels in the layout by introducing dedicated storage variables for the left and right fixed panels. This refactoring streamlines state management through a modular approach, encapsulating panel toggling logic in specific functions. As a result, the design components become more maintainable and responsive to state changes, improving overall performance and clarity.

Changes

Files Change Summary
packages/controller/src/useLayout.js Introduced leftFixedPanelsStorage and rightFixedPanelsStorage for managing fixed panel states; added functions for toggling these states. Updated export to include new variables and functions.
packages/design-core/src/DesignPlugins.vue Replaced pluginsState.fixedPanels with leftFixedPanelsStorage; updated class bindings and destructured hook to include new state management functions. Simplified panel toggling logic.
packages/design-core/src/DesignSettings.vue Renamed settingsState.fixedPanels to rightFixedPanelsStorage in template and script; encapsulated panel state toggling in changeRightFixedPanels function.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant Layout
    participant Storage

    User->>UI: Toggle Left Fixed Panel
    UI->>Layout: changeLeftFixedPanels(pluginName)
    Layout->>Storage: Update leftFixedPanelsStorage
    Storage-->>Layout: State Updated
    Layout-->>UI: Refresh UI with new state
    UI-->>User: Display updated panel state
Loading
sequenceDiagram
    participant User
    participant UI
    participant Layout
    participant Storage

    User->>UI: Toggle Right Fixed Panel
    UI->>Layout: changeRightFixedPanels(pluginName)
    Layout->>Storage: Update rightFixedPanelsStorage
    Storage-->>Layout: State Updated
    Layout-->>UI: Refresh UI with new state
    UI-->>User: Display updated panel state
Loading

Poem

🐇 In a layout bright and fair,
Fixed panels dance without a care.
With a toggle here and a change so neat,
Our plugins find their perfect seat!
Hopping forward, things align,
Oh, what joy, our code does shine! ✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b28884b and 78903ca.

Files selected for processing (3)
  • packages/controller/src/useLayout.js (2 hunks)
  • packages/design-core/src/DesignPlugins.vue (4 hunks)
  • packages/design-core/src/DesignSettings.vue (4 hunks)
Additional comments not posted (12)
packages/controller/src/useLayout.js (4)

100-101: Persisting fixed panels state with useStorage.

The introduction of leftFixedPanelsStorage and rightFixedPanelsStorage using useStorage is a good approach for persisting state across sessions. Ensure that the initial values set in layoutState are appropriate and that any changes to these states are correctly reflected in the UI.


103-107: Encapsulate logic for changing left fixed panels.

The changeLeftFixedPanels function effectively toggles the presence of a pluginName in leftFixedPanelsStorage. This encapsulation improves code modularity and readability.


108-112: Encapsulate logic for changing right fixed panels.

Similarly, changeRightFixedPanels encapsulates the logic for toggling the pluginName in rightFixedPanelsStorage. This approach is consistent with the left panel management and enhances maintainability.


196-199: Export new storage and change functions.

The export of leftFixedPanelsStorage, rightFixedPanelsStorage, changeLeftFixedPanels, and changeRightFixedPanels makes these functionalities available to other parts of the application, promoting reuse and consistency in state management.

packages/design-core/src/DesignSettings.vue (4)

8-13: Update class and prop bindings to use rightFixedPanelsStorage.

The use of rightFixedPanelsStorage in the :class and :fixed-panels bindings ensures that the component reflects the persisted state of fixed panels. This change centralizes the state management and improves consistency.


70-71: Destructure rightFixedPanelsStorage and changeRightFixedPanels.

Destructuring these from useLayout aligns with the new state management strategy, ensuring that the component uses the centralized state logic.


112-112: Use changeRightFixedPanels for toggling panel state.

The fixPanel method now uses changeRightFixedPanels, centralizing the logic for toggling the fixed state. This improves maintainability by reducing inline logic.


125-126: Return fixPanel and rightFixedPanelsStorage.

Returning these from the setup function makes them available to the template, ensuring that the component can interact with the new state management logic.

packages/design-core/src/DesignPlugins.vue (4)

82-89: Update class and prop bindings to use leftFixedPanelsStorage.

The update to use leftFixedPanelsStorage in the :class and :fixed-panels bindings ensures that the component reflects the persisted state of left fixed panels. This centralizes the state management and improves consistency.


137-137: Destructure changeLeftFixedPanels and leftFixedPanelsStorage.

Destructuring these from useLayout aligns with the new state management strategy, ensuring that the component uses the centralized state logic.


208-208: Use changeLeftFixedPanels for toggling panel state.

The fixPanel method now uses changeLeftFixedPanels, centralizing the logic for toggling the fixed state. This improves maintainability by reducing inline logic.


224-225: Return pluginState and leftFixedPanelsStorage.

Returning these from the setup function ensures they are available to the template, allowing interaction with the new state management logic.

@hexqi hexqi added the ospp-2024 ospp-2024 label Aug 15, 2024
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 78903ca and ad78222.

Files selected for processing (1)
  • packages/controller/src/useLayout.js (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/controller/src/useLayout.js

@hexqi hexqi merged commit 221d482 into opentiny:ospp-2024/002-plugin-layout Aug 21, 2024
1 check passed
@STATICHIT STATICHIT deleted the FixedPanels-vueuse branch August 27, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ospp-2024 ospp-2024
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants