bbovenzi commented on code in PR #50732:
URL: https://github.com/apache/airflow/pull/50732#discussion_r2124667970


##########
airflow-core/src/airflow/ui/openapi-gen/queries/customInfiniteQueries.ts:
##########
@@ -0,0 +1,38 @@
+import { InfiniteData, useInfiniteQuery, UseInfiniteQueryOptions } from 
"@tanstack/react-query";
+
+import { DagService } from "openapi/requests/services.gen";
+
+import * as Common from "./common";
+
+export const useDagServiceGetDagTagsInfinite = <
+  TData = InfiniteData<Common.DagServiceGetDagTagsDefaultResponse>,
+  TError = unknown,
+  TQueryKey extends Array<unknown> = unknown[],
+>(
+  {
+    limit,
+    orderBy,
+    tagNamePattern,
+  }: {
+    limit?: number;
+    orderBy?: string;
+    tagNamePattern?: string;
+  } = {},
+  queryKey?: TQueryKey,
+  options?: Omit<UseInfiniteQueryOptions<TData, TError>, "queryKey" | 
"queryFn">,
+) =>
+  useInfiniteQuery({
+    queryKey: Common.UseDagServiceGetDagTagsKeyFn({ limit, orderBy, 
tagNamePattern }, queryKey),
+    queryFn: ({ pageParam }) =>
+      DagService.getDagTags({ limit, offset: pageParam as number, orderBy, 
tagNamePattern }) as TData,
+    initialPageParam: 0,
+    getNextPageParam: (lastPage, _allPages, lastPageParam, _allPageParams) =>
+      (lastPageParam as number) < (lastPage as 
Common.DagServiceGetDagTagsDefaultResponse).total_entries
+        ? (lastPage as Common.DagServiceGetDagTagsDefaultResponse).tags.length 
+ (lastPageParam as number)
+        : undefined,
+    getPreviousPageParam: (firstPage, _allPages, firstPageParam, 
_allPageParams) =>
+      (firstPageParam as number) > 0
+        ? -(firstPage as 
Common.DagServiceGetDagTagsDefaultResponse).tags.length + (firstPageParam as 
number)
+        : undefined,

Review Comment:
   Does `pageParam = 0` as a default help?
   
   And then using the below type can allow us to cast only once.
   
   ```
   type QueryOptions = UseInfiniteQueryOptions<
     DAGTagCollectionResponse,
     Error,
     InfiniteData<DAGTagCollectionResponse>,
     DAGTagCollectionResponse,
     unknown[],
     number
   >;



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to