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

fix: fixed material generation and database connection for components #1151

Closed
wants to merge 2 commits into from

Conversation

Ljhhhhhh
Copy link

@Ljhhhhhh Ljhhhhhh commented Feb 27, 2025

…t libraries

  • Add support for TinyVue and Element Plus component libraries in material generation
  • Update database connection script with new table and column names
  • Modify component insertion logic to match new database schema
  • Add version and script details for third-party component libraries

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

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 enhanced package integration that streamlines the use of popular UI component libraries with up-to-date asset details.
    • Added a new method for material history retrieval, with a deprecation notice for the previous method.
  • Refactor

    • Improved component data handling and backend connectivity to boost consistency and reliability during component operations.
    • Updated database interaction logic for better structure and clarity in component metadata.

…t libraries

- Add support for TinyVue and Element Plus component libraries in material generation
- Update database connection script with new table and column names
- Modify component insertion logic to match new database schema
- Add version and script details for third-party component libraries
Copy link
Contributor

coderabbitai bot commented Feb 27, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update modifies the generateComponents function in scripts/buildMaterials.mjs to change the declaration order of certain variables. In scripts/connection.mjs, significant alterations include renaming methods, updating SQL queries and table names, and restructuring parameters for database interactions related to components. A new method has been added, and a deprecation notice has been introduced for the previous method, reflecting a comprehensive restructuring of the database interactions and component data model.

Changes

File(s) Change Summary
scripts/buildMaterials.mjs Modified the generateComponents function to declare packageName, version, and exportName variables before their first use, ensuring they are available for subsequent logic without altering functionality.
scripts/connection.mjs Updated DB interaction logic: changed table names (e.g., from user_components to t_component), adjusted SQL queries in initDB and relation methods, renamed relationMaterialHistory to relationMaterialBlockHistory, introduced a new relationMaterialHistory with a deprecation notice, and restructured parameters for insertComponent with new metadata fields.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client Request
    participant MC as MysqlConnection
    participant DB as Database
    C->>MC: Call relationMaterialHistory(id)
    MC->>DB: Execute SQL query on updated table
    DB-->>MC: Return query result
    Note over MC: Also includes updated handling in \n insertComponent and initDB\n with new parameters and table names.
Loading

Suggested labels

refactor-main

Suggested reviewers

  • hexqi
  • chilingling

Poem

In fields of code I softly hop,
A curious rabbit, eager to explore,
New packages and queries, a joyful crop,
Dancing through files like never before.
With tweaks and updates, my heart does pop!
🐰💻 Hop along to sync and soar!


📜 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 1c4b640 and 67760dc.

📒 Files selected for processing (1)
  • scripts/buildMaterials.mjs (1 hunks)

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.
  • @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.

@github-actions github-actions bot added the enhancement New feature or request label Feb 27, 2025
@Ljhhhhhh Ljhhhhhh changed the title feat: update material generation and database connection for components fix: fixed material generation and database connection for components Feb 27, 2025
@github-actions github-actions bot added bug Something isn't working and removed enhancement New feature or request labels Feb 27, 2025
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

🧹 Nitpick comments (1)
scripts/connection.mjs (1)

208-208: Preserve or remove the old relation method consistently.

The function relationMaterialBlockHistory is marked as deprecated while referencing the old table. If it isn’t used anywhere, consider removing it altogether to avoid confusion.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 36a2b5e and 1c4b640.

📒 Files selected for processing (2)
  • scripts/buildMaterials.mjs (2 hunks)
  • scripts/connection.mjs (6 hunks)
🧰 Additional context used
🪛 ESLint
scripts/buildMaterials.mjs

[error] 176-176: 'packages' is not defined.

(no-undef)

🔇 Additional comments (5)
scripts/buildMaterials.mjs (2)

96-97: No issues found with snippets initialization.

Defining snippets as an empty array helps ensure consistent data structure in the material bundle before merging snippet data.


98-114: Consider reconciling mismatch between version fields.

You’re specifying "version": "3.20.0" for TinyVue but using a script tagged at @~3.14. Verify that the intended versions are correct and consistent to avoid future maintenance confusion. The same applies to other packages if any version mismatch arises.

scripts/connection.mjs (3)

18-20: Confirm table and material history references.

Renaming the table to t_component and changing materialHistoryId to 1 may break existing references or queries if other parts of the codebase still expect the old table or ID.


219-231: New method introduced for relating material histories.

The new function relationMaterialHistory(id) references a different table (r_material_history_component). This is clearer than the old approach. Double-check if any existing calls need updating.


