@@ -28,10 +28,10 @@ const SectionTitle = ({ children }: { children: ReactNode }) => (
28
28
< h2 className = 'pf-c-title' > { children } </ h2 >
29
29
) ;
30
30
31
- export const Dispatch = ( props : RouteProps ) => {
31
+ export const Dispatch = ( { location , navigate } : RouteProps ) => {
32
32
const { featureFlags } = useContext ( ) ;
33
33
34
- const { pathname } = ParamHelper . parseParamString ( props . location . search ) as {
34
+ const { pathname } = ParamHelper . parseParamString ( location . search ) as {
35
35
pathname : string ;
36
36
} ;
37
37
@@ -41,15 +41,56 @@ export const Dispatch = (props: RouteProps) => {
41
41
const [ roles , setRoles ] = useState ( null ) ;
42
42
43
43
useEffect ( ( ) => {
44
- CollectionVersionAPI . list ( { namespace, name, is_highest : true } )
45
- . then ( ( { data : { data } } ) => setCollections ( data || [ ] ) )
46
- . catch ( ( ) => setCollections ( [ ] ) ) ;
44
+ const wait = [ ] ;
45
+
46
+ wait . push (
47
+ CollectionVersionAPI . list ( { namespace, name, is_highest : true } )
48
+ . then ( ( { data : { data } } ) => data || [ ] )
49
+ . catch ( ( ) => [ ] )
50
+ . then ( ( c ) => ( setCollections ( c ) , c ) ) ,
51
+ ) ;
47
52
48
53
if ( featureFlags . legacy_roles ) {
49
- LegacyRoleAPI . list ( { github_user : namespace , name } )
50
- . then ( ( { data : { results } } ) => setRoles ( results || [ ] ) )
51
- . catch ( ( ) => setRoles ( [ ] ) ) ;
54
+ wait . push (
55
+ LegacyRoleAPI . list ( { github_user : namespace , name } )
56
+ . then ( ( { data : { results } } ) => results || [ ] )
57
+ . catch ( ( ) => [ ] )
58
+ . then ( ( r ) => ( setRoles ( r ) , r ) ) ,
59
+ ) ;
52
60
}
61
+
62
+ Promise . all ( wait ) . then ( ( [ collections , roles ] ) => {
63
+ if ( collections . length === 1 && ! roles ?. length ) {
64
+ const {
65
+ collection_version : { name : collection , namespace } ,
66
+ repository : { name : repo } ,
67
+ } = collections [ 0 ] ;
68
+
69
+ navigate (
70
+ formatPath ( Paths . collectionByRepo , {
71
+ collection,
72
+ namespace,
73
+ repo,
74
+ } ) ,
75
+ ) ;
76
+ }
77
+
78
+ if ( roles . length === 1 && ! collections . length ) {
79
+ const {
80
+ name,
81
+ summary_fields : {
82
+ namespace : { name : username } ,
83
+ } ,
84
+ } = roles [ 0 ] ;
85
+
86
+ navigate (
87
+ formatPath ( Paths . legacyRole , {
88
+ username,
89
+ name,
90
+ } ) ,
91
+ ) ;
92
+ }
93
+ } ) ;
53
94
} , [ pathname ] ) ;
54
95
55
96
return (
0 commit comments