From f4bd572fff6dc50179367509c640541b6ac3e61e Mon Sep 17 00:00:00 2001 From: lcx <1793599591@qq.com> Date: Thu, 29 Jan 2026 17:49:57 +0800 Subject: [PATCH] feat: 1.4 - List supports search --- frontend/public/locales/en/translation.json | 1 + .../public/locales/zh-CN/translation.json | 1 + frontend/src/api/resourceGroup.api.ts | 18 ++++++++++++++-- .../src/components/dashboard/APIKeyModal.tsx | 14 +++++++++++-- .../resource-group/resourceGroup.tsx | 21 ------------------- 5 files changed, 30 insertions(+), 25 deletions(-) diff --git a/frontend/public/locales/en/translation.json b/frontend/public/locales/en/translation.json index 81f4fe1..51e095d 100644 --- a/frontend/public/locales/en/translation.json +++ b/frontend/public/locales/en/translation.json @@ -888,6 +888,7 @@ "Select Date Range": "Select Date Range", "Resource group name \"{{name}}\" is reserved and cannot be used": "Resource group name \"{{name}}\" is reserved and cannot be used", "Resource group name \"{{name}}\" already exists": "Resource group name \"{{name}}\" already exists", + "Auth key name \"{{name}}\" already exists": "Auth key name \"{{name}}\" already exists", "Start date must be before end date": "Start date must be before end date", "Start date cannot be earlier than 30 days ago": "Start date cannot be earlier than 30 days ago" } diff --git a/frontend/public/locales/zh-CN/translation.json b/frontend/public/locales/zh-CN/translation.json index 032e4ac..f7d6ec1 100644 --- a/frontend/public/locales/zh-CN/translation.json +++ b/frontend/public/locales/zh-CN/translation.json @@ -955,6 +955,7 @@ "Select Date Range": "选择日期范围", "Resource group name \"{{name}}\" is reserved and cannot be used": "资源组名称 \"{{name}}\" 是保留名称,不能使用", "Resource group name \"{{name}}\" already exists": "资源组名称 \"{{name}}\" 已存在", + "Auth key name \"{{name}}\" already exists": "认证密钥 \"{{name}}\" 已存在", "Start date must be before end date": "开始日期必须早于结束日期", "Start date cannot be earlier than 30 days ago": "开始日期不能早于30天前" } diff --git a/frontend/src/api/resourceGroup.api.ts b/frontend/src/api/resourceGroup.api.ts index da9556d..bff0027 100644 --- a/frontend/src/api/resourceGroup.api.ts +++ b/frontend/src/api/resourceGroup.api.ts @@ -183,7 +183,14 @@ export const createResourceGroup = async (name: string, isDefault: boolean): Pro body: { name: name, is_default: isDefault } as unknown as BodyInit, }); if (!response.success) { - toast.error(response.error_message || i18n.t("Failed to create resource group")); + const errorMsg = response.error_message + if (errorMsg?.endsWith('already exists')) { + toast.error(i18n.t(errorMsg, { name: name })); + } else if(errorMsg?.endsWith('cannot be used')) { + toast.error(i18n.t(errorMsg, { name: name })); + } else { + toast.error(errorMsg || i18n.t("Failed to create resource group")); + } return { success: false, id: "", @@ -215,7 +222,14 @@ export const updateResourceGroup = async ( body: { name: name, is_default: isDefault } as unknown as BodyInit, }); if (!response.success) { - toast.error(response.error_message || i18n.t("Failed to update resource group")); + const errorMsg = response.error_message + if (errorMsg?.endsWith('already exists')) { + toast.error(i18n.t(errorMsg, { name: name })); + } else if(errorMsg?.endsWith('cannot be used')) { + toast.error(i18n.t(errorMsg, { name: name })); + } else { + toast.error(errorMsg || i18n.t("Failed to update resource group")); + } return false; } return true; diff --git a/frontend/src/components/dashboard/APIKeyModal.tsx b/frontend/src/components/dashboard/APIKeyModal.tsx index d8bda53..6039efa 100644 --- a/frontend/src/components/dashboard/APIKeyModal.tsx +++ b/frontend/src/components/dashboard/APIKeyModal.tsx @@ -64,7 +64,12 @@ export const APIKeyModal = ({ if (!response.success) { console.error("Error creating auth key:", response.error_message); - toast.error(t("Failed to create auth key")); + const errorMsg = response.error_message + if (errorMsg?.endsWith('already exists')) { + toast.error(t(errorMsg, { name: keyName })); + } else { + toast.error(t("Failed to create auth key")); + } return; } @@ -79,7 +84,12 @@ export const APIKeyModal = ({ if (!response.success) { console.error("Error updating auth key:", response.error_message); - toast.error(t("Failed to update auth key")); + const errorMsg = response.error_message + if (errorMsg?.endsWith('already exists')) { + toast.error(t(errorMsg, { name: keyName })); + } else { + toast.error(t("Failed to update auth key")); + } return; } diff --git a/frontend/src/components/resource-group/resourceGroup.tsx b/frontend/src/components/resource-group/resourceGroup.tsx index 009dc8f..3bd4b99 100644 --- a/frontend/src/components/resource-group/resourceGroup.tsx +++ b/frontend/src/components/resource-group/resourceGroup.tsx @@ -103,27 +103,6 @@ const ResourceGroupManagement: React.FC = () => { // 去除首尾空格 const trimmedName = name.trim(); - // 验证保留名称(不区分大小写) - const reservedNames = ['allow all', 'deny all']; - if (reservedNames.some(reserved => reserved.toLowerCase() === trimmedName.toLowerCase())) { - toast.error(t('Resource group name "{{name}}" is reserved and cannot be used', { name: trimmedName })); - return; - } - - // 验证名称是否重复 - const isDuplicate = groups.some(group => { - // 编辑时排除当前组 - if (editingGroup && group.id === editingGroup.id) { - return false; - } - return group.name.toLowerCase() === trimmedName.toLowerCase(); - }); - - if (isDuplicate) { - toast.error(t('Resource group name "{{name}}" already exists', { name: trimmedName })); - return; - } - let success = false; if (editingGroup) {