From f7cb7b437cc2453268f0e5407f7de5824d488d06 Mon Sep 17 00:00:00 2001 From: Sasa Jovicic Date: Fri, 19 Jul 2024 14:52:26 +0200 Subject: [PATCH] Add a dropdown to job header to choose job type on relaunch --- .../awx/interfaces/RelaunchConfiguration.ts | 1 + frontend/awx/views/jobs/JobHeader.cy.tsx | 5 ++- .../views/jobs/hooks/useRelaunchOptions.tsx | 35 +++++++++++++++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/frontend/awx/interfaces/RelaunchConfiguration.ts b/frontend/awx/interfaces/RelaunchConfiguration.ts index 80df8dd28e..646165b43f 100644 --- a/frontend/awx/interfaces/RelaunchConfiguration.ts +++ b/frontend/awx/interfaces/RelaunchConfiguration.ts @@ -17,6 +17,7 @@ export interface JobRelaunch { hosts?: 'all' | 'failed' | null; /** Credential passwords */ credential_passwords?: string; + job_type?: 'run' | 'check' | null; } export interface InventorySourceUpdate { diff --git a/frontend/awx/views/jobs/JobHeader.cy.tsx b/frontend/awx/views/jobs/JobHeader.cy.tsx index 64fcbe59f3..a4191b1391 100644 --- a/frontend/awx/views/jobs/JobHeader.cy.tsx +++ b/frontend/awx/views/jobs/JobHeader.cy.tsx @@ -14,7 +14,10 @@ describe('Job Page', () => { }); it('Relaunch and cancel buttons are visible on a running job', () => { cy.mount(, { path: ':job_type/:id', initialEntries: ['/workflow/1'] }); - cy.get('[data-cy="relaunch-job"]').should('contain', 'Relaunch job'); + cy.get('[data-cy="relaunch-job-with"]').should('exist'); + cy.get('[data-cy="relaunch-job-with"]').click(); + cy.get('[data-cy="job-type-run"]').should('exist'); + cy.get('[data-cy="job-type-check"]').should('exist'); cy.get('[data-cy="cancel-job"]').should('contain', 'Cancel job'); }); it('Delete button is disabled on a running job', () => { diff --git a/frontend/awx/views/jobs/hooks/useRelaunchOptions.tsx b/frontend/awx/views/jobs/hooks/useRelaunchOptions.tsx index 08e1c93b28..e2d33dab33 100644 --- a/frontend/awx/views/jobs/hooks/useRelaunchOptions.tsx +++ b/frontend/awx/views/jobs/hooks/useRelaunchOptions.tsx @@ -11,6 +11,8 @@ export function useRelaunchOptions(): IPageAction[] { const relaunchJob = useRelaunchJob(); const relaunchAllHosts = useRelaunchJob({ hosts: 'all' }); const relaunchFailedHosts = useRelaunchJob({ hosts: 'failed' }); + const relaunchRunJobType = useRelaunchJob({ job_type: 'run' }); + const relaunchCheckJobType = useRelaunchJob({ job_type: 'check' }); return useMemo( () => [ { @@ -22,9 +24,31 @@ export function useRelaunchOptions(): IPageAction[] { label: t(`Relaunch job`), isHidden: (job: UnifiedJob) => !(job.type !== 'system_job' && job.summary_fields?.user_capabilities?.start) || - (job.status === 'failed' && job.type === 'job'), + job.type === 'job', onClick: (job: UnifiedJob) => void relaunchJob(job), }, + { + type: PageActionType.Dropdown, + selection: PageActionSelection.Single, + isPinned: true, + icon: RocketIcon, + label: t(`Relaunch job with`), + isHidden: (job: UnifiedJob) => job.type !== 'job' || job.status === 'failed', + actions: [ + { + type: PageActionType.Button, + selection: PageActionSelection.Single, + label: t(`Job type run`), + onClick: (job: UnifiedJob) => void relaunchRunJobType(job), + }, + { + type: PageActionType.Button, + selection: PageActionSelection.Single, + label: t(`Job type check`), + onClick: (job: UnifiedJob) => void relaunchCheckJobType(job), + }, + ], + }, { type: PageActionType.Dropdown, selection: PageActionSelection.Single, @@ -50,6 +74,13 @@ export function useRelaunchOptions(): IPageAction[] { ], }, ], - [t, relaunchAllHosts, relaunchFailedHosts, relaunchJob] + [ + t, + relaunchRunJobType, + relaunchCheckJobType, + relaunchAllHosts, + relaunchFailedHosts, + relaunchJob, + ] ); }