From 92c65af944b2c9f0c4fc1754a1ef8aa6cb71bd77 Mon Sep 17 00:00:00 2001 From: "use-tusk[bot]" <144006087+use-tusk[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:54:29 -0700 Subject: [PATCH] [ENG-1137] Fix cache tabs to maintain their selected state visually (#2712) * fix(cache): ensure cache tabs hold selected state * fix(11149993052): auto linting --------- Co-authored-by: use-tusk[bot] <144006087+use-tusk[bot]@users.noreply.github.com> Co-authored-by: Justin Torre --- web/components/templates/cache/cachePage.tsx | 208 +++++++++---------- web/pages/cache.tsx | 4 +- 2 files changed, 103 insertions(+), 109 deletions(-) diff --git a/web/components/templates/cache/cachePage.tsx b/web/components/templates/cache/cachePage.tsx index 9508a5cc39..9cd78e327f 100644 --- a/web/components/templates/cache/cachePage.tsx +++ b/web/components/templates/cache/cachePage.tsx @@ -6,16 +6,7 @@ import { TableCellsIcon, } from "@heroicons/react/24/outline"; import { ElementType, useMemo, useState } from "react"; -import { - BarChart, - Tab, - TabGroup, - TabList, - TabPanel, - TabPanels, - Divider, - Badge, -} from "@tremor/react"; +import { BarChart, Divider, Badge } from "@tremor/react"; import ThemedDrawer from "../../shared/themed/themedDrawer"; import ThemedListItem from "../../shared/themed/themedListItem"; import RequestsPageV2 from "../requestsV2/requestsPageV2"; @@ -32,6 +23,7 @@ import { formatNumber } from "../users/initialColumns"; import { useOrg } from "@/components/layout/organizationContext"; import { DiffHighlight } from "../welcome/diffHighlight"; import { FeatureUpgradeCard } from "@/components/shared/helicone/FeatureUpgradeCard"; +import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs"; import { IslandContainer } from "@/components/ui/islandContainer"; interface CachePageProps { @@ -42,7 +34,7 @@ interface CachePageProps { sortDirection: SortDirection | null; isCustomProperty: boolean; }; - defaultIndex?: number; + defaultIndex: string; } const tabs: { @@ -63,7 +55,7 @@ const tabs: { ]; const CachePage = (props: CachePageProps) => { - const { currentPage, pageSize, sort, defaultIndex = 0 } = props; + const { currentPage, pageSize, sort, defaultIndex = "0" } = props; const [timeFilter, _] = useState({ start: new Date(new Date().getTime() - 1000 * 60 * 60 * 24 * 30), end: new Date(), @@ -243,121 +235,123 @@ openai.chat.completions.create( ) : (
- - + + {tabs.map((tab) => ( - { router.push( { - query: { tab: tab.id }, + query: { ...router.query, tab: tab.id }, }, undefined, { shallow: true } ); }} > + {tab.title} - + ))} - - - -
-
-
    - {metrics.map((metric, i) => ( -
  • - -
    -
    - {metric.label} -
    - {metric.isLoading ? ( -
    - ) : ( -
    - {metric.value} -
    - )} -
    -
  • - ))} -
-
-

- Caches last 30 days -

-
- {isAnyLoading ? ( -
-
-
- ) : ( -
- -
- )} -
-
-
-
+ + +
+
+
    + {metrics.map((metric, i) => ( +
  • + +
    +
    + {metric.label} +
    + {metric.isLoading ? ( +
    + ) : ( +
    + {metric.value} +
    + )} +
    +
  • + ))} +
+

- Top Requests + Caches last 30 days

-
    - {chMetrics.topRequests.data?.data?.map( - (request: any, i: any) => ( - { - setSelectedRequest(request); - setOpen(true); - }} - title={request.prompt} - subtitle={`Created: ${new Date( - request.first_used - ).toLocaleString()}`} - icon={CircleStackIcon} - value={request.count} - pill={} - secondarySubtitle={`Recent: ${new Date( - request.last_used - ).toLocaleString()}`} +
    + {isAnyLoading ? ( +
    +
    +
    + ) : ( +
    + - ) +
    )} -
+
- - -
- +
+

+ Top Requests +

+
    + {chMetrics.topRequests.data?.data?.map( + (request: any, i: any) => ( + { + setSelectedRequest(request); + setOpen(true); + }} + title={request.prompt} + subtitle={`Created: ${new Date( + request.first_used + ).toLocaleString()}`} + icon={CircleStackIcon} + value={request.count} + pill={} + secondarySubtitle={`Recent: ${new Date( + request.last_used + ).toLocaleString()}`} + /> + ) + )} +
- - - +
+
+ +
+ +
+
+
)} diff --git a/web/pages/cache.tsx b/web/pages/cache.tsx index fc5dc00890..fce7ba0e83 100644 --- a/web/pages/cache.tsx +++ b/web/pages/cache.tsx @@ -15,7 +15,7 @@ interface CacheProps { sortDirection: SortDirection | null; isCustomProperty: boolean; }; - defaultIndex: number; + defaultIndex: string; } const Cache = (props: CacheProps) => { @@ -55,7 +55,7 @@ export const getServerSideProps = withAuthSSR(async (options) => { sortDirection: sortDirection ? (sortDirection as SortDirection) : null, isCustomProperty: isCustomProperty === "true", }, - defaultIndex: tab ? parseInt(tab as string) : 0, + defaultIndex: tab ? tab.toString() : "0", }, }; });