From efb9e71ec61d79c4e2c028cadff380b4e946599a Mon Sep 17 00:00:00 2001 From: Adrian Nackov Date: Thu, 11 Jul 2024 11:36:19 +0000 Subject: [PATCH] fix ActivityStream button at details page Signed-off-by: Adrian Nackov --- .../awx/access/common/useViewActivityStream.tsx | 14 ++++++++++++-- frontend/awx/common/useAwxView.tsx | 7 +++++++ .../templates/TemplatePage/TemplatePage.tsx | 10 ++++++---- .../WorkflowJobTemplatePage.tsx | 8 +++++--- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/frontend/awx/access/common/useViewActivityStream.tsx b/frontend/awx/access/common/useViewActivityStream.tsx index a5e2982232..8e3994f81c 100644 --- a/frontend/awx/access/common/useViewActivityStream.tsx +++ b/frontend/awx/access/common/useViewActivityStream.tsx @@ -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, @@ -11,6 +12,15 @@ import { AwxRoute } from '../../main/AwxRoutes'; export function useViewActivityStream(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[]>(() => { return [ { @@ -18,9 +28,9 @@ export function useViewActivityStream(queryType: string) { 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]); } diff --git a/frontend/awx/common/useAwxView.tsx b/frontend/awx/common/useAwxView.tsx index 15c6519e90..96ef13b2d4 100644 --- a/frontend/awx/common/useAwxView.tsx +++ b/frontend/awx/common/useAwxView.tsx @@ -107,6 +107,13 @@ export function useAwxView(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 { diff --git a/frontend/awx/resources/templates/TemplatePage/TemplatePage.tsx b/frontend/awx/resources/templates/TemplatePage/TemplatePage.tsx index 1816362ecd..8906c4b685 100644 --- a/frontend/awx/resources/templates/TemplatePage/TemplatePage.tsx +++ b/frontend/awx/resources/templates/TemplatePage/TemplatePage.tsx @@ -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, diff --git a/frontend/awx/resources/templates/WorkflowJobTemplatePage/WorkflowJobTemplatePage.tsx b/frontend/awx/resources/templates/WorkflowJobTemplatePage/WorkflowJobTemplatePage.tsx index 06b66fab44..96fbf9f043 100644 --- a/frontend/awx/resources/templates/WorkflowJobTemplatePage/WorkflowJobTemplatePage.tsx +++ b/frontend/awx/resources/templates/WorkflowJobTemplatePage/WorkflowJobTemplatePage.tsx @@ -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,