@@ -42,12 +42,6 @@ export const ProfilesSelector = ({
4242} : ProfilesSelectorProps ) => {
4343 const id = useId ( ) ;
4444
45- useEffect ( ( ) => {
46- if ( ! value && defaultValue ) {
47- onChange ( defaultValue ) ;
48- }
49- } , [ defaultValue ] ) ;
50-
5145 const genericSchemas = useAtomValue ( genericSchemasAtom ) ;
5246 const profileSchemas = useAtomValue ( profileSchemasAtom ) ;
5347
@@ -96,10 +90,6 @@ export const ProfilesSelector = ({
9690
9791 const { data, error, loading } = useQuery ( query ) ;
9892
99- if ( loading ) return < LoadingIndicator className = "p-4" /> ;
100-
101- if ( error ) return < ErrorScreen message = { error . message } /> ;
102-
10393 // Get all profiles name to retrieve the information from the result
10494 const profilesNameList : string [ ] = profilesList
10595 . map ( ( profile ) => profile ?. name ?? "" )
@@ -114,6 +104,26 @@ export const ProfilesSelector = ({
114104 [ ]
115105 ) ;
116106
107+ useEffect ( ( ) => {
108+ if ( ! value && defaultValue && profiles . length && ! loading ) {
109+ const defaultProfiles = defaultValue
110+ . map ( ( defaultProfile ) => {
111+ return profiles . find ( ( profile ) => {
112+ return profile . id === defaultProfile . id ;
113+ } ) ;
114+ } )
115+ . filter ( ( profile ) : profile is ProfileData => {
116+ return ! ! profile ?. id ;
117+ } ) ;
118+
119+ onChange ( defaultProfiles ) ;
120+ }
121+ } , [ defaultValue , loading , profiles ] ) ;
122+
123+ if ( loading ) return < LoadingIndicator className = "p-4" /> ;
124+
125+ if ( error ) return < ErrorScreen message = { error . message } /> ;
126+
117127 if ( ! profiles || profiles . length === 0 ) return null ;
118128
119129 const selectedValues = value ?? [ ] ;
0 commit comments