Skip to content

Commit

Permalink
[NA]: [FE] replace getProjectByName function endpoint; (#643)
Browse files Browse the repository at this point in the history
* [NA]: replace getProjectByName function endpoint;

* [NA]: add signals to get by name requests;

* [NA]: use signal in getDatasetByName;

---------

Co-authored-by: Sasha <[email protected]>
  • Loading branch information
aadereiko and Sasha authored Nov 15, 2024
1 parent 0230420 commit 734e9fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
12 changes: 9 additions & 3 deletions apps/opik-frontend/src/api/datasets/useDatasetItemByName.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
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";

type UseDatasetByNameParams = {
datasetName: string;
};

const getDatasetByName = async ({ datasetName }: UseDatasetByNameParams) => {
const getDatasetByName = async (
{ signal }: QueryFunctionContext,
{ datasetName }: UseDatasetByNameParams,
) => {
const response = await api.post<Dataset>(
`${DATASETS_REST_ENDPOINT}/retrieve`,
{
dataset_name: datasetName,
},
{
signal,
},
);

return response.data;
Expand All @@ -23,7 +29,7 @@ export default function useDatasetItemByName(
) {
return useQuery({
queryKey: ["dataset", params],
queryFn: () => getDatasetByName(params),
queryFn: (context) => getDatasetByName(context, params),
...options,
});
}
22 changes: 7 additions & 15 deletions apps/opik-frontend/src/api/projects/useProjectByName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,26 @@ 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<UseProjectsListResponse>(
PROJECTS_REST_ENDPOINT,
const { data } = await api.post<Project>(
`${PROJECTS_REST_ENDPOINT}retrieve`,
{
name: projectName,
},
{
signal,
params: {
search: projectName,
page: 1,
size: 10000,
},
},
);

return data?.content.find((p) => p.name === projectName) || null;
return data;
};

export default function useProjectByName(
params: UseProjectByNameParams,
options?: QueryConfig<Project | null>,
options?: QueryConfig<Project>,
) {
return useQuery({
queryKey: ["project", params],
Expand Down

0 comments on commit 734e9fd

Please sign in to comment.