Skip to content

Commit

Permalink
✨ Fetch tasks with server-based filtering (#1956)
Browse files Browse the repository at this point in the history
Part-of: #1931
Reference-Url: konveyor/tackle2-hub#640

Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko authored Jun 13, 2024
1 parent 460fded commit c2f4f06
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions client/src/app/api/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ export function getTaskById(
export const getTasks = () =>
axios.get<Task[]>(TASKS).then((response) => response.data);

export const getServerTasks = (params: HubRequestParams = {}) =>
getHubPaginatedResult<Task>(TASKS, params);

export const deleteTask = (id: number) => axios.delete<Task>(`${TASKS}/${id}`);

export const cancelTask = (id: number) =>
Expand Down
29 changes: 28 additions & 1 deletion client/src/app/queries/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { useMutation, useQuery } from "@tanstack/react-query";

import { cancelTask, deleteTask, getTaskById, getTasks } from "@app/api/rest";
import {
cancelTask,
deleteTask,
getServerTasks,
getTaskById,
getTasks,
} from "@app/api/rest";
import { universalComparator } from "@app/utils/utils";
import { HubPaginatedResult, HubRequestParams, Task } from "@app/api/models";

interface FetchTasksFilters {
addon?: string;
Expand Down Expand Up @@ -50,6 +57,26 @@ export const useFetchTasks = (
};
};

export const useServerTasks = (params: HubRequestParams = {}) => {
const { data, isLoading, error, refetch } = useQuery({
queryKey: [TasksQueryKey, params],
queryFn: async () => await getServerTasks(params),
onError: (error) => console.log("error, ", error),
keepPreviousData: true,
});

return {
result: {
data: data?.data,
total: data?.total ?? 0,
params: data?.params ?? params,
} as HubPaginatedResult<Task>,
isFetching: isLoading,
fetchError: error,
refetch,
};
};

export const useDeleteTaskMutation = (
onSuccess: () => void,
onError: (err: Error | null) => void
Expand Down

0 comments on commit c2f4f06

Please sign in to comment.