refactor(usage): address PR review — null-safe mark, hook renames, lazy intl
This commit is contained in:
@@ -287,9 +287,15 @@ function flattenItem(
|
|||||||
// The chart series legend can't render a tag, so it carries the deleted
|
// 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
|
// marker as text ("<name> [Deleted.<id>]"); the tables render a DeletedTag off
|
||||||
// ``flat.deleted`` + the id and so keep the clean name.
|
// ``flat.deleted`` + the id and so keep the clean name.
|
||||||
const deletedWord = getIntl().formatMessage({ id: 'usage.table.deleted' });
|
|
||||||
const key =
|
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
|
// 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).
|
// sub-group value (the switch below targets single-dimension table rows).
|
||||||
if (rawKey != null) flat.group = key;
|
if (rawKey != null) flat.group = key;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useMemo } from 'react';
|
|||||||
import DeletedTag from '../components/deleted-tag';
|
import DeletedTag from '../components/deleted-tag';
|
||||||
import { BreakdownItem as ListItem } from '../config/types';
|
import { BreakdownItem as ListItem } from '../config/types';
|
||||||
|
|
||||||
const useModelsColumns = () => {
|
const useAPIKeysColumns = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
@@ -113,4 +113,4 @@ const useModelsColumns = () => {
|
|||||||
}, [intl]);
|
}, [intl]);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useModelsColumns;
|
export default useAPIKeysColumns;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ interface ColumnsHookProps {
|
|||||||
sortOrder: string[];
|
sortOrder: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const useModelsColumns = () => {
|
const useUsersColumns = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
@@ -123,4 +123,4 @@ const useModelsColumns = () => {
|
|||||||
}, [intl]);
|
}, [intl]);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useModelsColumns;
|
export default useUsersColumns;
|
||||||
|
|||||||
@@ -9,9 +9,13 @@
|
|||||||
* strings.
|
* strings.
|
||||||
*/
|
*/
|
||||||
export const withDeletedMark = (
|
export const withDeletedMark = (
|
||||||
label: string,
|
label: string | undefined | null,
|
||||||
deleted: boolean | undefined | null,
|
deleted: boolean | undefined | null,
|
||||||
deletedWord: string,
|
deletedWord: string,
|
||||||
id?: string | number | null
|
id?: string | number | null
|
||||||
): string =>
|
): string => {
|
||||||
deleted ? `${label} [${deletedWord}${id != null ? `.#${id}` : ''}]` : label;
|
const safeLabel = label || '';
|
||||||
|
if (!deleted) return safeLabel;
|
||||||
|
const suffix = `[${deletedWord}${id != null ? `.#${id}` : ''}]`;
|
||||||
|
return safeLabel ? `${safeLabel} ${suffix}` : suffix;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user