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 width is persisted using vueuse. #732

Merged
merged 6 commits into from
Aug 14, 2024

Conversation

STATICHIT
Copy link

@STATICHIT STATICHIT commented Aug 11, 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

The plugin width 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

    • Enhanced management of plugin widths with a more streamlined approach using function calls for better performance.
    • Introduced storage persistence for plugin widths across sessions.
    • Added a new dependency to improve utility functions for Vue.js applications.
  • Bug Fixes

    • Improved clarity and maintainability in the layout management process.
  • Style

    • Added a new CSS variable for date picker width, promoting consistent styling.
    • Consolidated attributes in the plugin-panel component for improved readability and cleaner code structure.
    • Restructured template layouts in various components for better organization without affecting functionality.

Copy link
Contributor

coderabbitai bot commented Aug 11, 2024

Walkthrough

The recent updates streamline plugin width management across various components, shifting from a reactive property approach to a more functional style. This transition enhances performance, clarity, and maintainability by introducing new functions for width retrieval and modification. Overall, these changes refine layout handling, leading to a more efficient and cohesive user interface experience.

Changes

Files Change Summary
.../common/component/PluginPanel.vue Updated to use getPluginWidth for direct width retrieval, removing the watch on pluginWidth. Simplified panelWidth logic.
.../controller/src/useLayout.js Introduced useStorage for persistent pluginWidth. Added getPluginWidth and changePluginWidth for structured width management.
.../plugins/bridge/src/BridgeSetting.vue Replaced destructured pluginWidth with getPluginWidth, simplifying width retrieval for the 'Bridge' plugin.
.../plugins/data/src/Main.vue Shifted from pluginWidth to getPluginWidth for improved width handling.
.../plugins/datasource/src/DataSourceForm.vue Updated to use getPluginWidth for calculating leftMargin, enhancing width retrieval method.
.../plugins/datasource/src/DataSourceGlobalDataHandler.vue Replaced pluginWidth with getPluginWidth for improved clarity in width access.
.../plugins/datasource/src/DataSourceRecordList.vue Transitioned to getPluginWidth for width retrieval, maintaining existing functionality.
.../plugins/datasource/src/DataSourceRemotePanel.vue Updated leftMargin calculation to utilize getPluginWidth, changing the width access mechanism.
.../plugins/page/src/PageFolderSetting.vue Replaced pluginWidth with getPluginWidth for dynamic width retrieval in the AppManage plugin.
.../plugins/page/src/PageSetting.vue Shifted to getPluginWidth for width access, improving the method of calculating leftMargin.
.../settings/events/src/Main.vue Consolidated plugin-panel attributes for readability, changed :fixed-name from PLUGIN_NAME.Event to SETTING_NAME.Event.
package.json Added a new dependency @vueuse/core with version ^9.6.0 to enhance project capabilities.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MainComponent
    participant LayoutManager

    User->>MainComponent: Interacts with plugin
    MainComponent->>LayoutManager: Calls getPluginWidth()
    LayoutManager-->>MainComponent: Returns width
    MainComponent->>User: Updates UI based on width
Loading

🐇 In the meadow, a rabbit did say,
"With widths so neat, I hop and I play!
Oh, plugins so spry, with margins so wide,
Thanks to the change, there’s joy in my stride!
Let's leap for the code, so tidy and bright,
A hop and a skip in the soft moonlight!" 🌙✨


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 5df2ba3 and 29a505a.

Files selected for processing (11)
  • packages/common/component/PluginPanel.vue (4 hunks)
  • packages/controller/src/useLayout.js (4 hunks)
  • packages/plugins/bridge/src/BridgeSetting.vue (1 hunks)
  • packages/plugins/data/src/Main.vue (1 hunks)
  • packages/plugins/datasource/src/DataSourceForm.vue (1 hunks)
  • packages/plugins/datasource/src/DataSourceGlobalDataHandler.vue (1 hunks)
  • packages/plugins/datasource/src/DataSourceRecordList.vue (1 hunks)
  • packages/plugins/datasource/src/DataSourceRemotePanel.vue (1 hunks)
  • packages/plugins/page/src/PageFolderSetting.vue (1 hunks)
  • packages/plugins/page/src/PageSetting.vue (1 hunks)
  • packages/settings/events/src/Main.vue (1 hunks)
Additional comments not posted (13)
packages/settings/events/src/Main.vue (1)

2-2: Verify the change from PLUGIN_NAME.Event to SETTING_NAME.Event.

The change in the :fixed-name attribute might imply a shift in context or categorization. Ensure that SETTING_NAME.Event is correctly defined and used in the application.

packages/plugins/datasource/src/DataSourceGlobalDataHandler.vue (1)

