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: table search form visible control #5121

Merged
merged 3 commits into from
Dec 12, 2024

Conversation

mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Dec 12, 2024

Description

为表格添加控制搜索表单区域是否可见的方法,并添加一个名为search的工具按钮(可在toolbarConfig中配置是否可以显示)

image

image

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced documentation for the Vben Vxe Table component, including configuration details for the search form and API methods.
    • Added a search control button in the toolbar for improved user interaction.
    • Introduced new properties and methods to manage the visibility of the search form.
    • Added new properties for toolbar configuration, enhancing grid functionality.
  • Localization

    • Added new localization entries for search functionality in English and Chinese.
  • Improvements

    • Updated grid options to include new properties for better control and functionality of the VxeGrid component.
    • Improved type definitions for enhanced type safety across components.

@mynetfan mynetfan requested review from anncwb, vince292007 and a team as code owners December 12, 2024 14:02
Copy link

changeset-bot bot commented Dec 12, 2024

⚠️ No Changeset found

Latest commit: 2b846d2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/effects/plugins/src/vxe-table/api.ts

Oops! Something went wrong! :(

ESLint: 9.16.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/node_modules/@vben/eslint-config/dist/index.mjs' imported from /eslint.config.mjs
at finalizeResolution (node:internal/modules/esm/resolve:257:11)
at moduleResolve (node:internal/modules/esm/resolve:914:10)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

Walkthrough

The pull request introduces enhancements to the Vben Vxe Table component, focusing on the search functionality. Key updates include the addition of a toggleSearchForm method and a showSearchForm property to control the visibility of the search form. The documentation has been updated to reflect these changes, and new configurations have been added to the grid options, particularly the toolbarConfig for search controls. Localization files have also been updated to include new search-related terms in English and Chinese.

Changes

File Path Change Summary
docs/src/components/common-ui/vben-vxe-table.md Updated documentation to include toggleSearchForm method and showSearchForm property details.
docs/src/demos/vben-vxe-table/form/index.vue Added toolbarConfig property with search boolean in gridOptions.
packages/effects/plugins/src/vxe-table/api.ts Introduced showSearchForm property and toggleSearchForm method in VxeGridApi.
packages/effects/plugins/src/vxe-table/index.ts Added export for VxeTableGridOptions type and updated export for VbenVxeGrid.
packages/effects/plugins/src/vxe-table/types.ts Added ToolbarConfigOptions and VxeTableGridOptions interfaces; updated VxeGridProps.
packages/effects/plugins/src/vxe-table/use-vxe-grid.vue Updated toolbar options and added onToolbarToolClick function for handling search form toggling.
packages/locales/src/langs/en-US/common.json Added "search": "Search" key for localization.
packages/locales/src/langs/zh-CN/common.json Added "search": "搜索" key for localization.
playground/src/views/examples/vxe-table/custom-cell.vue Added showOverflow property in gridOptions.
playground/src/views/examples/vxe-table/form.vue Updated gridOptions type to VxeTableGridOptions and added new properties in gridOptions.

Possibly related PRs

Suggested labels

feature

Suggested reviewers

  • vince292007
  • anncwb

Poem

🐰 In the meadow, changes bloom,
With search forms now, there's more room.
Toggle and show, the options are bright,
Vben Vxe Table, a new delight!
Hop along, let the features play,
Enhancing our tables, day by day! 🌼


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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

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: 3

🧹 Outside diff range and nitpick comments (4)
packages/effects/plugins/src/vxe-table/use-vxe-grid.vue (1)

109-123: Simplify Conditional Logic for Toolbar Tools

The conditional assignment for toolbarConfig.tools works correctly but can be made more readable.

Consider extracting the condition into a descriptive variable:

const showSearchTool = gridOptions.value?.toolbarConfig?.search && !!formOptions.value;

const toolbarConfig: VxeGridPropTypes.ToolbarConfig = {
  tools: showSearchTool
    ? [
        {
          code: 'search',
          icon: 'vxe-icon--search',
          circle: true,
          status: isFormShow.value ? 'primary' : undefined,
          title: $t('common.search'),
        },
      ]
    : [],
};

This enhances readability by making the purpose of the condition clearer.

packages/effects/plugins/src/vxe-table/types.ts (1)

22-25: LGTM: Well-documented toolbar search option

The ToolbarConfigOptions interface is well-defined with clear JSDoc comments in Chinese. Consider adding English translations for better international developer experience.

playground/src/views/examples/vxe-table/form.vue (1)

88-88: Consider configuring exportConfig

An empty exportConfig object is added but not configured. Consider adding necessary export configuration or removing if not needed.

docs/src/components/common-ui/vben-vxe-table.md (1)

168-169: Enhance search form documentation with examples

While the documentation explains the feature, it would be more helpful with code examples.

Consider adding a code example showing how to configure and use the search form visibility control:

// Example configuration
const gridOptions = {
  toolbarConfig: {
    search: true, // Enable search form control button
  },
};

// Example usage with API
gridApi.toggleSearchForm(); // Toggle visibility
gridApi.setFormVisible(false); // Hide form
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d308da6 and 0a887d3.

📒 Files selected for processing (10)
  • docs/src/components/common-ui/vben-vxe-table.md (3 hunks)
  • docs/src/demos/vben-vxe-table/form/index.vue (1 hunks)
  • packages/effects/plugins/src/vxe-table/api.ts (4 hunks)
  • packages/effects/plugins/src/vxe-table/index.ts (1 hunks)
  • packages/effects/plugins/src/vxe-table/types.ts (4 hunks)
  • packages/effects/plugins/src/vxe-table/use-vxe-grid.vue (5 hunks)
  • packages/locales/src/langs/en-US/common.json (1 hunks)
  • packages/locales/src/langs/zh-CN/common.json (1 hunks)
  • playground/src/views/examples/vxe-table/custom-cell.vue (1 hunks)
  • playground/src/views/examples/vxe-table/form.vue (4 hunks)
🔇 Additional comments (17)
packages/effects/plugins/src/vxe-table/use-vxe-grid.vue (4)

4-6: Approved: Imported Types from 'vxe-table'

The addition of VxeGridDefines and VxeGridPropTypes imports enhances type safety for the component.


62-62: Approved: Added 'isFormShow' to prioritized values

Including isFormShow allows the component to control the visibility of the form based on priority values.


117-117: Confirm Usage of 'status' Property

The status property is set to 'primary' when isFormShow.value is true. Ensure that 'primary' is a valid status value for styling the toolbar button in your UI library.

Check the documentation of the button component to confirm that the status prop accepts 'primary' and applies the desired styling.


335-339: Review Change from 'v-if' to 'v-show'

Switching from v-if to v-show alters how the form component is managed in the DOM.

  • v-if removes the element from the DOM when the condition is false, which resets component state.
  • v-show toggles the visibility but keeps the component in the DOM, preserving its state.

Ensure that:

  • Keeping the form's state when hidden is intentional.
  • There are no unintended side effects from preserving the form's state.

If the form should reset when hidden, consider retaining v-if.

packages/locales/src/langs/zh-CN/common.json (1)

13-13: Clarify Distinction Between 'query' and 'search'

Both "query" and "search" are translated as "搜索".

  • If both keys serve different purposes, consider using distinct translations to avoid confusion.
  • If they are interchangeable, one key may suffice.

Review the usage context to determine if both keys are necessary.

packages/effects/plugins/src/vxe-table/index.ts (2)

2-2: Approved: Exporting 'VxeTableGridOptions'

Exporting VxeTableGridOptions makes the type available for external use, enhancing type definitions.


5-5: Approved: Reordered Export Statements

Reordering exports improves code organization without affecting functionality.

packages/locales/src/langs/en-US/common.json (1)

13-13: Differentiate Between 'query' and 'search'

Both "query" and "search" have the value "Search".

  • Determine if the two keys are intended for different contexts.
  • If they have distinct meanings, consider updating one of the values to reflect this difference.

This will help maintain clarity in the application's UI text.

packages/effects/plugins/src/vxe-table/types.ts (1)

51-51: Verify impact of gridOptions type change

The change from VxeTableGridProps to VxeTableGridOptions for gridOptions type could affect existing code.

Also applies to: 60-63

✅ Verification successful

No breaking changes from gridOptions type update

The type change is safe because:

  • VxeTableGridOptions extends VxeTableGridProps, maintaining backward compatibility
  • All existing usages of gridOptions in the codebase are using the implementation type (VxeGridProps['gridOptions']) or object literals, not the VxeTableGridProps type directly
  • The type is only used as an optional property with DeepPartial, providing additional flexibility
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing gridOptions usage that might be affected
rg "gridOptions.*:.*VxeTableGridProps" --type ts

Length of output: 50


Script:

#!/bin/bash
# Search for any usage of gridOptions in TypeScript files
rg "gridOptions" --type ts -A 2

# Also search for VxeTableGridProps type references
rg "VxeTableGridProps" --type ts -A 2

# Search for imports or type definitions related to VxeTable grid types
rg "(VxeTableGridProps|VxeTableGridOptions)" --type ts

Length of output: 2209

playground/src/views/examples/vxe-table/custom-cell.vue (1)

85-85: Verify visual impact of disabled overflow

Setting showOverflow: false might affect how cell content is displayed, especially for the Product Name column which could contain long text.

Consider testing with various content lengths to ensure proper display.

playground/src/views/examples/vxe-table/form.vue (2)

104-111: LGTM: Comprehensive toolbar configuration

The toolbar configuration enables all necessary features including search, which aligns with the PR objective. The configuration is well-structured and includes useful additional features like export and zoom.


114-117: LGTM: Improved parameter structure

The useVbenVxeGrid call has been restructured for better readability while maintaining functionality.

packages/effects/plugins/src/vxe-table/api.ts (3)

24-24: LGTM: Default state initialization

The isFormShow property is properly initialized with a sensible default value.


85-89: LGTM: Clean implementation of setFormVisible

The method provides direct control over form visibility with a clear and concise implementation.


119-127: Address commented out grid recalculation code

The commented out grid recalculation code suggests a potential layout issue that was encountered during development.

Please verify if removing the grid recalculation affects the layout when toggling the form visibility. Consider either:

  1. Removing the commented code if it's not needed
  2. Implementing the recalculation if it's necessary for proper layout
docs/src/components/common-ui/vben-vxe-table.md (2)

220-228: LGTM: Clear API documentation

The API documentation for the new methods is clear and well-structured.


242-242: LGTM: Props documentation

The isFormShow prop is properly documented with a clear description.

packages/effects/plugins/src/vxe-table/use-vxe-grid.vue Outdated Show resolved Hide resolved
packages/effects/plugins/src/vxe-table/types.ts Outdated Show resolved Hide resolved
docs/src/demos/vben-vxe-table/form/index.vue Show resolved Hide resolved
@zwtvip
Copy link

zwtvip commented Dec 12, 2024

大神,isFormShow 改成 isShowForm 写起来会不会顺畅点 个人愚见,见谅,可以无视

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

🧹 Outside diff range and nitpick comments (3)
packages/effects/plugins/src/vxe-table/types.ts (2)

22-25: LGTM! Consider adding English documentation.

The interface is well-defined and properly extends the base type. Consider adding English documentation for better international developer experience.

 interface ToolbarConfigOptions extends VxeGridPropTypes.ToolbarConfig {
-  /** 是否显示切换搜索表单的按钮 */
+  /** Whether to show the search form toggle button
+   * 是否显示切换搜索表单的按钮
+   */
   search?: boolean;
 }

52-52: LGTM! Consider adding English documentation.

The type changes are correct and maintain type safety. Consider adding English documentation for better international developer experience.

   gridOptions?: DeepPartial<VxeTableGridOptions>;
   /**
-   * 显示搜索表单
+   * Whether to show the search form
+   * 显示搜索表单
    */
   showSearchForm?: boolean;

Also applies to: 61-64

packages/effects/plugins/src/vxe-table/use-vxe-grid.vue (1)

110-140: Clean up commented code.

The toolbar configuration is implemented correctly, but there are unnecessary commented-out code blocks that should be removed for better maintainability.

-  // if (gridOptions.value?.toolbarConfig?.search) {
-  // }
-  // 强制使用固定的toolbar配置,不允许用户自定义
-  // 减少配置的复杂度,以及后续维护的成本
   toolbarConfig.slots = {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0a887d3 and 2b846d2.

📒 Files selected for processing (4)
  • docs/src/components/common-ui/vben-vxe-table.md (3 hunks)
  • packages/effects/plugins/src/vxe-table/api.ts (3 hunks)
  • packages/effects/plugins/src/vxe-table/types.ts (4 hunks)
  • packages/effects/plugins/src/vxe-table/use-vxe-grid.vue (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/src/components/common-ui/vben-vxe-table.md
🔇 Additional comments (6)
packages/effects/plugins/src/vxe-table/types.ts (1)

27-30: LGTM! Good choice making toolbarConfig optional.

The interface is well-defined and making toolbarConfig optional maintains backward compatibility with existing implementations.

packages/effects/plugins/src/vxe-table/api.ts (2)

24-24: LGTM! Good default value choice.

Setting showSearchForm to true by default maintains backward compatibility with existing implementations.


113-121: Verify if grid recalculation is needed after toggling.

The implementation is correct, but the commented-out recalculation code suggests potential layout issues. Consider testing with various scenarios to verify if grid recalculation is necessary.

✅ Verification successful

Let me search for more context about the grid component and visibility changes.


Let me search for one more thing to understand the grid's layout behavior.


Based on the gathered evidence, I can now provide the final response:

Grid recalculation after toggling search form can be safely removed

The codebase analysis shows that:

  • The search form's visibility is controlled by a simple v-show directive in the template
  • No other implementations require grid recalculation after visibility changes
  • The form layout is handled independently through Vue's reactive system

The commented-out recalculation code appears to be unnecessary overhead and can be safely removed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other implementations that might require recalculation after visibility changes
rg -A 3 'recalculate|updateLayout' 

Length of output: 308


Script:

#!/bin/bash
# Search for grid-related visibility changes and layout updates
rg -A 5 'showSearchForm|show.*Form.*grid' 

# Search for grid component implementation
ast-grep --pattern 'class $_ {
  $$$
  grid
  $$$
}'

Length of output: 3263


Script:

#!/bin/bash
# Search for grid layout-related code and recalculation patterns
ast-grep --pattern 'grid.$$$recalculate'

# Look for form-related layout updates
rg -A 3 'form.*layout|layout.*form'

Length of output: 496

packages/effects/plugins/src/vxe-table/use-vxe-grid.vue (3)

4-7: LGTM! Good type imports.

The added type imports are appropriate and used correctly throughout the code.


337-341: LGTM! Good use of v-show directive.

Using v-show instead of v-if is a good choice for frequently toggled elements as it's more performant. The class handling is also implemented correctly.


196-203: 🛠️ Refactor suggestion

Improve type safety in event handling.

The event handling is implemented correctly, but the type assertion could be improved for better type safety.

-  (
-    gridEvents.value?.toolbarToolClick as VxeGridListeners['toolbarToolClick']
-  )?.(event);
+  const handler = gridEvents.value?.toolbarToolClick;
+  if (handler && typeof handler === 'function') {
+    (handler as VxeGridListeners['toolbarToolClick'])(event);
+  }

Likely invalid or redundant comment.

@mynetfan
Copy link
Collaborator Author

大神,isFormShow 改成 isShowForm 写起来会不会顺畅点 个人愚见,见谅,可以无视

改成了showSearchForm,这个应该用的少,基本上也只是将搜索表单设为默认不显示时可能会用到。

@mynetfan mynetfan merged commit ed465d2 into vbenjs:main Dec 12, 2024
14 checks passed
@mynetfan mynetfan deleted the feat/toggle-table-form branch December 12, 2024 14:28
@anncwb anncwb added the feature label Dec 12, 2024
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.

3 participants