-
Notifications
You must be signed in to change notification settings - Fork 458
Feat/model driven:The model driver is optimized, and built-in interfaces for adding, deleting, modifying, and querying are added. #1756
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
base: develop
Are you sure you want to change the base?
Conversation
…into fix/model-driven
WalkthroughThe pull request replaces direct axios HTTP calls with a centralized meta API abstraction (getMetaApi) across form and table components, updates API request/response handling patterns, adjusts default values and validation rules, and adds a default value field to the field management interface. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Tip 🧪 Unit Test Generation v2 is now available!We have significantly improved our unit test generation capabilities. To enable: Add this to your reviews:
finishing_touches:
unit_tests:
enabled: trueTry it out by using the Have feedback? Share your thoughts on our Discord thread! Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
packages/plugins/model-manager/src/components/ModelBasicForm.vue (1)
42-64:⚠️ Potential issue | 🟡 MinorPreserve the default modelUrl on model switches
Line 42 and Line 60‑64:
localValueinitially merges the defaultmodelUrl, but the watcher replaces it withnewModel, which drops the default whenmodelUrlis absent. That makes the field empty after switching models. Reapply the default in the watcher (and avoidundefined/...when the env var is missing).🛠️ Suggested adjustment
-const localValue = ref({ modelUrl: `${import.meta.env.VITE_ORIGIN}/platform-center/api/model-data`, ...props.model }) +const origin = import.meta.env.VITE_ORIGIN ?? '' +const defaultModelUrl = `${origin}/platform-center/api/model-data` +const localValue = ref({ modelUrl: defaultModelUrl, ...props.model }) ... - (newModel) => { - localValue.value = newModel - }, + (newModel) => { + localValue.value = { modelUrl: defaultModelUrl, ...newModel } + },packages/builtinComponent/src/components/BaseForm.vue (1)
128-140:⚠️ Potential issue | 🟠 MajorAvoid mutating form state by deleting
idLine 133‑139:
delete data.idmutates the reactive model (modelData.value) and can drop the id needed for later update/delete flows. Build a copy for the payload instead.🛠️ Suggested adjustment
- const id = data.id - delete data.id + const { id, ...payload } = data ? { ...data } : {} return getMetaApi(META_SERVICE.Http) .post(apiInfo.url, { nameEn: formModel.value.nameEn, - data: data, + data: payload, params: { id } })packages/builtinComponent/src/components/BaseTable.vue (1)
167-175:⚠️ Potential issue | 🔴 CriticalFix undefined
tableModelreferences in CRUD helpersLine 173/191/214/234:
tableModelis not declared (onlyTableModelexists). Any CRUD call will throw a ReferenceError. UseTableModelconsistently.🛠️ Suggested adjustment
- .post(apiInfo.url, { nameEn: tableModel.value.nameEn, params: data }) + .post(apiInfo.url, { nameEn: TableModel.value.nameEn, params: data }) ... - nameEn: tableModel.value.nameEn, + nameEn: TableModel.value.nameEn, ... - nameEn: tableModel.value.nameEn, - nameCn: tableModel.value.nameCn, + nameEn: TableModel.value.nameEn, + nameCn: TableModel.value.nameCn, ... - .post(apiInfo.url, { ...evidence, nameEn: tableModel.value.nameEn }) + .post(apiInfo.url, { ...evidence, nameEn: TableModel.value.nameEn })Also applies to: 182-194, 203-216, 228-235
packages/builtinComponent/src/components/BasePage.vue (1)
320-332:⚠️ Potential issue | 🟠 MajorDon’t delete
idfrom edit form dataLine 325‑332: updateApi removes
data.idin place, which mutatesaddFormDataand can cause the dialog to lose the record id. Use a payload copy without mutating form state.🛠️ Suggested adjustment
- const id = data.id - delete data.id + const { id, ...payload } = data ? { ...data } : {} return getMetaApi(META_SERVICE.Http) .post(apiInfo.url, { nameEn: pageModel.value.nameEn, - data: data, + data: payload, params: { id } })
🤖 Fix all issues with AI agents
In `@packages/configurator/src/model-api-configurator/ModelApiConfigurator.vue`:
- Around line 175-178: getModel currently only sets selectedModel and
methodBasicData.method, which can leave stale values in selectedFunction and
methodBasicData.url; update getModel to also clear selectedFunction (e.g. reset
selectedFunction or selectedFunction.value) and reset methodBasicData.url to an
empty string when switching models, keeping the existing methodBasicData.method
= 'post' behavior and ensuring you clear the reactive references
(selectedFunction and methodBasicData.url) so the UI does not show stale data.
In `@packages/plugins/model-manager/src/components/FieldManager.vue`:
- Around line 89-95: The inline edit for the defaultValue column must be
disabled for ModelRef types and the read-only cell should show the referenced
model's label instead of the raw ID: update the tiny-grid-column template (the
block using row.isEditing and row.defaultValue) to conditionally render the
tiny-input only when row.type !== 'ModelRef', and for ModelRef rows render the
resolved label (e.g., use an existing property like row.defaultValueLabel or
call a resolver method such as resolveModelLabel(row.defaultValue)). Ensure any
v-model binding to row.defaultValue is not applied for ModelRef in-line edits so
the expanded-panel select remains the single source of truth and invalid IDs
cannot be persisted.
| const getModel = (data) => { | ||
| selectedModel.value = data | ||
| methodBasicData.url = data.baseUrl | ||
| methodBasicData.method = 'post' | ||
| } |
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.
Reset selected function and URL on model change
Line 175‑178: getModel now only resets the method. If a previous function was selected, selectedFunction and methodBasicData.url can stay populated, showing stale data for a different model. Clear them when the model changes.
🛠️ Suggested adjustment
const getModel = (data) => {
selectedModel.value = data
methodBasicData.method = 'post'
+ methodBasicData.url = ''
+ selectedFunction.value = null
}📝 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 getModel = (data) => { | |
| selectedModel.value = data | |
| methodBasicData.url = data.baseUrl | |
| methodBasicData.method = 'post' | |
| } | |
| const getModel = (data) => { | |
| selectedModel.value = data | |
| methodBasicData.method = 'post' | |
| methodBasicData.url = '' | |
| selectedFunction.value = null | |
| } |
🤖 Prompt for AI Agents
In `@packages/configurator/src/model-api-configurator/ModelApiConfigurator.vue`
around lines 175 - 178, getModel currently only sets selectedModel and
methodBasicData.method, which can leave stale values in selectedFunction and
methodBasicData.url; update getModel to also clear selectedFunction (e.g. reset
selectedFunction or selectedFunction.value) and reset methodBasicData.url to an
empty string when switching models, keeping the existing methodBasicData.method
= 'post' behavior and ensuring you clear the reactive references
(selectedFunction and methodBasicData.url) so the UI does not show stale data.
| <tiny-grid-column field="defaultValue" title="默认值" width="120"> | ||
| <template #default="{ row }"> | ||
| <div v-if="row.isEditing" class="editing-cell"> | ||
| <tiny-input v-model="row.defaultValue" placeholder="请输入默认值" size="small" /> | ||
| </div> | ||
| <div v-else class="readonly-cell">{{ row.defaultValue }}</div> | ||
| </template> |
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.
Guard ModelRef defaultValue edits to avoid invalid IDs
Line 91-95: the new defaultValue column uses a free‑text input for all types. For ModelRef, this can conflict with the select in the expanded panel and persist invalid IDs; the read‑only view also shows the raw ID. Consider disabling the inline edit for ModelRef and rendering the label instead.
🛠️ Suggested adjustment
- <div v-if="row.isEditing" class="editing-cell">
- <tiny-input v-model="row.defaultValue" placeholder="请输入默认值" size="small" />
- </div>
- <div v-else class="readonly-cell">{{ row.defaultValue }}</div>
+ <div v-if="row.isEditing" class="editing-cell">
+ <tiny-input
+ v-model="row.defaultValue"
+ placeholder="请输入默认值"
+ size="small"
+ :disabled="row.type === 'ModelRef'"
+ />
+ </div>
+ <div v-else class="readonly-cell">
+ {{ row.type === 'ModelRef' ? getModelName(row.defaultValue) : row.defaultValue }}
+ </div>🤖 Prompt for AI Agents
In `@packages/plugins/model-manager/src/components/FieldManager.vue` around lines
89 - 95, The inline edit for the defaultValue column must be disabled for
ModelRef types and the read-only cell should show the referenced model's label
instead of the raw ID: update the tiny-grid-column template (the block using
row.isEditing and row.defaultValue) to conditionally render the tiny-input only
when row.type !== 'ModelRef', and for ModelRef rows render the resolved label
(e.g., use an existing property like row.defaultValueLabel or call a resolver
method such as resolveModelLabel(row.defaultValue)). Ensure any v-model binding
to row.defaultValue is not applied for ModelRef in-line edits so the
expanded-panel select remains the single source of truth and invalid IDs cannot
be persisted.
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?
后端内置了增删改查接口,前端改动自动匹配对应接口,如果需要修改为自己的接口就改动baseUrl即可
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Refactor
Chores
✏️ Tip: You can customize this high-level summary in your review settings.