1- /*
2- * This file is part of Edgehog.
3- *
4- * Copyright 2025 SECO Mind Srl
5- *
6- * Licensed under the Apache License, Version 2.0 (the "License");
7- * you may not use this file except in compliance with the License.
8- * You may obtain a copy of the License at
9- *
10- * http://www.apache.org/licenses/LICENSE-2.0
11- *
12- * Unless required by applicable law or agreed to in writing, software
13- * distributed under the License is distributed on an "AS IS" BASIS,
14- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15- * See the License for the specific language governing permissions and
16- * limitations under the License.
17- *
18- * SPDX-License-Identifier: Apache-2.0
19- */
1+ // This file is part of Edgehog.
2+ //
3+ // Copyright 2025-2026 SECO Mind Srl
4+ //
5+ // Licensed under the Apache License, Version 2.0 (the "License");
6+ // you may not use this file except in compliance with the License.
7+ // You may obtain a copy of the License at
8+ //
9+ // http://www.apache.org/licenses/LICENSE-2.0
10+ //
11+ // Unless required by applicable law or agreed to in writing, software
12+ // distributed under the License is distributed on an "AS IS" BASIS,
13+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ // See the License for the specific language governing permissions and
15+ // limitations under the License.
16+ //
17+ // SPDX-License-Identifier: Apache-2.0
2018
21- import _ from "lodash" ;
2219import { Suspense , useCallback , useEffect , useMemo , useState } from "react" ;
2320import type { FallbackProps } from "react-error-boundary" ;
2421import { ErrorBoundary } from "react-error-boundary" ;
@@ -43,8 +40,9 @@ import {
4340import Button from "@/components/Button" ;
4441import Spinner from "@/components/Spinner" ;
4542import Stack from "@/components/Stack" ;
46- import { RECORDS_TO_LOAD_FIRST , RECORDS_TO_LOAD_NEXT } from "@/constants" ;
43+ import { RECORDS_TO_LOAD_FIRST } from "@/constants" ;
4744import { ApplicationRecord } from "@/forms/CreateDeploymentCampaign" ;
45+ import useRelayConnectionPagination from "@/hooks/useRelayConnectionPagination" ;
4846
4947const GET_APPLICATION_QUERY = graphql `
5048 query ReleaseSelect_getApplication_Query(
@@ -109,40 +107,24 @@ const ReleaseSelect = ({
109107
110108 const [ searchText , setSearchText ] = useState < string | null > ( null ) ;
111109
112- const debounceRefetch = useMemo (
113- ( ) =>
114- _ . debounce ( ( text : string ) => {
115- if ( text === "" ) {
116- refetch (
117- {
118- first : RECORDS_TO_LOAD_FIRST ,
119- } ,
120- { fetchPolicy : "network-only" } ,
121- ) ;
122- } else {
123- refetch (
124- {
125- first : RECORDS_TO_LOAD_FIRST ,
126- filter : { version : { ilike : `%${ text } %` } } ,
127- } ,
128- { fetchPolicy : "network-only" } ,
129- ) ;
130- }
131- } , 500 ) ,
132- [ refetch ] ,
133- ) ;
134-
135- useEffect ( ( ) => {
136- if ( searchText !== null ) {
137- debounceRefetch ( searchText ) ;
138- }
139- } , [ debounceRefetch , searchText ] ) ;
110+ const { onLoadMore } = useRelayConnectionPagination ( {
111+ hasNext,
112+ isLoadingNext,
113+ loadNext,
114+ refetch,
115+ searchText,
116+ buildFilter : ( text ) => {
117+ if ( text === "" ) {
118+ return undefined ;
119+ }
140120
141- const loadNextOptions = useCallback ( ( ) => {
142- if ( hasNext && ! isLoadingNext ) {
143- loadNext ( RECORDS_TO_LOAD_NEXT ) ;
144- }
145- } , [ hasNext , isLoadingNext , loadNext ] ) ;
121+ return {
122+ version : {
123+ ilike : `%${ text } %` ,
124+ } ,
125+ } ;
126+ } ,
127+ } ) ;
146128
147129 const releaseOptions = useMemo ( ( ) => {
148130 const releases =
@@ -192,7 +174,7 @@ const ReleaseSelect = ({
192174 getOptionValue = { getReleaseValue }
193175 noOptionsMessage = { ( { inputValue } ) => noReleaseOptionsMessage ( inputValue ) }
194176 isLoading = { isLoadingNext }
195- onMenuScrollToBottom = { hasNext ? loadNextOptions : undefined }
177+ onMenuScrollToBottom = { onLoadMore }
196178 onInputChange = { ( text ) => setSearchText ( text ) }
197179 />
198180 ) ;
0 commit comments