refactor(usage): address PR review — null-safe mark, hook renames, lazy intl

This commit is contained in:
jialin
2026-07-09 15:17:53 +08:00
committed by jialin
parent d91fbec9d7
commit 794ac724ca
4 changed files with 19 additions and 9 deletions
+8 -2
View File
@@ -287,9 +287,15 @@ function flattenItem(
// The chart series legend can't render a tag, so it carries the deleted
// marker as text ("<name> [Deleted.<id>]"); the tables render a DeletedTag off
// ``flat.deleted`` + the id and so keep the clean name.
const deletedWord = getIntl().formatMessage({ id: 'usage.table.deleted' });
const key =
rawKey != null ? withDeletedMark(rawKey, deleted, deletedWord, id) : rawKey;
rawKey != null
? withDeletedMark(
rawKey,
deleted,
deleted ? getIntl().formatMessage({ id: 'usage.table.deleted' }) : '',
id
)
: rawKey;
// Generic group label — for a compound (date + dim) trend row the key is the
// sub-group value (the switch below targets single-dimension table rows).
if (rawKey != null) flat.group = key;
@@ -5,7 +5,7 @@ import { useMemo } from 'react';
import DeletedTag from '../components/deleted-tag';
import { BreakdownItem as ListItem } from '../config/types';
const useModelsColumns = () => {
const useAPIKeysColumns = () => {
const intl = useIntl();
return useMemo(() => {
@@ -113,4 +113,4 @@ const useModelsColumns = () => {
}, [intl]);
};
export default useModelsColumns;
export default useAPIKeysColumns;
+2 -2
View File
@@ -9,7 +9,7 @@ interface ColumnsHookProps {
sortOrder: string[];
}
const useModelsColumns = () => {
const useUsersColumns = () => {
const intl = useIntl();
return useMemo(() => {
@@ -123,4 +123,4 @@ const useModelsColumns = () => {
}, [intl]);
};
export default useModelsColumns;
export default useUsersColumns;
+7 -3
View File
@@ -9,9 +9,13 @@
* strings.
*/
export const withDeletedMark = (
label: string,
label: string | undefined | null,
deleted: boolean | undefined | null,
deletedWord: string,
id?: string | number | null
): string =>
deleted ? `${label} [${deletedWord}${id != null ? `.#${id}` : ''}]` : label;
): string => {
const safeLabel = label || '';
if (!deleted) return safeLabel;
const suffix = `[${deletedWord}${id != null ? `.#${id}` : ''}]`;
return safeLabel ? `${safeLabel} ${suffix}` : suffix;
};