@@ -18,7 +18,11 @@ export function useViewActivityStream<T extends object>() {
18
18
const location = useLocation ( ) ;
19
19
const firstURLItems = location . pathname . split ( '/' ) [ 1 ] ;
20
20
const secondURLItems = location . pathname . split ( '/' ) [ 2 ] ;
21
+ const thirdUrlItems = location . pathname . split ( '/' ) [ 3 ] ;
21
22
const isSchedule = location . pathname . split ( '/' ) . includes ( 'schedules' ) ;
23
+ const isNumeric = ( value : string ) => {
24
+ return / ^ - ? \d + $ / . test ( value ) ;
25
+ } ;
22
26
23
27
const pathIdentifier = isSchedule
24
28
? 'schedules'
@@ -46,10 +50,18 @@ export function useViewActivityStream<T extends object>() {
46
50
case 'instance-groups' :
47
51
type = 'instance_group' ;
48
52
break ;
53
+ case 'templates' :
54
+ type = secondURLItems . replace ( / - / g, '_' ) ;
55
+ break ;
49
56
default :
50
57
type = pathIdentifier . slice ( 0 , - 1 ) ;
51
58
break ;
52
59
}
60
+ // add host__id=..., instance_group__id=... depending on url
61
+ const query = { query : { type } } ;
62
+ if ( isNumeric ( thirdUrlItems ) ) {
63
+ query [ 'query' ] [ `${ type } __id` ] = thirdUrlItems ;
64
+ }
53
65
return useMemo < IPageAction < T > [ ] | [ ] > ( ( ) => {
54
66
if ( config ?. license_info . product_name !== 'AWX' ) return [ ] ;
55
67
return [
@@ -58,9 +70,9 @@ export function useViewActivityStream<T extends object>() {
58
70
selection : PageActionSelection . Single ,
59
71
icon : HistoryIcon ,
60
72
label : t ( 'View activity stream' ) ,
61
- onClick : ( ) => pageNavigate ( AwxRoute . ActivityStream , { query : { type } } ) ,
73
+ onClick : ( ) => pageNavigate ( AwxRoute . ActivityStream , query ) ,
62
74
} ,
63
75
{ type : PageActionType . Seperator } ,
64
76
] ;
65
- } , [ type , pageNavigate , t , config ?. license_info . product_name ] ) ;
77
+ } , [ pageNavigate , t , config ?. license_info . product_name , query ] ) ;
66
78
}
0 commit comments