mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-17 04:17:43 +00:00
Usage Entity labels
This commit is contained in:
+1
-1
@@ -265,7 +265,7 @@ describe("EntityUsage", () => {
|
||||
});
|
||||
|
||||
expect(await screen.findByText("Tag Spend Overview")).toBeInTheDocument();
|
||||
expect(await screen.findByText("$-")).toBeInTheDocument();
|
||||
expect(await screen.findByText("$0.00")).toBeInTheDocument();
|
||||
expect(screen.getByText("Total Spend")).toBeInTheDocument();
|
||||
expect(screen.getAllByText("0")[0]).toBeInTheDocument();
|
||||
});
|
||||
|
||||
+16
-2
@@ -305,6 +305,20 @@ const EntityUsage: React.FC<EntityUsageProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
const getEntityLabel = (entity: string, metadata?: Record<string, any>): string => {
|
||||
if (entityList) {
|
||||
const entityItem = entityList.find((item) => item.value === entity);
|
||||
if (entityItem) {
|
||||
return entityItem.label;
|
||||
}
|
||||
}
|
||||
// Fallback to team_alias for backward compatibility
|
||||
if (metadata?.team_alias) {
|
||||
return metadata.team_alias;
|
||||
}
|
||||
return entity;
|
||||
};
|
||||
|
||||
const filterDataByTags = (data: EntityMetricWithMetadata[]) => {
|
||||
if (selectedTags.length === 0) return data;
|
||||
return data.filter((item) => selectedTags.includes(item.metadata.id));
|
||||
@@ -328,7 +342,7 @@ const EntityUsage: React.FC<EntityUsageProps> = ({
|
||||
cache_creation_input_tokens: 0,
|
||||
},
|
||||
metadata: {
|
||||
alias: (data.metadata as any).team_alias || entity,
|
||||
alias: getEntityLabel(entity, data.metadata as any),
|
||||
id: entity,
|
||||
},
|
||||
};
|
||||
@@ -472,7 +486,7 @@ const EntityUsage: React.FC<EntityUsageProps> = ({
|
||||
const metrics = entityData as EntityMetrics;
|
||||
return (
|
||||
<p key={entity} className="text-sm text-gray-600">
|
||||
{metrics.metadata.team_alias || entity}: $
|
||||
{getEntityLabel(entity, metrics.metadata)}: $
|
||||
{formatNumberWithCommas(metrics.metrics.spend, 2)}
|
||||
</p>
|
||||
);
|
||||
|
||||
@@ -72,8 +72,8 @@ describe("dataUtils", () => {
|
||||
});
|
||||
|
||||
it("should handle zero and non-finite values", () => {
|
||||
expect(formatNumberWithCommas(0)).toBe("-");
|
||||
expect(formatNumberWithCommas(0, 2)).toBe("-");
|
||||
expect(formatNumberWithCommas(0)).toBe("0");
|
||||
expect(formatNumberWithCommas(0, 2)).toBe("0.00");
|
||||
expect(formatNumberWithCommas(Infinity)).toBe("-");
|
||||
expect(formatNumberWithCommas(Number.NaN)).toBe("-");
|
||||
});
|
||||
@@ -83,6 +83,18 @@ describe("dataUtils", () => {
|
||||
expect(formatNumberWithCommas(12_345, 2, true)).toBe("12.35K");
|
||||
expect(formatNumberWithCommas(-1_200, 2, true)).toBe("-1.20K");
|
||||
});
|
||||
|
||||
it("should show zero when showZero is true", () => {
|
||||
expect(formatNumberWithCommas(0, 0, false, true)).toBe("0");
|
||||
expect(formatNumberWithCommas(0, 2, false, true)).toBe("0.00");
|
||||
expect(formatNumberWithCommas(0, 0, true, true)).toBe("0");
|
||||
});
|
||||
|
||||
it("should return '-' for zero when showZero is false", () => {
|
||||
expect(formatNumberWithCommas(0, 0, false, false)).toBe("-");
|
||||
expect(formatNumberWithCommas(0, 2, false, false)).toBe("-");
|
||||
expect(formatNumberWithCommas(0, 0, true, false)).toBe("-");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getSpendString", () => {
|
||||
|
||||
@@ -16,8 +16,9 @@ export const formatNumberWithCommas = (
|
||||
value: number | null | undefined,
|
||||
decimals: number = 0,
|
||||
abbreviate: boolean = false,
|
||||
showZero: boolean = true,
|
||||
): string => {
|
||||
if (value === null || value === undefined || !Number.isFinite(value) || value === 0) {
|
||||
if (value === null || value === undefined || !Number.isFinite(value) || (value === 0 && !showZero)) {
|
||||
return "-";
|
||||
}
|
||||
|
||||
@@ -51,7 +52,7 @@ export const getSpendString = (value: number | null | undefined, decimals: numbe
|
||||
return "-";
|
||||
}
|
||||
|
||||
const formatted = formatNumberWithCommas(value, decimals);
|
||||
const formatted = formatNumberWithCommas(value, decimals, false, false);
|
||||
const numericFormatted = Number(formatted.replace(/,/g, ""));
|
||||
|
||||
if (numericFormatted === 0) {
|
||||
|
||||
Reference in New Issue
Block a user