38-39: LGTM! Verify the implementation and usage of getPluginWidth.

The change to use getPluginWidth improves clarity and encapsulation.

Ensure that getPluginWidth is implemented correctly and used consistently.

Verification successful

Verified: Implementation and Usage of getPluginWidth

The function getPluginWidth is correctly implemented in packages/controller/src/useLayout.js and is consistently used across various components to compute leftMargin. This change improves code clarity and encapsulation as intended.

  • Implementation: packages/controller/src/useLayout.js
  • Consistent Usage: Found in multiple components such as DataSourceGlobalDataHandler.vue, BridgeSetting.vue, PageSetting.vue, etc.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation and usage of `getPluginWidth`.

# Test: Search for the function definition and usage. Expect: Correct implementation and consistent usage.
ast-grep --lang javascript --pattern $'const getPluginWidth = ($_name) => { $$$ }'

Length of output: 172


Script:

#!/bin/bash
# Search for the implementation of `getPluginWidth` in the codebase, excluding files with known encoding issues.
rg 'getPluginWidth' --glob '!packages/controller/js/constants.js' -A 5

# Additionally, search for the usage of `getPluginWidth` across the codebase to ensure consistent usage.
rg 'getPluginWidth' -A 5

Length of output: 12997

packages/controller/src/useLayout.js (2)

15-15: LGTM! Ensure correct usage of useStorage.

The introduction of useStorage enhances the persistence of pluginWidth.


56-64: Verify the correctness of getPluginWidth and changePluginWidth.

These functions improve the encapsulation and management of plugin widths. Ensure they are correctly implemented and used.

Verification successful

Verified: Correctness of getPluginWidth and changePluginWidth

The functions getPluginWidth and changePluginWidth are correctly implemented and encapsulate the necessary logic for managing plugin widths. They are defined and exported from packages/controller/src/useLayout.js, indicating their intended use in other parts of the application. No issues found in their implementation.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation and usage of `getPluginWidth` and `changePluginWidth`.

# Test: Search for the function definitions and usage. Expect: Correct implementation and consistent usage.
ast-grep --lang javascript --pattern $'const getPluginWidth = ($_name) => { $$$ }'
ast-grep --lang javascript --pattern $'const changePluginWidth = ($_name, $_width) => { $$$ }'

Length of output: 357


Script:

#!/bin/bash
# Description: Verify the implementation and usage of `getPluginWidth` and `changePluginWidth`, excluding problematic files.

# Find all JavaScript files, excluding known problematic ones, and search for function definitions and usage.
fd -e js -E packages/controller/js/constants.js -x ast-grep --lang javascript --pattern $'const getPluginWidth = ($_name) => { $$$ }' {}
fd -e js -E packages/controller/js/constants.js -x ast-grep --lang javascript --pattern $'const changePluginWidth = ($_name, $_width) => { $$$ }' {}

Length of output: 291


Script:

#!/bin/bash
# Description: Verify the implementation and usage of `getPluginWidth` and `changePluginWidth` with a broader search pattern.

# Use ripgrep to search for any occurrences of `getPluginWidth` and `changePluginWidth` in JavaScript files.
rg 'getPluginWidth' --glob '!packages/controller/js/constants.js' --glob '*.js' -A 3
rg 'changePluginWidth' --glob '!packages/controller/js/constants.js' --glob '*.js' -A 3

Length of output: 1101

packages/plugins/page/src/PageFolderSetting.vue (1)

46-47: Refactor: Use getPluginWidth for width retrieval.

The change from a reactive property to a function call encapsulates the logic for obtaining plugin width, which can enhance maintainability and clarity. Ensure that getPluginWidth is correctly defined and used throughout the codebase.

Verification successful

Verification Successful: getPluginWidth is correctly defined and used.

The getPluginWidth function is properly defined in packages/controller/src/useLayout.js and is consistently used across various components in the codebase, including PageFolderSetting.vue, to retrieve plugin widths. No issues found with its definition or usage.

  • Definition: packages/controller/src/useLayout.js
  • Usage: Multiple components such as PageFolderSetting.vue, BridgeSetting.vue, etc.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition and usage of `getPluginWidth`.

# Test: Search for the definition and usage of `getPluginWidth`. Expect: Correct definition and consistent usage.
ast-grep --lang javascript --pattern $'function getPluginWidth($_) { $$$ }'

Length of output: 165


Script:

#!/bin/bash
# Description: Search for the usage and definition of `getPluginWidth` across the codebase, considering it might be a method or part of an object.

# Search for any function or method named `getPluginWidth`.
rg 'getPluginWidth' -A 5

