fix: onUpdate prefix event name faild to save#1778
fix: onUpdate prefix event name faild to save#1778chilingling wants to merge 1 commit intoopentiny:developfrom
Conversation
WalkthroughA new regular expression constant for validating update event names is exported from the verification module, and the BlockEventForm component is refactored to use centralized regex patterns for event name validation instead of inline checks. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 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)
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.
🧹 Nitpick comments (1)
packages/plugins/block/src/BlockEventForm.vue (1)
140-147: Consider extracting shared validation logic to reduce duplication.The update-event validation (
REGEXP_UPDATE_EVENT_NAME.test() && propertys.value.some(...)) is duplicated between the form validator (lines 114-117) andchangeEventName. If validation criteria change, both locations must be updated.♻️ Suggested refactor to extract validation helper
+ const isValidUpdateEventName = (name: string) => + REGEXP_UPDATE_EVENT_NAME.test(name) && + propertys.value.some((item: any) => item.property === name.replace('onUpdate:', '')) + const rules = { eventName: [ { validator: (_rule: any /* IFormInnerRule */, value: string, callback: (e?: Error) => void) => { if (isUpdateEvent.value) { - const matched = REGEXP_UPDATE_EVENT_NAME.test(value) - const propertyMatched = propertys.value.some((item) => item.property === value.replace('onUpdate:', '')) - return matched && propertyMatched + return isValidUpdateEventName(value) ? callback() : callback(new Error(`${value} 需要有对应的 ${value.replace('onUpdate:', '')} 在属性中定义`)) }const changeEventName = () => { const isEventNameValid = isUpdateEvent.value - ? REGEXP_UPDATE_EVENT_NAME.test(formData.eventName) && - propertys.value.some((item: any) => item.property === formData.eventName.replace('onUpdate:', '')) + ? isValidUpdateEventName(formData.eventName) : verifyEventName(formData.eventName)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/plugins/block/src/BlockEventForm.vue` around lines 140 - 147, The update-event validation logic (REGEXP_UPDATE_EVENT_NAME.test(...) && propertys.value.some(...)) is duplicated between the form validator and the changeEventName block; extract that into a single helper (e.g., isUpdateEventNameValid(eventName) or validateEventNameForUpdate) that uses REGEXP_UPDATE_EVENT_NAME and propertys.value to check the stripped name, then replace the duplicated checks in the form validation and in the changeEventName flow (where isEventNameValid is computed and used before calling renameBlockEventName/getEditEventName) to call the new helper, keeping verifyEventName for non-update cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/plugins/block/src/BlockEventForm.vue`:
- Around line 140-147: The update-event validation logic
(REGEXP_UPDATE_EVENT_NAME.test(...) && propertys.value.some(...)) is duplicated
between the form validator and the changeEventName block; extract that into a
single helper (e.g., isUpdateEventNameValid(eventName) or
validateEventNameForUpdate) that uses REGEXP_UPDATE_EVENT_NAME and
propertys.value to check the stripped name, then replace the duplicated checks
in the form validation and in the changeEventName flow (where isEventNameValid
is computed and used before calling renameBlockEventName/getEditEventName) to
call the new helper, keeping verifyEventName for non-update cases.
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
【问题描述】

onUpdate:xxx的事件名无法保存。【问题分析】
保存的时候,仅校验了普通的事件名,没有兼容
onUpdate:xxx的事件名,导致无法保存。【修复方案】
校验的时候,兼容
onUpdate:xxx的事件名自验证:

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
Refactor
Bug Fixes