From 7d8755f0e4761d358a2c221d5960abf6790a3c0b Mon Sep 17 00:00:00 2001 From: dylan Date: Fri, 31 May 2024 10:59:19 -0400 Subject: [PATCH] updating queryKeys --- .../[project_id]/evaluate/page-client.tsx | 4 +- .../[project_id]/prompts/page-client.tsx | 4 +- app/(protected)/projects/page-client.tsx | 2 +- components/evaluate/evaluation-table.tsx | 2 +- components/shared/add-to-dataset.tsx | 4 +- components/shared/header.tsx | 16 +++---- components/shared/project-switcher.tsx | 43 ++++++++++++++----- 7 files changed, 49 insertions(+), 26 deletions(-) diff --git a/app/(protected)/project/[project_id]/evaluate/page-client.tsx b/app/(protected)/project/[project_id]/evaluate/page-client.tsx index 97bfb8ca..1391c283 100644 --- a/app/(protected)/project/[project_id]/evaluate/page-client.tsx +++ b/app/(protected)/project/[project_id]/evaluate/page-client.tsx @@ -36,7 +36,7 @@ export default function PageClient({ email }: { email: string }) { const [totalPages, setTotalPages] = useState(1); const { data: testAverages, isLoading: testAveragesLoading } = useQuery({ - queryKey: [`fetch-test-averages-${projectId}-query`], + queryKey: ["fetch-test-averages-query", projectId], queryFn: async () => { const response = await fetch(`/api/metrics/tests?projectId=${projectId}`); if (!response.ok) { @@ -58,7 +58,7 @@ export default function PageClient({ email }: { email: string }) { isLoading: testsLoading, error: testsError, } = useQuery({ - queryKey: [`fetch-tests-${projectId}-query`], + queryKey: ["fetch-tests-query", projectId], queryFn: async () => { const response = await fetch(`/api/test?projectId=${projectId}`); if (!response.ok) { diff --git a/app/(protected)/project/[project_id]/prompts/page-client.tsx b/app/(protected)/project/[project_id]/prompts/page-client.tsx index 8b4eafcf..b5cc02b8 100644 --- a/app/(protected)/project/[project_id]/prompts/page-client.tsx +++ b/app/(protected)/project/[project_id]/prompts/page-client.tsx @@ -37,7 +37,7 @@ export default function PageClient({ email }: { email: string }) { }; const fetchPrompts = useQuery({ - queryKey: [`fetch-prompts-${projectId}-query`], + queryKey: ["fetch-prompts-query", projectId], queryFn: async () => { const response = await fetch( `/api/span-prompt?projectId=${projectId}&page=${page}&pageSize=${PAGE_SIZE}` @@ -188,7 +188,7 @@ const PromptRow = ({ const promptContent = extractSystemPromptFromLlmInputs(prompts); const fetchEvaluation = useQuery({ - queryKey: [`fetch-evaluation-query-${prompt.span_id}`], + queryKey: ["fetch-evaluation-query", prompt.span_id], queryFn: async () => { const response = await fetch(`/api/evaluation?prompt=${promptContent}`); diff --git a/app/(protected)/projects/page-client.tsx b/app/(protected)/projects/page-client.tsx index a3c2c77b..5c2afd8d 100644 --- a/app/(protected)/projects/page-client.tsx +++ b/app/(protected)/projects/page-client.tsx @@ -143,7 +143,7 @@ function ProjectCard({ teamId: string; }) { const { data: projectStats, isLoading: projectStatsLoading } = useQuery({ - queryKey: [`fetch-project-stats-${project.id}`], + queryKey: ["fetch-project-stats", project.id], queryFn: async () => { const response = await fetch( `/api/stats/project?projectId=${project.id}` diff --git a/components/evaluate/evaluation-table.tsx b/components/evaluate/evaluation-table.tsx index da201b24..9a1fa740 100644 --- a/components/evaluate/evaluation-table.tsx +++ b/components/evaluate/evaluation-table.tsx @@ -49,7 +49,7 @@ export default function EvaluationTable({ }; const fetchLlmPromptSpans = useQuery({ - queryKey: [`fetch-llm-prompt-spans-${test.id}-query`], + queryKey: ["fetch-llm-prompt-spans-query", test.id], queryFn: async () => { const filters = [ { diff --git a/components/shared/add-to-dataset.tsx b/components/shared/add-to-dataset.tsx index 7dd181c6..910276e8 100644 --- a/components/shared/add-to-dataset.tsx +++ b/components/shared/add-to-dataset.tsx @@ -100,7 +100,7 @@ export function AddtoDataset({ }); selectedData!.forEach((data) => { queryClient.invalidateQueries({ - queryKey: [`fetch-data-query-${data.spanId}`], + queryKey: ["fetch-data-query", data.spanId], }); }); setBusy(false); @@ -130,7 +130,7 @@ export default function DatasetCombobox({ const [datasetId, setDatasetId] = React.useState(""); const fetchDatasets = useQuery({ - queryKey: ["fetch-datasets-query"], + queryKey: ["fetch-datasets-query", projectId], queryFn: async () => { const response = await fetch(`/api/dataset?id=${projectId}`); const result = await response.json(); diff --git a/components/shared/header.tsx b/components/shared/header.tsx index 24c66ac7..9ce1eeb4 100644 --- a/components/shared/header.tsx +++ b/components/shared/header.tsx @@ -24,7 +24,7 @@ import { ProjectSwitcher } from "./project-switcher"; export function Header({ email }: { email: string }) { const pathname = usePathname(); const fetchAccountStats = useQuery({ - queryKey: ["fetch-account-stats"], + queryKey: ["fetch-account-stats", email], queryFn: async () => { const response = await fetch(`/api/stats/account?email=${email}`); const result = await response.json(); @@ -45,13 +45,13 @@ export function Header({ email }: { email: string }) {
- - Langtrace AI - - {pathname.includes("/project/") && } + + Langtrace AI + + {pathname.includes("/project/") && }
diff --git a/components/shared/project-switcher.tsx b/components/shared/project-switcher.tsx index 54ff8375..5a1c3897 100644 --- a/components/shared/project-switcher.tsx +++ b/components/shared/project-switcher.tsx @@ -1,11 +1,21 @@ import { Button } from "@/components/ui/button"; -import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem } from "@/components/ui/command"; -import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; +import { + Command, + CommandEmpty, + CommandGroup, + CommandInput, + CommandItem, +} from "@/components/ui/command"; +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover"; import { cn } from "@/lib/utils"; import { CaretSortIcon, CheckIcon } from "@radix-ui/react-icons"; import Link from "next/link"; import { usePathname } from "next/navigation"; -import React from 'react'; +import React from "react"; import { useQuery } from "react-query"; import { toast } from "sonner"; @@ -16,9 +26,9 @@ export function ProjectSwitcher({ email }: { email: string }) { const { data: projects, isLoading: projectsLoading, - error: projectsError + error: projectsError, } = useQuery({ - queryKey: ["fetch-projects-query"], + queryKey: ["fetch-projects-query", email], queryFn: async () => { const response = await fetch(`/api/projects?email=${email}`); if (!response.ok) { @@ -43,7 +53,11 @@ export function ProjectSwitcher({ email }: { email: string }) { aria-expanded={open} className="w-[200px] justify-between" > - {projects?.projects.filter((project : any) => project.id === pathname.split("/")[2])[0]?.name} + { + projects?.projects.filter( + (project: any) => project.id === pathname.split("/")[2] + )[0]?.name + } @@ -52,8 +66,12 @@ export function ProjectSwitcher({ email }: { email: string }) { No project found. - {projects?.projects.map((project : any) => ( - + {projects?.projects.map((project: any) => ( + {project.name}
@@ -74,4 +97,4 @@ export function ProjectSwitcher({ email }: { email: string }) { ); -} \ No newline at end of file +}