Skip to content

fix: delete model text - #7946

Merged
fit2cloudwxx merged 1 commit into
v3from
pr@v3@fix_deleteModelText
Nov 16, 2026
Merged

fit2cloudwxx merged 1 commit into
v3from
pr@v3@fix_deleteModelText

Conversation

@shaohuzhang1

@shaohuzhang1 shaohuzhang1 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

【【模型】删除已被引用的模型时,确认弹窗缺少关联资源数量及删除影响提示】
https://www.tapd.cn/tapd_fe/45245355/bug/detail/1145245355001079584

)
.then(() => {
return props.api.deleteModel(props.model.id).then(() => {
emit('refresh')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of the diff

Potential issues

  1. Empty string instead of undefined

    props.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 inside MsgConfirm will treat '' as "no message" by accident. Prefer undefined:

    props.model.resource_count
      ? t('model.delete.referenced', { count: props.model.resource_count })
      : undefined
  2. Type safety of resource_count
    Ensure the model type used by props.model actually declares resource_count (and that the list/detail API always returns it). Otherwise this is a compile error or a silent undefined → always-empty warning.

  3. i18n pluralization
    count is special in vue-i18n. Make sure model.delete.referenced has plural forms (e.g., ... | ...) in all locale files, and that the call uses the plural form, e.g. t('model.delete.referenced', { count }, count) (or tc). If a locale is missing the key, users will see the raw key.

  4. Missing error handling (pre-existing, but worth fixing)
    The chain has no .catch(). MsgConfirm rejects on cancel and deleteModel rejects 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 when resource_count > 0.

  5. 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.

  6. Message clarity
    model.delete.referenced should state the consequence explicitly (resources will be detached / deletion will fail), not just "N resources reference this".

  7. 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_count exists in the type and API payload
  • model.delete.referenced added 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

@fit2cloudwxx
fit2cloudwxx merged commit 226e69e into v3 Nov 16, 2026
3 of 4 checks passed
@fit2cloudwxx
fit2cloudwxx deleted the pr@v3@fix_deleteModelText branch November 16, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants