11// Copyright (C) 2022-2025 Intel Corporation
22// LIMITED EDGE SOFTWARE DISTRIBUTION LICENSE
33
4- import { ReactElement , ReactNode , Suspense } from 'react' ;
4+ import { ReactElement , ReactNode , Suspense , useMemo } from 'react' ;
55
66import { CustomFeatureFlags , DEV_FEATURE_FLAGS } from '@geti/core' ;
77import QUERY_KEYS from '@geti/core/src/requests/query-keys' ;
@@ -11,13 +11,16 @@ import {
1111} from '@geti/core/src/services/application-services-provider.component' ;
1212import { OnboardingProfile } from '@geti/core/src/users/services/onboarding-service.interface' ;
1313import { defaultTheme , IntelBrandedLoading , Provider as ThemeProvider } from '@geti/ui' ;
14- import { QueryClient , QueryClientProvider } from '@tanstack/react-query' ;
1514import { render , RenderOptions , RenderResult } from '@testing-library/react' ;
1615import { AuthProvider } from 'react-oidc-context' ;
1716import { MemoryRouter as Router } from 'react-router-dom' ;
1817
1918import { AccountStatusDTO } from '../core/organizations/dtos/organizations.interface' ;
20- import { NotificationProvider , Notifications } from '../notification/notification.component' ;
19+ import { NotificationProvider , Notifications , useNotification } from '../notification/notification.component' ;
20+ import {
21+ createGetiQueryClient ,
22+ QueryClientProvider ,
23+ } from '../providers/query-client-provider/query-client-provider.component' ;
2124import { TusUploadProvider } from '../providers/tus-upload-provider/tus-upload-provider.component' ;
2225import { getMockedWorkspace } from './mocked-items-factory/mocked-workspace' ;
2326
@@ -26,68 +29,79 @@ interface RequiredProvidersProps extends Partial<ApplicationServicesContextProps
2629 initialEntries ?: string [ ] ;
2730 featureFlags ?: CustomFeatureFlags ;
2831 profile ?: OnboardingProfile | null ;
29- queryClient ?: QueryClient ;
3032}
3133
3234const prefilledOrgId = '000000000000000000000001' ;
3335
34- const usePrefilledQueryClient = ( featureFlags ?: CustomFeatureFlags , profile ?: OnboardingProfile | null ) => {
35- const queryClient = new QueryClient ( {
36- defaultOptions : {
37- queries : {
38- gcTime : 1000 ,
36+ const PrefilledQueryClientProvider = ( {
37+ children,
38+ featureFlags,
39+ profile,
40+ } : {
41+ children : ReactNode ;
42+ featureFlags ?: CustomFeatureFlags ;
43+ profile ?: OnboardingProfile | null ;
44+ } ) => {
45+ const { addNotification } = useNotification ( ) ;
46+
47+ const prefilledQueryClient = useMemo ( ( ) => {
48+ const client = createGetiQueryClient ( {
49+ addNotification,
50+ defaultQueryOptions : {
51+ queries : {
52+ gcTime : 1000 ,
53+ } ,
3954 } ,
40- } ,
41- } ) ;
42-
43- queryClient . setQueryData ( QUERY_KEYS . FEATURE_FLAGS , {
44- ...DEV_FEATURE_FLAGS ,
45- ...featureFlags ,
46- } ) ;
47-
48- if ( profile !== null ) {
49- queryClient . setQueryData ( QUERY_KEYS . USER_ONBOARDING_PROFILE , {
50- organizations : [ { id : prefilledOrgId , status : AccountStatusDTO . ACTIVE } ] ,
51- hasAcceptedUserTermsAndConditions : true ,
52- ...profile ,
5355 } ) ;
54- }
5556
56- [ '123' , 'org-id' , 'organization-id' , prefilledOrgId ] . forEach ( ( organizationId ) => {
57- const workspaceKey = QUERY_KEYS . WORKSPACES ( organizationId ) ;
57+ client . setQueryData ( QUERY_KEYS . FEATURE_FLAGS , {
58+ ...DEV_FEATURE_FLAGS ,
59+ ...featureFlags ,
60+ } ) ;
5861
59- queryClient . setQueryData ( workspaceKey , [
60- getMockedWorkspace ( { id : 'workspace-1' , name : 'Workspace 1' } ) ,
61- getMockedWorkspace ( { id : 'workspace-2' , name : 'Workspace 2' } ) ,
62- ] ) ;
63- } ) ;
62+ if ( profile !== null && profile !== undefined ) {
63+ client . setQueryData ( QUERY_KEYS . USER_ONBOARDING_PROFILE , {
64+ ...profile ,
65+ organizations : [ { id : prefilledOrgId , status : AccountStatusDTO . ACTIVE } ] ,
66+ hasAcceptedUserTermsAndConditions : true ,
67+ } ) ;
68+ }
69+
70+ [ '123' , 'org-id' , 'organization-id' , prefilledOrgId ] . forEach ( ( organizationId ) => {
71+ const workspaceKey = QUERY_KEYS . WORKSPACES ( organizationId ) ;
72+
73+ client . setQueryData ( workspaceKey , [
74+ getMockedWorkspace ( { id : 'workspace-1' , name : 'Workspace 1' } ) ,
75+ getMockedWorkspace ( { id : 'workspace-2' , name : 'Workspace 2' } ) ,
76+ ] ) ;
77+ } ) ;
6478
65- return queryClient ;
79+ return client ;
80+ } , [ addNotification , featureFlags , profile ] ) ;
81+
82+ return < QueryClientProvider customQueryClient = { prefilledQueryClient } > { children } </ QueryClientProvider > ;
6683} ;
6784
6885export const RequiredProviders = ( {
6986 children,
7087 featureFlags,
7188 initialEntries,
7289 profile,
73- queryClient,
7490 ...services
7591} : RequiredProvidersProps ) : JSX . Element => {
76- const prefilledQueryClient = usePrefilledQueryClient ( featureFlags , profile ) ;
77-
7892 return (
7993 < Suspense fallback = { < IntelBrandedLoading /> } >
8094 < Router initialEntries = { initialEntries } >
8195 < AuthProvider >
8296 < NotificationProvider >
8397 < Notifications />
84- < QueryClientProvider client = { queryClient ?? prefilledQueryClient } >
98+ < PrefilledQueryClientProvider featureFlags = { featureFlags } profile = { profile } >
8599 < ThemeProvider theme = { defaultTheme } >
86100 < ApplicationServicesProvider useInMemoryEnvironment { ...services } >
87101 < TusUploadProvider > { children } </ TusUploadProvider >
88102 </ ApplicationServicesProvider >
89103 </ ThemeProvider >
90- </ QueryClientProvider >
104+ </ PrefilledQueryClientProvider >
91105 </ NotificationProvider >
92106 </ AuthProvider >
93107 </ Router >
0 commit comments