From 02fcb6a61e87c100fa3ae6b0855c648e058b5c3f Mon Sep 17 00:00:00 2001 From: heheer Date: Fri, 24 Jan 2025 19:09:08 +0800 Subject: [PATCH] export usage csv i18n (#3660) * export usage csv i18n * fix build --- packages/web/i18n/en/account_usage.json | 1 + packages/web/i18n/zh-CN/account_usage.json | 1 + packages/web/i18n/zh-Hant/account_usage.json | 1 + .../account/usage/UsageTable.tsx | 57 +++++++++++++------ 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/packages/web/i18n/en/account_usage.json b/packages/web/i18n/en/account_usage.json index 50d98de8ba36..bfb9cd72e025 100644 --- a/packages/web/i18n/en/account_usage.json +++ b/packages/web/i18n/en/account_usage.json @@ -13,6 +13,7 @@ "every_month": "Moon", "export_confirm": "Export confirmation", "export_confirm_tip": "There are currently {{total}} usage records in total. Are you sure to export?", + "export_title": "Time,Members,Type,Project name,AI points", "feishu": "Feishu", "generation_time": "Generation time", "input_token_length": "input tokens", diff --git a/packages/web/i18n/zh-CN/account_usage.json b/packages/web/i18n/zh-CN/account_usage.json index 8c8b5e2e803a..3b7bb0792516 100644 --- a/packages/web/i18n/zh-CN/account_usage.json +++ b/packages/web/i18n/zh-CN/account_usage.json @@ -15,6 +15,7 @@ "export_confirm": "导出确认", "export_confirm_tip": "当前共 {{total}} 条使用记录,确认导出?", "export_success": "导出成功", + "export_title": "时间,成员,类型,项目名,AI 积分消耗", "feishu": "飞书", "generation_time": "生成时间", "input_token_length": "输入 tokens", diff --git a/packages/web/i18n/zh-Hant/account_usage.json b/packages/web/i18n/zh-Hant/account_usage.json index 040d3cb50028..dd6699c6ddef 100644 --- a/packages/web/i18n/zh-Hant/account_usage.json +++ b/packages/web/i18n/zh-Hant/account_usage.json @@ -13,6 +13,7 @@ "every_month": "月", "export_confirm": "導出確認", "export_confirm_tip": "當前共 {{total}} 筆使用記錄,確認導出?", + "export_title": "時間,成員,類型,項目名,AI 積分消耗", "feishu": "飛書", "generation_time": "生成時間", "input_token_length": "輸入 tokens", diff --git a/projects/app/src/pageComponents/account/usage/UsageTable.tsx b/projects/app/src/pageComponents/account/usage/UsageTable.tsx index 00c9a2437f6d..ed550d5d1b48 100644 --- a/projects/app/src/pageComponents/account/usage/UsageTable.tsx +++ b/projects/app/src/pageComponents/account/usage/UsageTable.tsx @@ -43,24 +43,47 @@ const UsageTableList = ({ const { dateRange, selectTmbIds, isSelectAllTmb, usageSources, isSelectAllSource, projectName } = filterParams; - const requestParans = useMemo( - () => ({ + const requestParams = useMemo(() => { + const appNameMap = { + ['core.app.Question Guide']: t('common:core.app.Question Guide'), + ['common:support.wallet.usage.Audio Speech']: t('common:support.wallet.usage.Audio Speech'), + ['support.wallet.usage.Whisper']: t('common:support.wallet.usage.Whisper'), + ['support.wallet.moduleName.index']: t('common:support.wallet.moduleName.index'), + ['support.wallet.moduleName.qa']: t('common:support.wallet.moduleName.qa'), + ['core.dataset.training.Auto mode']: t('common:core.dataset.training.Auto mode'), + ['common:core.module.template.ai_chat']: t('common:core.module.template.ai_chat') + }; + + const sourcesMap = Object.fromEntries( + Object.entries(UsageSourceMap).map(([key, config]) => [ + key, + { + label: t(config.label as any) + } + ]) + ); + const title = t('account_usage:export_title'); + + return { dateStart: dateRange.from || new Date(), dateEnd: addDays(dateRange.to || new Date(), 1), sources: isSelectAllSource ? undefined : usageSources, + sourcesMap, + appNameMap, + title, teamMemberIds: isSelectAllTmb ? undefined : selectTmbIds, projectName - }), - [ - dateRange.from, - dateRange.to, - isSelectAllSource, - isSelectAllTmb, - projectName, - selectTmbIds, - usageSources - ] - ); + }; + }, [ + dateRange.from, + dateRange.to, + isSelectAllSource, + isSelectAllTmb, + projectName, + selectTmbIds, + usageSources, + t + ]); const { data: usages, @@ -69,8 +92,8 @@ const UsageTableList = ({ total } = usePagination(getUserUsages, { pageSize: 20, - params: requestParans, - refreshDeps: [requestParans] + params: requestParams, + refreshDeps: [requestParams] }); const [usageDetail, setUsageDetail] = useState(); @@ -80,11 +103,11 @@ const UsageTableList = ({ await downloadFetch({ url: `/api/proApi/support/wallet/usage/exportUsage`, filename: `usage.csv`, - body: requestParans + body: requestParams }); }, { - refreshDeps: [requestParans] + refreshDeps: [requestParams] } );