1- import { useInfiniteQuery } from "@tanstack/react-query" ;
1+ import {
2+ useInfiniteQuery ,
3+ useSuspenseInfiniteQuery ,
4+ } from "@tanstack/react-query" ;
25import { useEffect , useRef } from "react" ;
36import { type UseFormReturn , useFormContext } from "react-hook-form" ;
47import z from "zod" ;
@@ -212,11 +215,34 @@ export const ActorPreview = () => {
212215 ) ;
213216} ;
214217
218+ export const PrefillActorName = ( ) => {
219+ const prefilled = useRef ( false ) ;
220+ const { watch } = useFormContext < FormValues > ( ) ;
221+
222+ const { data : name , isSuccess } = useSuspenseInfiniteQuery ( {
223+ ...useEngineCompatDataProvider ( ) . buildsQueryOptions ( ) ,
224+ select : ( data ) => data . pages [ 0 ] . builds [ 0 ] . name ,
225+ } ) ;
226+
227+ const watchedValue = watch ( "name" ) ;
228+
229+ const { setValue } = useFormContext < FormValues > ( ) ;
230+
231+ useEffect ( ( ) => {
232+ if ( name && isSuccess && ! watchedValue && ! prefilled . current ) {
233+ setValue ( "name" , name ) ;
234+ prefilled . current = true ;
235+ }
236+ } , [ name , setValue , isSuccess , watchedValue ] ) ;
237+
238+ return null ;
239+ } ;
240+
215241export const PrefillRunnerName = ( ) => {
216242 const prefilled = useRef ( false ) ;
217243 const { watch } = useFormContext < FormValues > ( ) ;
218244
219- const { data = [ ] , isSuccess } = useInfiniteQuery (
245+ const { data = [ ] , isSuccess } = useSuspenseInfiniteQuery (
220246 useEngineCompatDataProvider ( ) . runnerNamesQueryOptions ( ) ,
221247 ) ;
222248
@@ -239,6 +265,33 @@ export const PrefillRunnerName = () => {
239265 return null ;
240266} ;
241267
268+ export const PrefillDatacenter = ( ) => {
269+ const prefilled = useRef ( false ) ;
270+ const { watch } = useFormContext < FormValues > ( ) ;
271+
272+ const { data : datacenter , isSuccess } = useSuspenseInfiniteQuery ( {
273+ ...useEngineCompatDataProvider ( ) . runnerConfigsQueryOptions ( ) ,
274+ select : ( data ) => {
275+ return Object . keys (
276+ Object . values ( data . pages [ 0 ] . runnerConfigs ) [ 0 ] . datacenters ,
277+ ) [ 0 ] ;
278+ } ,
279+ } ) ;
280+
281+ const watchedValue = watch ( "datacenter" ) ;
282+
283+ const { setValue } = useFormContext < FormValues > ( ) ;
284+
285+ useEffect ( ( ) => {
286+ if ( datacenter && isSuccess && ! watchedValue && ! prefilled . current ) {
287+ setValue ( "datacenter" , datacenter ) ;
288+ prefilled . current = true ;
289+ }
290+ } , [ datacenter , setValue , isSuccess , watchedValue ] ) ;
291+
292+ return null ;
293+ } ;
294+
242295export const Datacenter = ( ) => {
243296 const { control } = useFormContext < FormValues > ( ) ;
244297
@@ -251,6 +304,7 @@ export const Datacenter = () => {
251304 < FormLabel > Datacenter</ FormLabel >
252305 < FormControl >
253306 < RegionSelect
307+ showAuto = { false }
254308 value = { field . value }
255309 onValueChange = { field . onChange }
256310 />
0 commit comments