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 <adrian.nackov@mail.schwarz>
  • Loading branch information
aeter committed Jul 17, 2024
1 parent 372d1ca commit efb9e71
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
14 changes: 12 additions & 2 deletions frontend/awx/access/common/useViewActivityStream.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HistoryIcon } from '@patternfly/react-icons';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom';
import {
IPageAction,
PageActionSelection,
Expand All @@ -11,16 +12,25 @@ import { AwxRoute } from '../../main/AwxRoutes';
export function useViewActivityStream<T extends object>(queryType: string) {
const { t } = useTranslation();
const pageNavigate = usePageNavigate();

const query = { query: { type: queryType } };

// Filtering by resource id, like host__id=2, instance__id=5, etc.
const params = useParams<{ id: string }>();
if (/^\d+$/.test(params.id)) {
query['query'][`${queryType}__id`] = params.id;
}

return useMemo<IPageAction<T>[]>(() => {
return [
{
type: PageActionType.Button,
selection: PageActionSelection.Single,
icon: HistoryIcon,
label: t('View activity stream'),
onClick: () => pageNavigate(AwxRoute.ActivityStream, { query: { type: queryType } }),
onClick: () => pageNavigate(AwxRoute.ActivityStream, query),
},
{ type: PageActionType.Seperator },
];
}, [pageNavigate, queryType, t]);
}, [pageNavigate, query, t]);
}
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
10 changes: 6 additions & 4 deletions frontend/awx/resources/templates/TemplatePage/TemplatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import { useTemplateActions } from '../hooks/useTemplateActions';

export function TemplatePage() {
const { t } = useTranslation();
const activityStream = useViewActivityStream(
'job_template+workflow_job_template+workflow_job_template_node'
);
const params = useParams<{ id: string }>();
let activityStreamType: string = 'job_template+workflow_job_template+workflow_job_template_node';
if (/^\d+$/.test(params.id)) {
activityStreamType = 'job_template';
}
const activityStream = useViewActivityStream(activityStreamType);

const { activeAwxUser } = useAwxActiveUser();
const params = useParams<{ id: string }>();
const {
error: templateError,
data: template,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import { useTemplateActions } from '../hooks/useTemplateActions';

export function WorkflowJobTemplatePage() {
const { t } = useTranslation();
const activityStream = useViewActivityStream(
'job_template+workflow_job_template+workflow_job_template_node'
);
const params = useParams<{ id: string }>();
let activityStreamType: string = 'job_template+workflow_job_template+workflow_job_template_node';
if (/^\d+$/.test(params.id)) {
activityStreamType = 'workflow_job_template';
}
const activityStream = useViewActivityStream(activityStreamType);
const { activeAwxUser } = useAwxActiveUser();
const {
error: templateError,
Expand Down

0 comments on commit efb9e71

Please sign in to comment.