300-306: Validate default metadata fields for multi-tenant environments.

Defaulting every field (e.g., tenant_id = 1) might override intended multi-tenant or user-specific data. Ensure these defaults are correct and do not inadvertently break usage for different tenants or sites.

Comment on lines 171 to 185
const { package: packageName = '', version = '', exportName = '' } = npm || {}

if (connection.connected) {
if (material.npm) {
// 给组件添加 npm 来源详细信息
const packageItem = packages.find((item) => item.package === packageName)

if (packageItem) {
material.npm.version = packageItem.version
material.npm.script = packageItem.script
material.npm.css = packageItem.css
material.npm.destructuring = packageItem.destructuring
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix reference error: 'packages' is not defined.

The ESLint error and runtime failure occur because packages is never declared within this scope. Use the packages array from bundle.data.materials instead:

-            const packageItem = packages.find((item) => item.package === packageName)
+            const packageItem = bundle.data.materials.packages.find((item) => item.package === packageName)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const { package: packageName = '', version = '', exportName = '' } = npm || {}
if (connection.connected) {
if (material.npm) {
// 给组件添加 npm 来源详细信息
const packageItem = packages.find((item) => item.package === packageName)
if (packageItem) {
material.npm.version = packageItem.version
material.npm.script = packageItem.script
material.npm.css = packageItem.css
material.npm.destructuring = packageItem.destructuring
}
}
const { package: packageName = '', version = '', exportName = '' } = npm || {}
if (connection.connected) {
if (material.npm) {
// 给组件添加 npm 来源详细信息
const packageItem = bundle.data.materials.packages.find((item) => item.package === packageName)
if (packageItem) {
material.npm.version = packageItem.version
material.npm.script = packageItem.script
material.npm.css = packageItem.css
material.npm.destructuring = packageItem.destructuring
}
}
🧰 Tools
🪛 ESLint

[error] 176-176: 'packages' is not defined.

(no-undef)

@@ -335,7 +359,7 @@ class MysqlConnection {
* @param {object} component 组件数据
*/
initDB(component) {
const selectSqlContent = `SELECT * FROM ${this.config.database}.${componentsTableName} WHERE component = '${component.component}'`
const selectSqlContent = `SELECT * FROM ${this.config.database}.${componentsTableName} WHERE name_en = '${component.component}'`
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

name_en column might not exist.

The SELECT query uses WHERE name_en = ..., but your table definition does not show a name_en column. This will likely fail. Update the query or your schema.

Comment on lines +340 to +343
const sqlContent = `INSERT INTO ${componentsTableName} (version, name, name_en, icon, description, doc_url,
screenshot, tags, keywords, dev_mode, npm, \`group\`, \`category\`, priority, snippets,
schema_fragment, configure, \`public\`, framework, isOfficial, isDefault, tiny_reserved,
tenant, createdBy, updatedBy) VALUES ${values}`.replace(/\n/g, '')
schema_fragment, configure, \`public\`, framework, is_official, is_default, tiny_reserved,component_metadata,
library_id, tenant_id, renter_id, site_id, created_by, last_updated_by) VALUES ${values}`.replace(/\n/g, '')
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Mismatch between code and table definition for library_id.

Your CREATE TABLE statement defines a column named library, but the INSERT statement uses library_id. Update either the code or the schema to match.

-         library_id, tenant_id, renter_id, site_id, created_by, last_updated_by
+         library, tenant_id, renter_id, site_id, created_by, last_updated_by
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const sqlContent = `INSERT INTO ${componentsTableName} (version, name, name_en, icon, description, doc_url,
screenshot, tags, keywords, dev_mode, npm, \`group\`, \`category\`, priority, snippets,
schema_fragment, configure, \`public\`, framework, isOfficial, isDefault, tiny_reserved,
tenant, createdBy, updatedBy) VALUES ${values}`.replace(/\n/g, '')
schema_fragment, configure, \`public\`, framework, is_official, is_default, tiny_reserved,component_metadata,
library_id, tenant_id, renter_id, site_id, created_by, last_updated_by) VALUES ${values}`.replace(/\n/g, '')
const sqlContent = `INSERT INTO ${componentsTableName} (version, name, name_en, icon, description, doc_url,
screenshot, tags, keywords, dev_mode, npm, \`group\`, \`category\`, priority, snippets,
schema_fragment, configure, \`public\`, framework, is_official, is_default, tiny_reserved,component_metadata,
library, tenant_id, renter_id, site_id, created_by, last_updated_by) VALUES ${values}`.replace(/\n/g, '')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant