From 7e6e0317e15a29adf5531e54c5933cb3c05cc90d Mon Sep 17 00:00:00 2001 From: Drew Date: Tue, 3 Sep 2024 10:49:00 -0500 Subject: [PATCH] feat: use env variables and context for sidebar links --- .../analytics/src/components/Sidebar.tsx | 72 +++++++++++-------- 1 file changed, 41 insertions(+), 31 deletions(-) diff --git a/frontends/analytics/src/components/Sidebar.tsx b/frontends/analytics/src/components/Sidebar.tsx index 72a05ac5e0..a3890cf884 100644 --- a/frontends/analytics/src/components/Sidebar.tsx +++ b/frontends/analytics/src/components/Sidebar.tsx @@ -1,4 +1,4 @@ -import { Show, useContext, For } from "solid-js"; +import { Show, useContext, For, createMemo } from "solid-js"; import { OrgContext } from "../contexts/OrgContext"; import { UserContext } from "../contexts/UserAuthContext"; import { DatasetAndUsage } from "shared/types"; @@ -51,34 +51,44 @@ const navbarRoutes = [ ]; const dashboardURL = import.meta.env.VITE_DASHBOARD_URL as string; - -const domainNavbarRoutes = [ - { - href: dashboardURL, - label: "Dashboard", - icon: TbLayoutDashboard, - }, - { - href: "https://docs.trieve.ai/api-reference/", - label: "API Docs", - icon: AiOutlineApi, - }, - { - href: "https://search.trieve.ai", - label: "Search Playground", - icon: HiOutlineMagnifyingGlass, - }, - { - href: "https://chat.trieve.ai", - label: "Chat Playground", - icon: IoChatboxOutline, - }, -]; +const searchUrl = import.meta.env.VITE_SEARCH_UI_URL as string; +const chatUrl = import.meta.env.VITE_CHAT_UI_URL as string; export const Sidebar = (props: NavbarProps) => { const userContext = useContext(UserContext); const orgContext = useContext(OrgContext); + const domainNavbarRoutes = createMemo(() => { + const domainNavbarRoutes = [ + { + href: `${dashboardURL}/dashboard/dataset/${props.selectedDataset + ?.dataset.id}/start?org=${orgContext.selectedOrg().id}`, + label: "Dashboard", + icon: TbLayoutDashboard, + }, + { + href: "https://docs.trieve.ai/api-reference/", + label: "API Docs", + icon: AiOutlineApi, + }, + { + href: `${searchUrl}?organization=${ + orgContext.selectedOrg().id + }&dataset=${props.selectedDataset?.dataset.id}`, + label: "Search Playground", + icon: HiOutlineMagnifyingGlass, + }, + { + href: `${chatUrl}?organization=${ + orgContext.selectedOrg().id + }&dataset=${props.selectedDataset?.dataset.id}`, + label: "Chat Playground", + icon: IoChatboxOutline, + }, + ]; + return domainNavbarRoutes; + }); + const pathname = usePathname(); const navigate = useBetterNav(); @@ -172,23 +182,23 @@ export const Sidebar = (props: NavbarProps) => {
- + {(link) => { return ( -
{ - window.open(link.href); - }} + href={link.href} + target="_blank" > {link.icon({ size: "14px" })} {link.label} -
+ ); }}