From 25fb86a290c4ac5cc2ef6cd6e994b5e0f8a0d254 Mon Sep 17 00:00:00 2001 From: Sasha Date: Thu, 14 Nov 2024 18:10:34 +0100 Subject: [PATCH 1/3] [NA]: replace getProjectByName function endpoint; --- .../src/api/projects/useProjectByName.ts | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/apps/opik-frontend/src/api/projects/useProjectByName.ts b/apps/opik-frontend/src/api/projects/useProjectByName.ts index f5926cb64..bf1eefbb2 100644 --- a/apps/opik-frontend/src/api/projects/useProjectByName.ts +++ b/apps/opik-frontend/src/api/projects/useProjectByName.ts @@ -1,4 +1,4 @@ -import { QueryFunctionContext, useQuery } from "@tanstack/react-query"; +import { useQuery } from "@tanstack/react-query"; import api, { PROJECTS_REST_ENDPOINT, QueryConfig } from "@/api/api"; import { Project } from "@/types/projects"; @@ -6,38 +6,24 @@ type UseProjectByNameParams = { projectName: string; }; -type UseProjectsListResponse = { - content: Project[]; - total: number; -}; - -// @todo: replace it with another request to get a project id only when the be is ready -const getProjectByName = async ( - { signal }: QueryFunctionContext, - { projectName }: UseProjectByNameParams, -) => { - const { data } = await api.get( - PROJECTS_REST_ENDPOINT, +const getProjectByName = async ({ projectName }: UseProjectByNameParams) => { + const { data } = await api.post( + `${PROJECTS_REST_ENDPOINT}retrieve`, { - signal, - params: { - search: projectName, - page: 1, - size: 10000, - }, + name: projectName, }, ); - return data?.content.find((p) => p.name === projectName) || null; + return data; }; export default function useProjectByName( params: UseProjectByNameParams, - options?: QueryConfig, + options?: QueryConfig, ) { return useQuery({ queryKey: ["project", params], - queryFn: (context) => getProjectByName(context, params), + queryFn: () => getProjectByName(params), ...options, }); } From 3166e577d19f65c49a1437b617315a337f23afd5 Mon Sep 17 00:00:00 2001 From: Sasha Date: Fri, 15 Nov 2024 07:52:44 +0100 Subject: [PATCH 2/3] [NA]: add signals to get by name requests; --- .../src/api/datasets/useDatasetItemByName.ts | 9 ++++++--- .../src/api/projects/useProjectByName.ts | 12 +++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/opik-frontend/src/api/datasets/useDatasetItemByName.ts b/apps/opik-frontend/src/api/datasets/useDatasetItemByName.ts index c9f0fdc0f..12723a4f4 100644 --- a/apps/opik-frontend/src/api/datasets/useDatasetItemByName.ts +++ b/apps/opik-frontend/src/api/datasets/useDatasetItemByName.ts @@ -1,4 +1,4 @@ -import { useQuery } from "@tanstack/react-query"; +import { QueryFunctionContext, useQuery } from "@tanstack/react-query"; import api, { DATASETS_REST_ENDPOINT, QueryConfig } from "@/api/api"; import { Dataset } from "@/types/datasets"; @@ -6,7 +6,10 @@ type UseDatasetByNameParams = { datasetName: string; }; -const getDatasetByName = async ({ datasetName }: UseDatasetByNameParams) => { +const getDatasetByName = async ( + { signal }: QueryFunctionContext, + { datasetName }: UseDatasetByNameParams, +) => { const response = await api.post( `${DATASETS_REST_ENDPOINT}/retrieve`, { @@ -23,7 +26,7 @@ export default function useDatasetItemByName( ) { return useQuery({ queryKey: ["dataset", params], - queryFn: () => getDatasetByName(params), + queryFn: (context) => getDatasetByName(context, params), ...options, }); } diff --git a/apps/opik-frontend/src/api/projects/useProjectByName.ts b/apps/opik-frontend/src/api/projects/useProjectByName.ts index bf1eefbb2..2a09c63ad 100644 --- a/apps/opik-frontend/src/api/projects/useProjectByName.ts +++ b/apps/opik-frontend/src/api/projects/useProjectByName.ts @@ -1,4 +1,4 @@ -import { useQuery } from "@tanstack/react-query"; +import { QueryFunctionContext, useQuery } from "@tanstack/react-query"; import api, { PROJECTS_REST_ENDPOINT, QueryConfig } from "@/api/api"; import { Project } from "@/types/projects"; @@ -6,12 +6,18 @@ type UseProjectByNameParams = { projectName: string; }; -const getProjectByName = async ({ projectName }: UseProjectByNameParams) => { +const getProjectByName = async ( + { signal }: QueryFunctionContext, + { projectName }: UseProjectByNameParams, +) => { const { data } = await api.post( `${PROJECTS_REST_ENDPOINT}retrieve`, { name: projectName, }, + { + signal, + }, ); return data; @@ -23,7 +29,7 @@ export default function useProjectByName( ) { return useQuery({ queryKey: ["project", params], - queryFn: () => getProjectByName(params), + queryFn: (context) => getProjectByName(context, params), ...options, }); } From b1bcbf67fb3ffc69e6970fb1ec94a1f5bfce0868 Mon Sep 17 00:00:00 2001 From: Sasha Date: Fri, 15 Nov 2024 08:42:32 +0100 Subject: [PATCH 3/3] [NA]: use signal in getDatasetByName; --- apps/opik-frontend/src/api/datasets/useDatasetItemByName.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/opik-frontend/src/api/datasets/useDatasetItemByName.ts b/apps/opik-frontend/src/api/datasets/useDatasetItemByName.ts index 12723a4f4..d4988a742 100644 --- a/apps/opik-frontend/src/api/datasets/useDatasetItemByName.ts +++ b/apps/opik-frontend/src/api/datasets/useDatasetItemByName.ts @@ -15,6 +15,9 @@ const getDatasetByName = async ( { dataset_name: datasetName, }, + { + signal, + }, ); return response.data;