@@ -5,7 +5,12 @@ import {useLocation} from 'react-router-dom'
55
66// Utils
77import { notify } from 'src/shared/actions/notifications'
8- import { getOperatorAccounts , getOperatorOrgs } from 'src/client/unityRoutes'
8+ import {
9+ getOperatorAccounts ,
10+ getOperatorOrgs ,
11+ getOperatorProviders ,
12+ OperatorProvidersResponse ,
13+ } from 'src/client/unityRoutes'
914import { getAccountsError , getOrgsError } from 'src/shared/copy/notifications'
1015import { getQuartzMe } from 'src/me/selectors'
1116
@@ -32,9 +37,17 @@ export interface OperatorContextType {
3237 ) => void
3338 handleGetAccounts : ( ) => void
3439 handleGetOrgs : ( ) => void
40+ handleGetProviders : ( ) => void
3541 organizations : OperatorOrg [ ]
3642 pathname : string
43+ providerInfo : OperatorProvidersResponse
3744 searchTerm : string
45+ providers : string [ ]
46+ setProviders : (
47+ providers : string [ ] | ( ( prevState : string [ ] ) => string [ ] )
48+ ) => void
49+ regions : string [ ]
50+ setRegions : ( regions : string [ ] | ( ( prevState : string [ ] ) => string [ ] ) ) => void
3851 setSearchTerm : ( searchTerm ?: string ) => void
3952 status : RemoteDataState
4053 hasWritePermissions : boolean
@@ -46,9 +59,18 @@ export const DEFAULT_CONTEXT: OperatorContextType = {
4659 setAccountTypes : ( ) => { } ,
4760 handleGetAccounts : ( ) => { } ,
4861 handleGetOrgs : ( ) => { } ,
62+ handleGetProviders : ( ) => { } ,
4963 organizations : [ ] ,
5064 pathname : OperatorRoutes . default ,
65+ providerInfo : {
66+ providers : [ ] ,
67+ regions : { } ,
68+ } ,
5169 searchTerm : '' ,
70+ providers : [ ] ,
71+ setProviders : ( ) => { } ,
72+ regions : [ ] ,
73+ setRegions : ( ) => { } ,
5274 setSearchTerm : ( ) => { } ,
5375 status : RemoteDataState . NotStarted ,
5476 hasWritePermissions : false ,
@@ -64,6 +86,11 @@ export const OperatorProvider: FC<Props> = React.memo(({children}) => {
6486 const [ orgsStatus , setOrgsStatus ] = useState ( RemoteDataState . NotStarted )
6587 const [ searchTerm , setSearchTerm ] = useState ( '' )
6688 const [ accountTypes , setAccountTypes ] = useState < AccountType [ ] > ( [ ] )
89+ const [ providers , setProviders ] = useState < string [ ] > ( [ ] )
90+ const [ regions , setRegions ] = useState < string [ ] > ( [ ] )
91+ const [ providerInfo , setProviderInfo ] = useState < OperatorProvidersResponse > (
92+ DEFAULT_CONTEXT . providerInfo
93+ )
6794 const dispatch = useDispatch ( )
6895 const quartzMe = useSelector ( getQuartzMe )
6996
@@ -96,7 +123,12 @@ export const OperatorProvider: FC<Props> = React.memo(({children}) => {
96123 try {
97124 setOrgsStatus ( RemoteDataState . Loading )
98125 const resp = await getOperatorOrgs ( {
99- query : { query : searchTerm , accountTypes} ,
126+ query : {
127+ query : searchTerm ,
128+ accountTypes,
129+ providers,
130+ regions,
131+ } ,
100132 } )
101133
102134 if ( resp . status !== 200 ) {
@@ -110,7 +142,21 @@ export const OperatorProvider: FC<Props> = React.memo(({children}) => {
110142 setOrgsStatus ( RemoteDataState . Error )
111143 dispatch ( notify ( getOrgsError ( ) ) )
112144 }
113- } , [ accountTypes , searchTerm , dispatch ] )
145+ } , [ accountTypes , searchTerm , providers , regions , dispatch ] )
146+
147+ const handleGetProviders = useCallback ( async ( ) => {
148+ try {
149+ const resp = await getOperatorProviders ( { } )
150+
151+ if ( resp . status !== 200 ) {
152+ throw new Error ( resp . data . message )
153+ }
154+
155+ setProviderInfo ( resp . data )
156+ } catch ( error ) {
157+ console . error ( { error} )
158+ }
159+ } , [ ] )
114160
115161 const { pathname} = useLocation ( )
116162
@@ -123,12 +169,13 @@ export const OperatorProvider: FC<Props> = React.memo(({children}) => {
123169 handleGetAccounts ( )
124170 break
125171 case OperatorRoutes . organizations :
172+ handleGetProviders ( )
126173 handleGetOrgs ( )
127174 break
128175 default :
129176 return
130177 }
131- } , [ pathname , handleGetAccounts , handleGetOrgs ] )
178+ } , [ pathname , handleGetAccounts , handleGetOrgs , handleGetProviders ] )
132179
133180 let status = RemoteDataState . Done
134181
@@ -153,10 +200,16 @@ export const OperatorProvider: FC<Props> = React.memo(({children}) => {
153200 setAccountTypes,
154201 handleGetAccounts,
155202 handleGetOrgs,
203+ handleGetProviders,
156204 organizations,
157205 pathname,
206+ providerInfo,
158207 searchTerm,
159208 setSearchTerm,
209+ providers,
210+ setProviders,
211+ regions,
212+ setRegions,
160213 status,
161214 hasWritePermissions,
162215 } }
0 commit comments