@@ -20,10 +20,10 @@ import { Field } from "@chakra-ui/react";
2020import { useQueryClient } from "@tanstack/react-query" ;
2121import { AsyncSelect } from "chakra-react-select" ;
2222import type { OptionsOrGroups , GroupBase , SingleValue } from "chakra-react-select" ;
23- import debounce from "debounce-promise" ;
2423import React from "react" ;
2524import { useTranslation } from "react-i18next" ;
2625import { useNavigate } from "react-router-dom" ;
26+ import { useDebouncedCallback } from "use-debounce" ;
2727
2828import { UseDagServiceGetDagsKeyFn } from "openapi/queries" ;
2929import { DagService } from "openapi/requests/services.gen" ;
@@ -49,32 +49,31 @@ export const SearchDags = ({
4949 }
5050 } ;
5151
52- const searchDag = (
53- inputValue : string ,
54- callback : ( options : OptionsOrGroups < Option , GroupBase < Option > > ) => void ,
55- ) : Promise < OptionsOrGroups < Option , GroupBase < Option > > > =>
56- queryClient . fetchQuery ( {
57- queryFn : ( ) =>
58- DagService . getDags ( {
59- dagDisplayNamePattern : inputValue ,
60- limit : SEARCH_LIMIT ,
61- } ) . then ( ( data : DAGCollectionResponse ) => {
62- const options = data . dags . map ( ( dag : DAGResponse ) => ( {
63- label : dag . dag_display_name || dag . dag_id ,
64- value : dag . dag_id ,
65- } ) ) ;
52+ const searchDagDebounced = useDebouncedCallback (
53+ ( inputValue : string , callback : ( options : OptionsOrGroups < Option , GroupBase < Option > > ) => void ) => {
54+ void queryClient . fetchQuery ( {
55+ queryFn : ( ) =>
56+ DagService . getDags ( {
57+ dagDisplayNamePattern : inputValue ,
58+ limit : SEARCH_LIMIT ,
59+ } ) . then ( ( data : DAGCollectionResponse ) => {
60+ const options = data . dags . map ( ( dag : DAGResponse ) => ( {
61+ label : dag . dag_display_name || dag . dag_id ,
62+ value : dag . dag_id ,
63+ } ) ) ;
6664
67- callback ( options ) ;
65+ callback ( options ) ;
6866
69- return options ;
67+ return options ;
68+ } ) ,
69+ queryKey : UseDagServiceGetDagsKeyFn ( {
70+ dagDisplayNamePattern : inputValue ,
7071 } ) ,
71- queryKey : UseDagServiceGetDagsKeyFn ( {
72- dagDisplayNamePattern : inputValue ,
73- } ) ,
74- staleTime : 0 ,
75- } ) ;
76-
77- const searchDagDebounced = debounce ( searchDag , 300 ) ;
72+ staleTime : 0 ,
73+ } ) ;
74+ } ,
75+ 300 ,
76+ ) ;
7877
7978 return (
8079 < Field . Root >
0 commit comments