Skip to content

Commit

Permalink
fix ActivityStream button at details page
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Nackov <[email protected]>
  • Loading branch information
aeter committed Jul 11, 2024
1 parent 3187525 commit 2a554d7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 14 additions & 2 deletions frontend/awx/access/common/useViewActivityStream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export function useViewActivityStream<T extends object>() {
const location = useLocation();
const firstURLItems = location.pathname.split('/')[1];
const secondURLItems = location.pathname.split('/')[2];
const thirdUrlItems = location.pathname.split('/')[3];
const isSchedule = location.pathname.split('/').includes('schedules');
const isNumeric = (value: string) => {
return /^-?\d+$/.test(value);
};

const pathIdentifier = isSchedule
? 'schedules'
Expand Down Expand Up @@ -46,10 +50,18 @@ export function useViewActivityStream<T extends object>() {
case 'instance-groups':
type = 'instance_group';
break;
case 'templates':
type = secondURLItems.replace(/-/g, '_');
break;
default:
type = pathIdentifier.slice(0, -1);
break;
}
// add host__id=..., instance_group__id=... depending on url
const query = { query: { type } };
if (isNumeric(thirdUrlItems)) {
query['query'][`${type}__id`] = thirdUrlItems;
}
return useMemo<IPageAction<T>[] | []>(() => {
if (config?.license_info.product_name !== 'AWX') return [];
return [
Expand All @@ -58,9 +70,9 @@ export function useViewActivityStream<T extends object>() {
selection: PageActionSelection.Single,
icon: HistoryIcon,
label: t('View activity stream'),
onClick: () => pageNavigate(AwxRoute.ActivityStream, { query: { type } }),
onClick: () => pageNavigate(AwxRoute.ActivityStream, query),
},
{ type: PageActionType.Seperator },
];
}, [type, pageNavigate, t, config?.license_info.product_name]);
}, [pageNavigate, t, config?.license_info.product_name, query]);
}
7 changes: 7 additions & 0 deletions frontend/awx/common/useAwxView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ export function useAwxView<T extends { id: number }>(options: {
.split('+')
.join(',')}&or__object2__in=${values[0].split('+').join(',')}`;
}
// add Activity Stream id filtering, like host__id=2
for (const keyId in filterState) {
if (/.+__id/.test(keyId)) {
const valId: string = filterState[keyId];
queryString += `&${keyId}=${valId}`;
}
}
} else if (toolbarFilter.query === 'search') {
queryString += values.map((value) => `${toolbarFilter.query}=${value}`).join('&');
} else {
Expand Down

0 comments on commit 2a554d7

Please sign in to comment.