fix: 🐛 preserve global dialog alert buttons#70
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ 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.
Code Review
This pull request refactors the useGlobalDialog composable by introducing helper functions to centralize dialog option normalization and button property processing. The review feedback suggests improving the flexibility of button styling by allowing the round property to be overridden and recommends further refactoring of the store actions to eliminate duplicated logic across the show, alert, confirm, and prompt methods.
| return { | ||
| ...props, | ||
| ...(text ? { text } : {}), | ||
| round: false, | ||
| } |
There was a problem hiding this comment.
The current implementation forces round: false by placing it after the spread operator, which prevents users from overriding this style (e.g., by passing confirmButtonProps: { round: true }). Moving the default property before the spread allows for user customization while still providing the desired default.
| return { | |
| ...props, | |
| ...(text ? { text } : {}), | |
| round: false, | |
| } | |
| return { | |
| round: false, | |
| ...props, | |
| ...(text ? { text } : {}), | |
| } |
| show(option: GlobalDialogOptions | string) { | ||
| this.currentPage = getCurrentPath() | ||
| this.dialogOptions = { | ||
| ...(CommonUtil.isString(option) ? { title: option } : option), | ||
| cancelButtonProps: { | ||
| round: false, | ||
| }, | ||
| confirmButtonProps: { | ||
| round: false, | ||
| }, | ||
| } | ||
| this.dialogOptions = normalizeOption(option) | ||
| }, | ||
| alert(option: GlobalDialogOptions | string) { | ||
| const DialogOptions = CommonUtil.deepMerge({ type: 'alert' }, CommonUtil.isString(option) ? { title: option } : option) as DialogOptions | ||
| DialogOptions.showCancelButton = false | ||
| this.show(DialogOptions) | ||
| this.currentPage = getCurrentPath() | ||
| this.dialogOptions = normalizeOption(option, 'alert') | ||
| }, | ||
| confirm(option: GlobalDialogOptions | string) { | ||
| const DialogOptions = CommonUtil.deepMerge({ type: 'confirm' }, CommonUtil.isString(option) ? { title: option } : option) as DialogOptions | ||
| DialogOptions.showCancelButton = true | ||
| this.show(DialogOptions) | ||
| this.currentPage = getCurrentPath() | ||
| this.dialogOptions = normalizeOption(option, 'confirm') | ||
| }, | ||
| prompt(option: GlobalDialogOptions | string) { | ||
| const DialogOptions = CommonUtil.deepMerge({ type: 'prompt' }, CommonUtil.isString(option) ? { title: option } : option) as DialogOptions | ||
| DialogOptions.showCancelButton = true | ||
| this.show(DialogOptions) | ||
| this.currentPage = getCurrentPath() | ||
| this.dialogOptions = normalizeOption(option, 'prompt') | ||
| }, |
There was a problem hiding this comment.
The logic for setting currentPage and calling normalizeOption is duplicated across all dialog actions. Refactoring the show action to accept an optional type parameter and having alert, confirm, and prompt call this.show would improve maintainability and reduce code duplication.
show(option: GlobalDialogOptions | string, type?: DialogType) {
this.currentPage = getCurrentPath()
this.dialogOptions = normalizeOption(option, type)
},
alert(option: GlobalDialogOptions | string) {
this.show(option, 'alert')
},
confirm(option: GlobalDialogOptions | string) {
this.show(option, 'confirm')
},
prompt(option: GlobalDialogOptions | string) {
this.show(option, 'prompt')
},
🤔 这个 PR 的性质是?(至少选择一个)
🔗 相关 Issue
暂无。
💡 需求背景和解决方案
GlobalDialog 的全局封装会统一调用
dialog.show(option),并在写入状态时补充默认按钮配置。原逻辑会导致alert()设置的showCancelButton: false被默认的cancelButtonProps影响,取消按钮仍然可能显示;同时confirmButtonText/cancelButtonText等快捷配置也没有统一合并到实际按钮配置中。本次修复:
useGlobalDialog内统一规范化show/alert/confirm/prompt的 dialog options。alert默认隐藏取消按钮,confirm/prompt默认显示取消按钮,同时保留调用方显式传入的showCancelButton。confirmButtonText/cancelButtonText合并进对应 button props,并在showCancelButton === false时保留cancelButtonProps: null。GlobalDialog.vue作为展示层,不在组件内分发不同 dialog 类型。☑️ 请求合并前的自查清单