Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ui/src/locales/en-US/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"title": "Model parameters"
},
"delete": {
"confirm": "Delete model “{name}”?"
"confirm": "Delete model “{name}”?",
"referenced": "This model is associated with {count} resources, which cannot be used after it is deleted. Proceed with caution."
},
"messages": {
"fetched": "Fetched successfully",
Expand Down
1 change: 0 additions & 1 deletion ui/src/locales/en-US/system/resource-management.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"workspace": "Workspace"
},
"delete": {
"modelReferenced": "This model is referenced by {count} resources. Deleting it will prevent those resources from working properly. Proceed with caution.",
"toolReferenced": "This tool is referenced by {count} resources. Deleting it will prevent those resources from working properly. Proceed with caution."
}
}
3 changes: 2 additions & 1 deletion ui/src/locales/zh-CN/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"title": "模型参数"
},
"delete": {
"confirm": "确认删除模型:{name}?"
"confirm": "是否删除模型:{name}?",
"referenced": "此模型关联 {count} 个资源,删除后无法使用,请谨慎操作。"
},
"messages": {
"fetched": "获取成功",
Expand Down
1 change: 0 additions & 1 deletion ui/src/locales/zh-CN/system/resource-management.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"workspace": "工作空间"
},
"delete": {
"modelReferenced": "该模型已被 {count} 个资源引用,删除后相关资源将无法正常运行,请谨慎操作。",
"toolReferenced": "该工具已被 {count} 个资源引用,删除后相关资源将无法正常运行,请谨慎操作。"
}
}
3 changes: 2 additions & 1 deletion ui/src/locales/zh-Hant/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"title": "模型參數"
},
"delete": {
"confirm": "確認刪除模型:{name}?"
"confirm": "是否刪除模型:{name}?",
"referenced": "此模型關聯 {count} 個資源,刪除後無法使用,請謹慎操作。"
},
"messages": {
"fetched": "取得成功",
Expand Down
1 change: 0 additions & 1 deletion ui/src/locales/zh-Hant/system/resource-management.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"workspace": "工作空間"
},
"delete": {
"modelReferenced": "該模型已被 {count} 個資源引用,刪除後相關資源將無法正常運作,請謹慎操作。",
"toolReferenced": "該工具已被 {count} 個資源引用,刪除後相關資源將無法正常運作,請謹慎操作。"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ const props = defineProps<{ api: typeof ModelApi | typeof SystemSharedModelApi;
const emit = defineEmits<{ refresh: [] }>()

function handleDeleteModel() {
return MsgConfirm(t('model.delete.confirm', { name: props.model.name }), undefined, {
cancelButtonText: t('common.actions.cancel'),
confirmButtonText: t('common.actions.delete'),
})
return MsgConfirm(
t('model.delete.confirm', { name: props.model.name }),
props.model.resource_count ? t('model.delete.referenced', { count: props.model.resource_count }) : '',
{ cancelButtonText: t('common.actions.cancel'), confirmButtonText: t('common.actions.delete') },
)
.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

Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/system/resource-management/model/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function getProvider(model: ModelItem): ModelProviderItem {
function handleDeleteModel(model: ModelItem) {
return MsgConfirm(
t('model.delete.confirm', { name: model.name }),
model.resource_count ? t('system.resourceManagement.delete.modelReferenced', { count: model.resource_count }) : '',
model.resource_count ? t('model.delete.referenced', { count: model.resource_count }) : '',
{ cancelButtonText: t('common.actions.cancel'), confirmButtonText: t('common.actions.delete') },
)
.then(() => {
Expand Down
Loading