Skip to content

Commit

Permalink
Add a dropdown to job header to choose job type on relaunch
Browse files Browse the repository at this point in the history
  • Loading branch information
Sasa Jovicic committed Jul 19, 2024
1 parent 4784d51 commit f7cb7b4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions frontend/awx/interfaces/RelaunchConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface JobRelaunch {
hosts?: 'all' | 'failed' | null;
/** Credential passwords */
credential_passwords?: string;
job_type?: 'run' | 'check' | null;
}

export interface InventorySourceUpdate {
Expand Down
5 changes: 4 additions & 1 deletion frontend/awx/views/jobs/JobHeader.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ describe('Job Page', () => {
});
it('Relaunch and cancel buttons are visible on a running job', () => {
cy.mount(<JobHeader />, { 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', () => {
Expand Down
35 changes: 33 additions & 2 deletions frontend/awx/views/jobs/hooks/useRelaunchOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export function useRelaunchOptions(): IPageAction<UnifiedJob>[] {
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(
() => [
{
Expand All @@ -22,9 +24,31 @@ export function useRelaunchOptions(): IPageAction<UnifiedJob>[] {
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,
Expand All @@ -50,6 +74,13 @@ export function useRelaunchOptions(): IPageAction<UnifiedJob>[] {
],
},
],
[t, relaunchAllHosts, relaunchFailedHosts, relaunchJob]
[
t,
relaunchRunJobType,
relaunchCheckJobType,
relaunchAllHosts,
relaunchFailedHosts,
relaunchJob,
]
);
}

0 comments on commit f7cb7b4

Please sign in to comment.