Skip to content

Commit 2a554d7

Browse files
committed
fix ActivityStream button at details page
Signed-off-by: Adrian Nackov <adrian.nackov@mail.schwarz>
1 parent 3187525 commit 2a554d7

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

frontend/awx/access/common/useViewActivityStream.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export function useViewActivityStream<T extends object>() {
1818
const location = useLocation();
1919
const firstURLItems = location.pathname.split('/')[1];
2020
const secondURLItems = location.pathname.split('/')[2];
21+
const thirdUrlItems = location.pathname.split('/')[3];
2122
const isSchedule = location.pathname.split('/').includes('schedules');
23+
const isNumeric = (value: string) => {
24+
return /^-?\d+$/.test(value);
25+
};
2226

2327
const pathIdentifier = isSchedule
2428
? 'schedules'
@@ -46,10 +50,18 @@ export function useViewActivityStream<T extends object>() {
4650
case 'instance-groups':
4751
type = 'instance_group';
4852
break;
53+
case 'templates':
54+
type = secondURLItems.replace(/-/g, '_');
55+
break;
4956
default:
5057
type = pathIdentifier.slice(0, -1);
5158
break;
5259
}
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+
}
5365
return useMemo<IPageAction<T>[] | []>(() => {
5466
if (config?.license_info.product_name !== 'AWX') return [];
5567
return [
@@ -58,9 +70,9 @@ export function useViewActivityStream<T extends object>() {
5870
selection: PageActionSelection.Single,
5971
icon: HistoryIcon,
6072
label: t('View activity stream'),
61-
onClick: () => pageNavigate(AwxRoute.ActivityStream, { query: { type } }),
73+
onClick: () => pageNavigate(AwxRoute.ActivityStream, query),
6274
},
6375
{ type: PageActionType.Seperator },
6476
];
65-
}, [type, pageNavigate, t, config?.license_info.product_name]);
77+
}, [pageNavigate, t, config?.license_info.product_name, query]);
6678
}

frontend/awx/common/useAwxView.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ export function useAwxView<T extends { id: number }>(options: {
107107
.split('+')
108108
.join(',')}&or__object2__in=${values[0].split('+').join(',')}`;
109109
}
110+
// add Activity Stream id filtering, like host__id=2
111+
for (const keyId in filterState) {
112+
if (/.+__id/.test(keyId)) {
113+
const valId: string = filterState[keyId];
114+
queryString += `&${keyId}=${valId}`;
115+
}
116+
}
110117
} else if (toolbarFilter.query === 'search') {
111118
queryString += values.map((value) => `${toolbarFilter.query}=${value}`).join('&');
112119
} else {

0 commit comments

Comments
 (0)