fix: fixed material generation and database connection for components#1152
fix: fixed material generation and database connection for components#1152Ljhhhhhh wants to merge 6 commits intoopentiny:developfrom
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
WalkthroughThe changes involve multiple files. In Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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
packages/canvas/render/src/application-function/global-state.tsOops! Something went wrong! :( ESLint: 8.57.1 ESLint couldn't find the plugin "@typescript-eslint/eslint-plugin". (The package "@typescript-eslint/eslint-plugin" was not found when loaded as a Node module from the directory "/packages/canvas".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following: The plugin "@typescript-eslint/eslint-plugin" was referenced from the config file in "packages/canvas/.eslintrc.cjs » @vue/eslint-config-typescript". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🔇 Additional comments (3)
✨ Finishing Touches
🪧 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.
Actionable comments posted: 3
🧹 Nitpick comments (2)
scripts/connection.mjs (2)
205-208: Provide concrete deprecation timeline and usage details.
Using@deprecatedis a good start, but consider documenting the removal version or guiding developers how to migrate to the newerrelationMaterialHistorymethod. This ensures a clear path forward.
301-308: Hard-coded defaults might limit flexibility.
The new fields (component_metadata,library_id,tenant_id,renter_id,site_id,created_by,last_updated_by) default tonullor1. If multiple tenants or sites exist, these static values may cause conflicts.Do you want to parameterize these fields or load them from environment variables for increased flexibility?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
scripts/buildMaterials.mjs(1 hunks)scripts/connection.mjs(6 hunks)
🔇 Additional comments (2)
scripts/buildMaterials.mjs (1)
153-154: Destructuring logic looks solid.
Extractingpackage,version, andexportNamefromnpmearly on prevents undefined errors and maintains readability. The fallback to{}ensures safe defaults ifnpmis missing.scripts/connection.mjs (1)
18-20: Verify references after renaming table and altering history ID.
Renaming the table to't_component'and resettingmaterialHistoryIdto1could potentially break references in other parts of the code if they rely on the old table name or on the previous history ID.Would you like me to generate a script to find any remaining references to the old table name or history ID?
| 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.
Schema mismatch for “name_en” and “component_metadata”.
This insert statement references name_en and component_metadata, but the table definition does not declare a name_en column. This will fail unless the table schema is updated accordingly.
A possible fix in your CREATE TABLE statement might be:
CREATE TABLE t_component (
...
+ name_en varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
component_metadata longtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
...
);Committable suggestion skipped: line range outside the PR's diff.
| /** | ||
| * 新建的组件关联物料资产包 | ||
| * @param {number} id 新建的组件id | ||
| */ | ||
| relationMaterialHistory(id) { | ||
| const uniqSql = `SELECT * FROM \`r_material_history_component\` WHERE \`material_history_id\`=${materialHistoryId} AND \`component_id\`=${id}` | ||
| this.query(uniqSql).then((result) => { | ||
| if (!result.length) { | ||
| const sqlContent = `INSERT INTO \`r_material_history_component\` (\`material_history_id\`, \`component_id\`) VALUES (${materialHistoryId}, ${id})` | ||
| this.query(sqlContent) | ||
| } | ||
| }) | ||
| } | ||
|
|
There was a problem hiding this comment.
Use parameterized queries to prevent SQL injection.
Directly concatenating id into the SQL statement may be risky if the value is not guaranteed to be an integer. Parameterized queries will secure this method and help avoid potential injection vulnerabilities.
Possible fix using placeholders (for example in MySQL Node libraries):
- const uniqSql = `SELECT * FROM \`r_material_history_component\` WHERE \`material_history_id\`=${materialHistoryId} AND \`component_id\`=${id}`
- ...
- const sqlContent = `INSERT INTO \`r_material_history_component\` (\`material_history_id\`, \`component_id\`) VALUES (${materialHistoryId}, ${id})`
+ const uniqSql = 'SELECT * FROM `r_material_history_component` WHERE `material_history_id` = ? AND `component_id` = ?'
+ ...
+ const sqlContent = 'INSERT INTO `r_material_history_component` (`material_history_id`, `component_id`) VALUES (?, ?)'
...Committable suggestion skipped: line range outside the PR's diff.
新增判断条件,默认为空对象
- 重构 global-state.ts 中的状态处理,支持数组和对象类型的状态计算 - 修改 VariableConfigurator.vue 中的变量加载方式 - 更新 useResource 中的应用状态获取逻辑,增加兼容性
The commit here is repeated with the commit of #1208, so it needs to be separated. |
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