fix(console): use toast for pip-install error display#8462
Conversation
The pip-install dialog displayed error messages as unstyled inline <small> text with no color differentiation from success messages. Replaced with useToast() to show errors as red snackbar, consistent with the rest of the dashboard.
There was a problem hiding this comment.
Code Review
This pull request refactors the pip installation feedback mechanism in ConsolePage.vue by replacing the inline status text with toast notifications using useToast. A critical issue was identified in the feedback where the code checks for res.data.status === 'ok', but the backend actually returns 'success' on successful operations. This mismatch would cause successful installations to incorrectly trigger an error toast.
| this.status = res.data.message; | ||
| setTimeout(() => { | ||
| this.status = ''; | ||
| if (res.data.status === 'ok') { |
There was a problem hiding this comment.
The backend Response class (as seen in astrbot/dashboard/routes/update.py line 165) uses "success" as the status string for successful responses, rather than "ok". Checking for res.data.status === 'ok' will evaluate to false even on successful installations, causing the error toast to be shown instead.\n\nPlease update the check to use 'success' to match the backend response status.
if (res.data.status === 'success') {
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
useToastimport is added in the<script setup>block but used inside the optionsmethodsblock, which has its own scope; you should import and initializeuseToastin the same script block wherepipInstalllives (or pass a toast handler in) to avoid a runtime/build-time reference error. - The fallback toast messages (e.g.
'安装成功。','安装失败。','请求失败。') are hardcoded strings; consider sourcing these from the existingi18n(tm) namespace for consistency with the rest of the console.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `useToast` import is added in the `<script setup>` block but used inside the options `methods` block, which has its own scope; you should import and initialize `useToast` in the same script block where `pipInstall` lives (or pass a toast handler in) to avoid a runtime/build-time reference error.
- The fallback toast messages (e.g. `'安装成功。'`, `'安装失败。'`, `'请求失败。'`) are hardcoded strings; consider sourcing these from the existing `i18n` (`tm`) namespace for consistency with the rest of the console.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Fixes the issue where the pip-install dialog in ConsolePage displayed error messages as unstyled inline text instead of using the standard toast notification pattern.
Closes #8468
Modifications / 改动点
dashboard/src/views/ConsolePage.vue:useToastfrom@/utils/toast<small>{{ status }}</small>element and unusedstatusdata fieldpipInstall()to usetoast.success()/toast.error()insteadres.data.statuscheck to distinguish ok/error responsesThis is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Before: Error message "缺少参数 package 或不合法。" displayed as unstyled small text inside the dialog with no color differentiation.
After:
requests) → green snackbar: "安装成功。", dialog auto-closesChecklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。