Repository navigation
fix: delete model text - #7946
Conversation
| ) | ||
| .then(() => { | ||
| return props.api.deleteModel(props.model.id).then(() => { | ||
| emit('refresh') |
There was a problem hiding this comment.
Review of the diff
Potential issues
-
Empty string instead of
undefinedprops.model.resource_count ? t(...) : ''
If
MsgConfirm's second parameter is rendered unconditionally (e.g., a subtitle<p>), an empty string can produce an empty node / extra spacing, and truthiness checks insideMsgConfirmwill treat''as "no message" by accident. Preferundefined:props.model.resource_count ? t('model.delete.referenced', { count: props.model.resource_count }) : undefined
-
Type safety of
resource_count
Ensure the model type used byprops.modelactually declaresresource_count(and that the list/detail API always returns it). Otherwise this is a compile error or a silentundefined→ always-empty warning. -
i18n pluralization
countis special in vue-i18n. Make suremodel.delete.referencedhas plural forms (e.g.,... | ...) in all locale files, and that the call uses the plural form, e.g.t('model.delete.referenced', { count }, count)(ortc). If a locale is missing the key, users will see the raw key. -
Missing error handling (pre-existing, but worth fixing)
The chain has no.catch().MsgConfirmrejects on cancel anddeleteModelrejects on API failure → unhandled promise rejection. Also, if the server rejects the deletion because the model is referenced, the user only sees a generic failure. Consider catching and showing a specific error, or disabling/replacing the delete action whenresource_count > 0. -
Stale
resource_count
The count comes from data loaded earlier; it may be out of date by the time the dialog opens. Don't rely on it for correctness — keep the server-side guard as the source of truth. -
Message clarity
model.delete.referencedshould state the consequence explicitly (resources will be detached / deletion will fail), not just "N resources reference this". -
Formatting
The one-line options object is long; run Prettier/ESLint to keep it consistent with repo style. The change also adds a line, so consider whether the diff noise (re-wrapping the whole call) is worth it.
Readability / optimization suggestion
Flatten the nested .then() and use async/await with explicit handling:
async function handleDeleteModel() {
const count = props.model.resource_count
try {
await MsgConfirm(
t('model.delete.confirm', { name: props.model.name }),
count ? t('model.delete.referenced', { count }, count) : undefined,
{
cancelButtonText: t('common.actions.cancel'),
confirmButtonText: t('common.actions.delete'),
},
)
} catch {
return // user cancelled
}
try {
await props.api.deleteModel(props.model.id)
emit('refresh')
} catch (err) {
// surface a proper error (toast) instead of an unhandled rejection
}
}Quick checklist
-
resource_countexists in the type and API payload -
model.delete.referencedadded to every locale, with plural forms - Second arg is
undefined(not'') when count is 0/missing - Cancel and API failure paths handled without unhandled rejections
- Confirm dialog wording explains the actual consequence
【【模型】删除已被引用的模型时,确认弹窗缺少关联资源数量及删除影响提示】
https://www.tapd.cn/tapd_fe/45245355/bug/detail/1145245355001079584