# Check for any export or import statements that might define or use `getPluginWidth`.
rg 'export.*getPluginWidth' -A 2
rg 'import.*getPluginWidth' -A 2

Length of output: 6545

packages/common/component/PluginPanel.vue (2)

107-120: Ensure correct usage of changePluginWidth.

The changePluginWidth function is used to update the panel width during mouse events. Ensure that it is correctly implemented to handle these updates efficiently.


73-73: Refactor: Simplify width management with getPluginWidth and changePluginWidth.

This refactoring replaces the reactive watch mechanism with direct function calls, which can improve performance and reduce complexity. Verify that these functions are correctly defined and used throughout the codebase.

Verification successful

Verification Successful: getPluginWidth and changePluginWidth are correctly defined and used.

The functions are defined in packages/controller/src/useLayout.js and are consistently used across multiple components to manage plugin widths effectively, supporting the proposed refactoring.

  • Definitions:

    • getPluginWidth: packages/controller/src/useLayout.js
    • changePluginWidth: packages/controller/src/useLayout.js
  • Usages:

    • packages/common/component/PluginPanel.vue
    • packages/plugins/page/src/PageSetting.vue
    • packages/plugins/page/src/PageFolderSetting.vue
    • packages/plugins/datasource/src/DataSourceRemotePanel.vue
    • packages/plugins/datasource/src/DataSourceGlobalDataHandler.vue
    • packages/plugins/datasource/src/DataSourceForm.vue
    • packages/plugins/data/src/Main.vue
    • packages/plugins/datasource/src/DataSourceRecordList.vue
    • packages/plugins/bridge/src/BridgeSetting.vue
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition and usage of `getPluginWidth` and `changePluginWidth`.

# Test: Search for the definition and usage of `getPluginWidth` and `changePluginWidth`. Expect: Correct definition and consistent usage.
ast-grep --lang javascript --pattern $'function getPluginWidth($_) { $$$ }'
ast-grep --lang javascript --pattern $'function changePluginWidth($_, $_) { $$$ }'

Length of output: 338


Script:

#!/bin/bash
# Description: Search for occurrences of `getPluginWidth` and `changePluginWidth` in the codebase.

# Search for the definition and usage of `getPluginWidth`.
rg 'getPluginWidth' -A 3

# Search for the definition and usage of `changePluginWidth`.
rg 'changePluginWidth' -A 3

Length of output: 6319

packages/plugins/datasource/src/DataSourceForm.vue (1)

51-52: Refactor: Transition to getPluginWidth for width management.

This change adopts a functional approach for retrieving plugin width, which can improve flexibility and maintainability. Ensure that getPluginWidth is correctly defined and used throughout the codebase.

Verification successful

Verification Successful: getPluginWidth is correctly defined and used across the codebase.

The function getPluginWidth is defined in packages/controller/src/useLayout.js and is consistently used in multiple components for managing plugin widths. This refactor aligns with the intended improvement in flexibility and maintainability.

  • Definition: packages/controller/src/useLayout.js
  • Usage:
    • packages/plugins/datasource/src/DataSourceForm.vue
    • packages/plugins/datasource/src/DataSourceRemotePanel.vue
    • packages/plugins/datasource/src/DataSourceRecordList.vue
    • packages/plugins/datasource/src/DataSourceGlobalDataHandler.vue
    • packages/plugins/page/src/PageFolderSetting.vue
    • packages/plugins/page/src/PageSetting.vue
    • packages/plugins/data/src/Main.vue
    • packages/plugins/bridge/src/BridgeSetting.vue
    • packages/common/component/PluginPanel.vue
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition and usage of `getPluginWidth`.

# Test: Search for the definition and usage of `getPluginWidth`. Expect: Correct definition and consistent usage.
ast-grep --lang javascript --pattern $'function getPluginWidth($_) { $$$ }'

Length of output: 165


Script:

#!/bin/bash
# Description: Verify the definition and usage of `getPluginWidth`.

# Search for the definition of `getPluginWidth` as a function or an export.
rg 'function getPluginWidth' --type js -A 2
rg 'export.*getPluginWidth' --type js -A 2

# Search for the usage of `getPluginWidth` across the codebase.
rg 'getPluginWidth' --type js -A 2

Length of output: 4159

packages/plugins/datasource/src/DataSourceRemotePanel.vue (1)

62-63: Use of getPluginWidth improves encapsulation.

Replacing pluginWidth with getPluginWidth enhances encapsulation and flexibility in managing plugin dimensions. This change aligns with best practices for handling dynamic properties.

packages/plugins/bridge/src/BridgeSetting.vue (1)

129-130: Consistent refactoring with getPluginWidth.

The shift from pluginWidth to getPluginWidth is consistent with other parts of the codebase, promoting a more functional approach to width management.

