Skip to content

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

Add collapse/expand to all charts (#331)

Marc Klingen5d82d941ec04
diff --git a/src/features/dashboard/components/MetricTable.tsx b/src/features/dashboard/components/MetricTable.tsx
index 62e46c737a..98872f9d39 100644
--- a/src/features/dashboard/components/MetricTable.tsx
+++ b/src/features/dashboard/components/MetricTable.tsx
@@ -5,8 +5,6 @@ import { numberFormatter, usdFormatter } from "@/src/utils/numbers";
import { DashboardTable } from "@/src/features/dashboard/components/cards/DashboardTable";
import { RightAlignedCell } from "@/src/features/dashboard/components/RightAlignedCell";
import { DashboardCard } from "@/src/features/dashboard/components/cards/DashboardCard";
-import { ExpandListButton } from "@/src/features/dashboard/components/cards/ChevronButton";
-import { useState } from "react";
export const MetricTable = ({
className,
@@ -17,7 +15,6 @@ export const MetricTable = ({
projectId: string;
globalFilterState: FilterState;
}) => {
- const [isExpanded, setIsExpanded] = useState(false);
const localFilters = globalFilterState.map((f) => ({
...f,
column: "timestamp",
@@ -60,11 +57,6 @@ export const MetricTable = ({
])
: [];
- const maxNumberOfEntries = 5;
- const expandedMetricsData = isExpanded
- ? metricsData
- : metricsData.slice(0, maxNumberOfEntries);
-
return (
<DashboardCard
className={className}
@@ -77,19 +69,14 @@ export const MetricTable = ({
<RightAlignedCell key={1}>Total tokens</RightAlignedCell>,
<RightAlignedCell key={1}>Total cost</RightAlignedCell>,
]}
- rows={expandedMetricsData}
+ rows={metricsData}
+ collapse={{ collapsed: 5, expanded: 20 }}
>
<TotalMetric
metric={totalTokens ? usdFormatter(totalTokens) : "$0"}
description="Total cost"
/>
</DashboardTable>
- <ExpandListButton
- isExpanded={isExpanded}
- setExpanded={setIsExpanded}
- totalLength={metricsData.length}
- maxLength={maxNumberOfEntries}
- />
</DashboardCard>
);
};
diff --git a/src/features/dashboard/components/ScoresTable.tsx b/src/features/dashboard/components/ScoresTable.tsx
index e4248701ca..ab1d72466e 100644
--- a/src/features/dashboard/components/ScoresTable.tsx
+++ b/src/features/dashboard/components/ScoresTable.tsx
@@ -3,11 +3,9 @@ import { type FilterState } from "@/src/features/filters/types";
import { TotalMetric } from "./TotalMetric";
import { numberFormatter } from "@/src/utils/numbers";
import { DashboardTable } from "@/src/features/dashboard/components/cards/DashboardTable";
-import { ExpandListButton } from "./cards/ChevronButton";
import { DashboardCard } from "@/src/features/dashboard/components/cards/DashboardCard";
import { NoData } from "@/src/features/dashboard/components/NoData";
import { RightAlignedCell } from "./RightAlignedCell";
-import { useState } from "react";
export const ScoresTable = ({
className,
@@ -18,7 +16,6 @@ export const ScoresTable = ({
projectId: string;
globalFilterState: FilterState;
}) => {
- const [isExpanded, setIsExpanded] = useState(false);
const localFilters = globalFilterState.map((f) => ({
...f,
column: "timestamp",
@@ -93,13 +90,9 @@ export const ScoresTable = ({
});
};
- const maxNumberOfEntries = 5;
- const joinedData = joinRequestData();
- const adjustedData = isExpanded
- ? joinedData
- : joinedData.slice(0, maxNumberOfEntries);
+ const data = joinRequestData();
- const totalScores = joinedData.reduce(
+ const totalScores = data.reduce(
(acc, curr) => acc + (curr.countScoreId as number),
0,
);
@@ -123,7 +116,7 @@ export const ScoresTable = ({
<RightAlignedCell key={1}>1</RightAlignedCell>,
]}
rows={
- adjustedData.map((item, i) => [
+ data.map((item, i) => [
item.scoreName,
<RightAlignedCell key={i}>
{numberFormatter(item.countScoreId as number)}
@@ -139,18 +132,13 @@ export const ScoresTable = ({
</RightAlignedCell>,
]) ?? []
}
+ collapse={{ collapsed: 5, expanded: 20 }}
>
<TotalMetric
metric={totalScores ? numberFormatter(totalScores) : "0"}
description="Total scores tracked"
/>
</DashboardTable>
- <ExpandListButton
- isExpanded={isExpanded}
- setExpanded={setIsExpanded}
- totalLength={joinedData.length}
- maxLength={maxNumberOfEntries}
- />
</DashboardCard>
);
};
diff --git a/src/features/dashboard/components/TracesChart.tsx b/src/features/dashboard/components/TracesChart.tsx
index 3f4c2619ef..00784cce1c 100644
--- a/src/features/dashboard/components/TracesChart.tsx
+++ b/src/features/dashboard/components/TracesChart.tsx
@@ -44,11 +44,11 @@ export const TracesBarListChart = ({
})
: [];
- const maxNumberOfEntries = 5;
+ const maxNumberOfEntries = { collapsed: 5, expanded: 20 };
const adjustedData = isExpanded
- ? transformedTraces
- : transformedTraces.slice(0, maxNumberOfEntries);
+ ? transformedTraces.slice(0, maxNumberOfEntries.expanded)
+ : transformedTraces.slice(0, maxNumberOfEntries.collapsed);
return (
<>
@@ -70,7 +70,12 @@ export const TracesBarListChart = ({
isExpanded={isExpanded}
setExpanded={setIsExpanded}
totalLength={transformedTraces.length}
- maxLength={maxNumberOfEntries}
+ maxLength={maxNumberOfEntries.collapsed}
+ expandText={
+ transformedTraces.length > maxNumberOfEntries.expanded
+ ? `Show top ${maxNumberOfEntries.expanded}`
+ : "Show all"
+ }
/>
</BarChartCard>
</>
diff --git a/src/features/dashboard/components/cards/DashboardTable.tsx b/src/features/dashboard/components/cards/DashboardTable.tsx
index 19430e922c..fe08da698b 100644
--- a/src/features/dashboard/components/cards/DashboardTable.tsx
+++ b/src/features/dashboard/components/cards/DashboardTable.tsx
@@ -1,5 +1,6 @@
+import { ExpandListButton } from "@/src/features/dashboard/components/cards/ChevronButton";
import { NoData } from "../NoData";
-import { type ReactNode } from "react";
+import { useState, type ReactNode } from "react";
type TableHeaders = ReactNode[];
type TableRows = ReactNode[][];
@@ -7,13 +8,19 @@ type DashboardTableProps = {
headers: TableHeaders;
rows: TableRows;
children?: ReactNode;
+ collapse?: {
+ collapsed: number;
+ expanded: number;
+ };
};
export const DashboardTable = ({
headers,
rows,
children,
+ collapse,
}: DashboardTableProps) => {
+ const [isExpanded, setExpanded] = useState(false);
return (
<>
{children}
@@ -37,22 +44,44 @@ export const DashboardTable = ({
</thead>
<tbody className="divide-y divide-gray-200 bg-white">
- {rows.map((row) => (
- <tr key={"1"}>
- {row.map((cell, i) => (
- <td
- key={i}
- className="whitespace-nowrap py-2 pl-3 pr-2 text-xs text-gray-500 sm:pl-0"
- >
- {cell}
- </td>
- ))}
- </tr>
- ))}
+ {rows
+ .slice(
+ 0,
+ collapse
+ ? isExpanded
+ ? collapse.expanded
+ : collapse.collapsed
+ : undefined,
+ )
+ .map((row) => (
+ <tr key={"1"}>
+ {row.map((cell, i) => (
+ <td
+ key={i}
+ className="whitespace-nowrap py-2 pl-3 pr-2 text-xs text-gray-500 sm:pl-0"
+ >
+ {cell}
+ </td>
+ ))}
+ </tr>
+ ))}
</tbody>
</table>
</div>
</div>
+ {collapse ? (
+ <ExpandListButton
+ isExpanded={isExpanded}
+ setExpanded={setExpanded}
+ totalLength={rows.length}
+ maxLength={collapse.collapsed}
+ expandText={
+ rows.length > collapse.expanded
+ ? `Show top ${collapse.expanded}`
+ : "Show all"
+ }
+ />
+ ) : null}
</div>
) : (
<NoData noDataText="No data" />