Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix: assign unique keys to sibling items (#860)

jhlopene3079afb2f19
diff --git a/.eslintrc.cjs b/.eslintrc.cjs
index 35c8320c01..b62d2c71ba 100644
--- a/.eslintrc.cjs
+++ b/.eslintrc.cjs
@@ -16,7 +16,7 @@ const config = {
rules: {
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-confusing-void-expression": "off",
- }
+ },
},
],
parser: "@typescript-eslint/parser",
@@ -35,6 +35,12 @@ const config = {
},
],
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
+ "react/jsx-key": [
+ "error",
+ {
+ warnOnDuplicates: true,
+ },
+ ],
},
};
diff --git a/src/features/dashboard/components/MetricTable.tsx b/src/features/dashboard/components/MetricTable.tsx
index 3ff07dd532..5a4875b98f 100644
--- a/src/features/dashboard/components/MetricTable.tsx
+++ b/src/features/dashboard/components/MetricTable.tsx
@@ -1,11 +1,11 @@
-import { api } from "@/src/utils/api";
-import { type FilterState } from "@/src/features/filters/types";
-import { TotalMetric } from "./TotalMetric";
-import { compactNumberFormatter, usdFormatter } from "@/src/utils/numbers";
-import { DashboardTable } from "@/src/features/dashboard/components/cards/DashboardTable";
+import DocPopup from "@/src/components/layouts/doc-popup";
import { RightAlignedCell } from "@/src/features/dashboard/components/RightAlignedCell";
import { DashboardCard } from "@/src/features/dashboard/components/cards/DashboardCard";
-import DocPopup from "@/src/components/layouts/doc-popup";
+import { DashboardTable } from "@/src/features/dashboard/components/cards/DashboardTable";
+import { type FilterState } from "@/src/features/filters/types";
+import { api } from "@/src/utils/api";
+import { compactNumberFormatter, usdFormatter } from "@/src/utils/numbers";
+import { TotalMetric } from "./TotalMetric";
export const MetricTable = ({
className,
@@ -54,12 +54,12 @@ export const MetricTable = ({
.filter((item) => item.model !== null)
.map((item, i) => [
item.model as string,
- <RightAlignedCell key={i}>
+ <RightAlignedCell key={`${i}-tokens`}>
{item.sumTotalTokens
? compactNumberFormatter(item.sumTotalTokens as number)
: "0"}
</RightAlignedCell>,
- <RightAlignedCell key={i}>
+ <RightAlignedCell key={`${i}-cost`}>
{item.totalTokenCost
? usdFormatter(item.totalTokenCost as number)
: "$0"}
@@ -76,8 +76,8 @@ export const MetricTable = ({
<DashboardTable
headers={[
"Model",
- <RightAlignedCell key={0}>Tokens</RightAlignedCell>,
- <RightAlignedCell key={0}>USD</RightAlignedCell>,
+ <RightAlignedCell key="tokens">Tokens</RightAlignedCell>,
+ <RightAlignedCell key="cost">USD</RightAlignedCell>,
]}
rows={metricsData}
collapse={{ collapsed: 5, expanded: 20 }}
diff --git a/src/features/dashboard/components/RightAlignedCell.tsx b/src/features/dashboard/components/RightAlignedCell.tsx
index 70c8076d0d..0088066b8e 100644
--- a/src/features/dashboard/components/RightAlignedCell.tsx
+++ b/src/features/dashboard/components/RightAlignedCell.tsx
@@ -1,18 +1,10 @@
-import { type Key, type ReactNode } from "react";
import { cn } from "@/src/utils/tailwind";
+import { type ReactNode } from "react";
export const RightAlignedCell = ({
children,
className,
- key,
}: {
children: ReactNode;
className?: string;
- key?: Key;
-}) => {
- return (
- <div className={cn("text-right", className)} key={key}>
- {children}
- </div>
- );
-};
+}) => <div className={cn("text-right", className)}>{children}</div>;
diff --git a/src/features/dashboard/components/ScoresTable.tsx b/src/features/dashboard/components/ScoresTable.tsx
index e28360aabf..cb028703d6 100644
--- a/src/features/dashboard/components/ScoresTable.tsx
+++ b/src/features/dashboard/components/ScoresTable.tsx
@@ -1,12 +1,12 @@
-import { api } from "@/src/utils/api";
+import DocPopup from "@/src/components/layouts/doc-popup";
+import { NoData } from "@/src/features/dashboard/components/NoData";
+import { DashboardCard } from "@/src/features/dashboard/components/cards/DashboardCard";
+import { DashboardTable } from "@/src/features/dashboard/components/cards/DashboardTable";
import { type FilterState } from "@/src/features/filters/types";
-import { TotalMetric } from "./TotalMetric";
+import { api } from "@/src/utils/api";
import { compactNumberFormatter } from "@/src/utils/numbers";
-import { DashboardTable } from "@/src/features/dashboard/components/cards/DashboardTable";
-import { DashboardCard } from "@/src/features/dashboard/components/cards/DashboardCard";
-import { NoData } from "@/src/features/dashboard/components/NoData";
import { RightAlignedCell } from "./RightAlignedCell";
-import DocPopup from "@/src/components/layouts/doc-popup";
+import { TotalMetric } from "./TotalMetric";
export const ScoresTable = ({
className,
@@ -128,23 +128,23 @@ export const ScoresTable = ({
<DashboardTable
headers={[
"Name",
- <RightAlignedCell key={0}>#</RightAlignedCell>,
- <RightAlignedCell key={0}>Avg</RightAlignedCell>,
- <RightAlignedCell key={0}>0</RightAlignedCell>,
- <RightAlignedCell key={0}>1</RightAlignedCell>,
+ <RightAlignedCell key="count">#</RightAlignedCell>,
+ <RightAlignedCell key="average">Avg</RightAlignedCell>,
+ <RightAlignedCell key="zero">0</RightAlignedCell>,
+ <RightAlignedCell key="one">1</RightAlignedCell>,
]}
rows={data.map((item, i) => [
item.scoreName,
- <RightAlignedCell key={i}>
+ <RightAlignedCell key={`${i}-count`}>
{compactNumberFormatter(item.countScoreId as number)}
</RightAlignedCell>,
- <RightAlignedCell key={i}>
+ <RightAlignedCell key={`${i}-average`}>
{compactNumberFormatter(item.avgValue)}
</RightAlignedCell>,
- <RightAlignedCell key={i}>
+ <RightAlignedCell key={`${i}-zero`}>
{compactNumberFormatter(item.zeroValueScore as number)}
</RightAlignedCell>,
- <RightAlignedCell key={i}>
+ <RightAlignedCell key={`${i}-one`}>
{compactNumberFormatter(item.oneValueScore)}
</RightAlignedCell>,
])}
diff --git a/src/features/dashboard/components/cards/DashboardTable.tsx b/src/features/dashboard/components/cards/DashboardTable.tsx
index d03ff50a37..369cb8664a 100644
--- a/src/features/dashboard/components/cards/DashboardTable.tsx
+++ b/src/features/dashboard/components/cards/DashboardTable.tsx
@@ -1,6 +1,6 @@
import { ExpandListButton } from "@/src/features/dashboard/components/cards/ChevronButton";
-import { NoData } from "../NoData";
import { useState, type ReactNode } from "react";
+import { NoData } from "../NoData";
type TableHeaders = ReactNode[];
type TableRows = ReactNode[][];
@@ -57,11 +57,11 @@ export const DashboardTable = ({
: collapse.collapsed
: undefined,
)
- .map((row) => (
- <tr key={"1"}>
- {row.map((cell, i) => (
+ .map((row, i) => (
+ <tr key={i}>
+ {row.map((cell, j) => (
<td
- key={i}
+ key={j}
className="whitespace-nowrap py-2 pl-3 pr-2 text-xs text-gray-500 sm:pl-0"
>
{cell}