Skip to content

Commit

Permalink
[OPIK-564] Create new home page
Browse files Browse the repository at this point in the history
- change logic to display link to demo project
  • Loading branch information
andriidudar committed Dec 12, 2024
1 parent a128a1c commit 3370e7a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 23 deletions.
40 changes: 40 additions & 0 deletions apps/opik-frontend/src/api/projects/useDemoProject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { QueryFunctionContext, useQuery } from "@tanstack/react-query";
import api, { PROJECTS_REST_ENDPOINT, QueryConfig } from "@/api/api";
import { Project } from "@/types/projects";
import { DEMO_PROJECT_NAME } from "@/constants/shared";

type UseDemoProjectParams = {
workspaceName: string;
};

const getDemoProject = async (
{ signal }: QueryFunctionContext,
params: UseDemoProjectParams,

Check failure on line 12 in apps/opik-frontend/src/api/projects/useDemoProject.ts

View workflow job for this annotation

GitHub Actions / lint

'params' is defined but never used
) => {
try {
const { data } = await api.post<Project | null>(
`${PROJECTS_REST_ENDPOINT}retrieve`,
{
name: DEMO_PROJECT_NAME,
},
{
signal,
},
);

return data;
} catch (e) {
return null;
}
};

export default function useDemoProject(
params: UseDemoProjectParams,
options?: QueryConfig<Project | null>,
) {
return useQuery({
queryKey: ["project", params],
queryFn: (context) => getDemoProject(context, params),
...options,
});
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from "react";
import { ArrowRight, MessageCircle, MousePointer, X } from "lucide-react";
import useLocalStorageState from "use-local-storage-state";
import { keepPreviousData } from "@tanstack/react-query";

import { Separator } from "@/components/ui/separator";
import { Button } from "@/components/ui/button";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Link } from "@tanstack/react-router";
import useAppStore from "@/store/AppStore";
import { DEMO_PROJECT_NAME } from "@/constants/shared";
import useDemoProject from "@/api/projects/useDemoProject";
import { buildDocsUrl } from "@/lib/utils";

const GetStartedSection = () => {
Expand All @@ -19,7 +20,15 @@ const GetStartedSection = () => {
},
);

if (hide) return null;
const { data: project, isPending } = useDemoProject(
{ workspaceName },
{
enabled: !hide,
placeholderData: keepPreviousData,
},
);

if (hide || isPending) return null;

return (
<div>
Expand All @@ -40,24 +49,25 @@ const GetStartedSection = () => {
</div>
</div>
<div className="flex gap-x-4">
<Alert>
<MousePointer className="size-4" />
<AlertTitle>Explore our demo project</AlertTitle>
<AlertDescription>
Browse our curated examples to draw inspiration for your own LLM
projects.
</AlertDescription>
<Link
to="/$workspaceName/redirect/projects"
params={{ workspaceName }}
search={{ name: DEMO_PROJECT_NAME }}
>
<Button variant="ghost" size="sm" className="-ml-2">
Go to demo project
<ArrowRight className="ml-1 size-4 shrink-0" />
</Button>
</Link>
</Alert>
{project && (
<Alert>
<MousePointer className="size-4" />
<AlertTitle>Explore our demo project</AlertTitle>
<AlertDescription>
Browse our curated examples to draw inspiration for your own LLM
projects.
</AlertDescription>
<Link
to="/$workspaceName/projects/$projectId"
params={{ workspaceName, projectId: project.id }}
>
<Button variant="ghost" size="sm" className="-ml-2">
Go to demo project
<ArrowRight className="ml-1 size-4 shrink-0" />
</Button>
</Link>
</Alert>
)}
<Alert>
<MessageCircle className="size-4" />
<AlertTitle>Log a trace</AlertTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const HomePage = () => {
<div className="pt-6">
<div className="mb-4 flex items-center justify-between">
<h1 className="comet-title-l truncate break-words">
Welcome to {calculateWorkspaceName(workspaceName)}
Welcome to {calculateWorkspaceName(workspaceName, "Opik")}
</h1>
</div>
<GetStartedSection />
Expand Down
6 changes: 4 additions & 2 deletions apps/opik-frontend/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,7 @@ export const toString = (value?: string | number | boolean | null) =>
export const maskAPIKey = (apiKey: string = "") =>
`${apiKey.substring(0, 6)}*****************`;

export const calculateWorkspaceName = (workspaceName: string) =>
workspaceName === DEFAULT_WORKSPACE_NAME ? "Personal" : workspaceName;
export const calculateWorkspaceName = (
workspaceName: string,
defaultName = "Personal",
) => (workspaceName === DEFAULT_WORKSPACE_NAME ? defaultName : workspaceName);

0 comments on commit 3370e7a

Please sign in to comment.