Skip to content

Commit 7e6e031

Browse files
Drewskeptrunedev
authored andcommitted
feat: use env variables and context for sidebar links
1 parent 3b60146 commit 7e6e031

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

frontends/analytics/src/components/Sidebar.tsx

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Show, useContext, For } from "solid-js";
1+
import { Show, useContext, For, createMemo } from "solid-js";
22
import { OrgContext } from "../contexts/OrgContext";
33
import { UserContext } from "../contexts/UserAuthContext";
44
import { DatasetAndUsage } from "shared/types";
@@ -51,34 +51,44 @@ const navbarRoutes = [
5151
];
5252

5353
const dashboardURL = import.meta.env.VITE_DASHBOARD_URL as string;
54-
55-
const domainNavbarRoutes = [
56-
{
57-
href: dashboardURL,
58-
label: "Dashboard",
59-
icon: TbLayoutDashboard,
60-
},
61-
{
62-
href: "https://docs.trieve.ai/api-reference/",
63-
label: "API Docs",
64-
icon: AiOutlineApi,
65-
},
66-
{
67-
href: "https://search.trieve.ai",
68-
label: "Search Playground",
69-
icon: HiOutlineMagnifyingGlass,
70-
},
71-
{
72-
href: "https://chat.trieve.ai",
73-
label: "Chat Playground",
74-
icon: IoChatboxOutline,
75-
},
76-
];
54+
const searchUrl = import.meta.env.VITE_SEARCH_UI_URL as string;
55+
const chatUrl = import.meta.env.VITE_CHAT_UI_URL as string;
7756

7857
export const Sidebar = (props: NavbarProps) => {
7958
const userContext = useContext(UserContext);
8059
const orgContext = useContext(OrgContext);
8160

61+
const domainNavbarRoutes = createMemo(() => {
62+
const domainNavbarRoutes = [
63+
{
64+
href: `${dashboardURL}/dashboard/dataset/${props.selectedDataset
65+
?.dataset.id}/start?org=${orgContext.selectedOrg().id}`,
66+
label: "Dashboard",
67+
icon: TbLayoutDashboard,
68+
},
69+
{
70+
href: "https://docs.trieve.ai/api-reference/",
71+
label: "API Docs",
72+
icon: AiOutlineApi,
73+
},
74+
{
75+
href: `${searchUrl}?organization=${
76+
orgContext.selectedOrg().id
77+
}&dataset=${props.selectedDataset?.dataset.id}`,
78+
label: "Search Playground",
79+
icon: HiOutlineMagnifyingGlass,
80+
},
81+
{
82+
href: `${chatUrl}?organization=${
83+
orgContext.selectedOrg().id
84+
}&dataset=${props.selectedDataset?.dataset.id}`,
85+
label: "Chat Playground",
86+
icon: IoChatboxOutline,
87+
},
88+
];
89+
return domainNavbarRoutes;
90+
});
91+
8292
const pathname = usePathname();
8393
const navigate = useBetterNav();
8494

@@ -172,23 +182,23 @@ export const Sidebar = (props: NavbarProps) => {
172182
<div class="h-4 border-b border-neutral-400/50" />
173183

174184
<div class="flex flex-col gap-2 px-2 pt-4">
175-
<For each={domainNavbarRoutes}>
185+
<For each={domainNavbarRoutes()}>
176186
{(link) => {
177187
return (
178-
<div
188+
<a
179189
role="link"
180190
classList={{
181-
"cursor-pointer flex items-center text-sm gap-2": true,
191+
"cursor-pointer flex items-center text-sm gap-2 hover:text-fuchsia-500":
192+
true,
182193
"text-purple-900 underline": pathname() === link.href,
183194
"text-black": pathname() !== link.href,
184195
}}
185-
onClick={() => {
186-
window.open(link.href);
187-
}}
196+
href={link.href}
197+
target="_blank"
188198
>
189199
{link.icon({ size: "14px" })}
190200
{link.label}
191-
</div>
201+
</a>
192202
);
193203
}}
194204
</For>

0 commit comments

Comments
 (0)