-
Notifications
You must be signed in to change notification settings - Fork 354
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
Conversation
…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
Caution Review failedThe pull request is closed. WalkthroughThis update modifies the Changes
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.
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📒 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 withsnippets
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 changingmaterialHistoryId
to1
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.
scripts/buildMaterials.mjs
Outdated
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 | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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}'` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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, '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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, '') |
…t libraries
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Refactor