From a822c665cda0f5e47709e8aa3e9ba42d890fa110 Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Tue, 3 Dec 2024 21:13:46 +0600 Subject: [PATCH] refactor(frontend): made the states name more meaningful --- .../observability/ObservabilityDashboard.tsx | 30 ++++--- .../observability/drawer/TestsetDrawer.tsx | 80 ++++++++++--------- .../observability/drawer/TraceContent.tsx | 9 +-- 3 files changed, 60 insertions(+), 59 deletions(-) diff --git a/agenta-web/src/components/pages/observability/ObservabilityDashboard.tsx b/agenta-web/src/components/pages/observability/ObservabilityDashboard.tsx index 4e90496723..88500c3bf8 100644 --- a/agenta-web/src/components/pages/observability/ObservabilityDashboard.tsx +++ b/agenta-web/src/components/pages/observability/ObservabilityDashboard.tsx @@ -41,7 +41,7 @@ import {convertToCsv, downloadCsv} from "@/lib/helpers/fileManipulations" import {useUpdateEffect} from "usehooks-ts" import {getStringOrJson} from "@/lib/helpers/utils" import ObservabilityContextProvider, {useObservabilityData} from "@/contexts/observability.context" -import TestsetDrawer from "./drawer/TestsetDrawer" +import TestsetDrawer, {TestsetTraceData} from "./drawer/TestsetDrawer" const useStyles = createUseStyles((theme: JSSTheme) => ({ title: { @@ -80,11 +80,8 @@ const ObservabilityDashboard = () => { const [selectedTraceId, setSelectedTraceId] = useQueryParam("trace", "") const [editColumns, setEditColumns] = useState(["span_type", "key", "usage"]) const [isFilterColsDropdownOpen, setIsFilterColsDropdownOpen] = useState(false) - const [isTestsetDrawerOpen, setIsTestsetDrawerOpen] = useState(false) const [selectedRowKeys, setSelectedRowKeys] = useState([]) - const [testsetDrawerData, setTestsetDrawerData] = useState< - {key: string; data: KeyValuePair; id: number}[] - >([]) + const [testsetDrawerData, setTestsetDrawerData] = useState([]) const [columns, setColumns] = useState>([ { title: "ID", @@ -499,16 +496,18 @@ const ObservabilityDashboard = () => { setSort({type, sorted, customRange}) }, []) - const getMatchingTracesByDataKeys = () => { + const getTestsetTraceData = () => { if (!traces?.length) return [] - const extractData = traces - .filter((trace) => selectedRowKeys.includes(trace.key)) - .flatMap((trace, idx) => ({data: trace.data, key: trace.key, id: idx + 1})) + const extractData = traces.reduce((acc, trace, idx) => { + if (selectedRowKeys.includes(trace.key)) { + acc.push({data: trace.data as KeyValuePair, key: trace.key, id: idx + 1}) + } + return acc + }, []) if (extractData.length > 0) { - setTestsetDrawerData(extractData as any) - setIsTestsetDrawerOpen(true) + setTestsetDrawerData(extractData) } } @@ -562,7 +561,7 @@ const ObservabilityDashboard = () => { Export as CSV