packages/plugins/page/src/PageSetting.vue (1)

76-77: Refactoring to getPluginWidth enhances modularity.

The use of getPluginWidth instead of pluginWidth aligns with the refactoring strategy seen in other files, improving modularity and encapsulation.

packages/plugins/data/src/Main.vue (1)

130-136: Improved maintainability with getPluginWidth.

Replacing pluginWidth with getPluginWidth enhances maintainability by using a functional approach. Ensure that this change does not affect the layout adversely.

Verification successful

Consistent usage of getPluginWidth across the codebase.

The function getPluginWidth is consistently used across various components to compute layout-related properties like leftMargin. This suggests that its usage in Main.vue should not adversely affect the layout. The change enhances maintainability by following a common pattern.

  • Instances found in files such as PageSetting.vue, PageFolderSetting.vue, DataSourceGlobalDataHandler.vue, and others confirm consistent usage.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `getPluginWidth` and its impact on layout.

# Test: Search for `getPluginWidth` usage. Expect: Consistent usage across the codebase.
rg --type vue -A 5 $'getPluginWidth'

Length of output: 63


Script:

#!/bin/bash
# Description: Verify the usage of `getPluginWidth` and its impact on layout by searching without specifying a file type.

# Test: Search for `getPluginWidth` usage across all files.
rg -A 5 'getPluginWidth'

Length of output: 6475

packages/plugins/datasource/src/DataSourceRecordList.vue (1)

110-111: Improved maintainability with getPluginWidth.

Replacing pluginWidth with getPluginWidth enhances maintainability by using a functional approach. Ensure that this change does not affect the layout adversely.

Copy link
Contributor

@lizhijie429 lizhijie429 left a comment

Choose a reason for hiding this comment

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

点击右侧高级插件面板时有报错,请处理一下。
image

Copy link
Contributor

@lizhijie429 lizhijie429 left a comment

Choose a reason for hiding this comment

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

image
请处理一下图片中的警告。

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 29a505a and ba6eb82.

Files selected for processing (3)
  • packages/design-core/src/DesignPlugins.vue (1 hunks)
  • packages/design-core/src/DesignSettings.vue (1 hunks)
  • packages/settings/events/src/Main.vue (1 hunks)
Files skipped from review due to trivial changes (2)
  • packages/design-core/src/DesignPlugins.vue
  • packages/design-core/src/DesignSettings.vue
Files skipped from review as they are similar to previous changes (1)
  • packages/settings/events/src/Main.vue

@hexqi hexqi added the ospp-2024 ospp-2024 label Aug 13, 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 ba6eb82 and f47ed92.

Files selected for processing (7)
  • mockServer/assets/css/0.1.20/index.css (1 hunks)
  • packages/plugins/bridge/src/BridgeSetting.vue (2 hunks)
  • packages/plugins/datasource/src/DataSourceForm.vue (2 hunks)
  • packages/plugins/datasource/src/DataSourceGlobalDataHandler.vue (2 hunks)
  • packages/plugins/datasource/src/DataSourceRecordList.vue (2 hunks)
  • packages/plugins/datasource/src/DataSourceRemotePanel.vue (3 hunks)
  • packages/plugins/page/src/PageFolderSetting.vue (2 hunks)
Files skipped from review due to trivial changes (1)
  • mockServer/assets/css/0.1.20/index.css
Files skipped from review as they are similar to previous changes (6)
  • packages/plugins/bridge/src/BridgeSetting.vue
  • packages/plugins/datasource/src/DataSourceForm.vue
  • packages/plugins/datasource/src/DataSourceGlobalDataHandler.vue
  • packages/plugins/datasource/src/DataSourceRecordList.vue
  • packages/plugins/datasource/src/DataSourceRemotePanel.vue
  • packages/plugins/page/src/PageFolderSetting.vue

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 f47ed92 and 2b07551.

Files selected for processing (1)
  • package.json (1 hunks)
Additional comments not posted (1)
package.json (1)

59-59: Dependency Addition Approved.

The addition of @vueuse/core with version ^9.6.0 is appropriate for enhancing the project's capabilities with utility functions for Vue.js applications.

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 2b07551 and 5e8365a.

Files selected for processing (1)
  • packages/design-core/src/DesignPlugins.vue (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/design-core/src/DesignPlugins.vue

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 5e8365a and 0eeabda.

Files selected for processing (1)
  • packages/plugins/page/src/PageSetting.vue (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/plugins/page/src/PageSetting.vue

@hexqi hexqi merged commit b28884b into opentiny:ospp-2024/002-plugin-layout Aug 14, 2024
1 check passed
@STATICHIT STATICHIT deleted the width-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