-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6058 from marshmalien/5890-jt-completed-jobs-list
Add Completed Job list tab to multiple resources Reviewed-by: Alex Corey <Alex.swansboro@gmail.com> https://github.com/AlexSCorey
- Loading branch information
Showing
22 changed files
with
336 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { withI18n } from '@lingui/react'; | ||
import { t } from '@lingui/macro'; | ||
import { | ||
Button, | ||
DataListAction, | ||
DataListCell, | ||
DataListCheck, | ||
DataListItem, | ||
DataListItemRow, | ||
DataListItemCells, | ||
Tooltip, | ||
} from '@patternfly/react-core'; | ||
import { RocketIcon } from '@patternfly/react-icons'; | ||
import LaunchButton from '@components/LaunchButton'; | ||
import StatusIcon from '@components/StatusIcon'; | ||
import { toTitleCase } from '@util/strings'; | ||
import { formatDateString } from '@util/dates'; | ||
import { JOB_TYPE_URL_SEGMENTS } from '@constants'; | ||
|
||
function JobListItem({ | ||
i18n, | ||
job, | ||
isSelected, | ||
onSelect, | ||
showTypeColumn = false, | ||
}) { | ||
const labelId = `check-action-${job.id}`; | ||
|
||
return ( | ||
<DataListItem aria-labelledby={labelId} id={`${job.id}`}> | ||
<DataListItemRow> | ||
<DataListCheck | ||
id={`select-job-${job.id}`} | ||
checked={isSelected} | ||
onChange={onSelect} | ||
aria-labelledby={labelId} | ||
/> | ||
<DataListItemCells | ||
dataListCells={[ | ||
<DataListCell key="status" isFilled={false}> | ||
{job.status && <StatusIcon status={job.status} />} | ||
</DataListCell>, | ||
<DataListCell key="name"> | ||
<span> | ||
<Link to={`/jobs/${JOB_TYPE_URL_SEGMENTS[job.type]}/${job.id}`}> | ||
<b> | ||
{job.id} — {job.name} | ||
</b> | ||
</Link> | ||
</span> | ||
</DataListCell>, | ||
...(showTypeColumn | ||
? [ | ||
<DataListCell key="type" aria-label="type"> | ||
{toTitleCase(job.type)} | ||
</DataListCell>, | ||
] | ||
: []), | ||
<DataListCell key="finished"> | ||
{formatDateString(job.finished)} | ||
</DataListCell>, | ||
]} | ||
/> | ||
{job.type !== 'system_job' && | ||
job.summary_fields?.user_capabilities?.start && ( | ||
<DataListAction | ||
aria-label="actions" | ||
aria-labelledby={labelId} | ||
id={labelId} | ||
> | ||
<Tooltip content={i18n._(t`Relaunch Job`)} position="top"> | ||
<LaunchButton resource={job}> | ||
{({ handleRelaunch }) => ( | ||
<Button variant="plain" onClick={handleRelaunch}> | ||
<RocketIcon /> | ||
</Button> | ||
)} | ||
</LaunchButton> | ||
</Tooltip> | ||
</DataListAction> | ||
)} | ||
</DataListItemRow> | ||
</DataListItem> | ||
); | ||
} | ||
|
||
export { JobListItem as _JobListItem }; | ||
export default withI18n()(JobListItem); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React from 'react'; | ||
import { createMemoryHistory } from 'history'; | ||
|
||
import { mountWithContexts } from '@testUtils/enzymeHelpers'; | ||
|
||
import JobListItem from './JobListItem'; | ||
|
||
const mockJob = { | ||
id: 123, | ||
type: 'job', | ||
url: '/api/v2/jobs/123/', | ||
summary_fields: { | ||
user_capabilities: { | ||
delete: true, | ||
start: true, | ||
}, | ||
}, | ||
created: '2019-08-08T19:24:05.344276Z', | ||
modified: '2019-08-08T19:24:18.162949Z', | ||
name: 'Demo Job Template', | ||
job_type: 'run', | ||
started: '2019-08-08T19:24:18.329589Z', | ||
finished: '2019-08-08T19:24:50.119995Z', | ||
status: 'successful', | ||
}; | ||
|
||
describe('<JobListItem />', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
const history = createMemoryHistory({ | ||
initialEntries: ['/jobs'], | ||
}); | ||
wrapper = mountWithContexts( | ||
<JobListItem job={mockJob} isSelected onSelect={() => {}} />, | ||
{ context: { router: { history } } } | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
wrapper.unmount(); | ||
}); | ||
|
||
test('initially renders successfully', () => { | ||
expect(wrapper.find('JobListItem').length).toBe(1); | ||
}); | ||
|
||
test('launch button shown to users with launch capabilities', () => { | ||
expect(wrapper.find('LaunchButton').length).toBe(1); | ||
}); | ||
|
||
test('launch button hidden from users without launch capabilities', () => { | ||
wrapper = mountWithContexts( | ||
<JobListItem | ||
job={{ | ||
...mockJob, | ||
summary_fields: { user_capabilities: { start: false } }, | ||
}} | ||
detailUrl={`/jobs/playbook/${mockJob.id}`} | ||
onSelect={() => {}} | ||
isSelected={false} | ||
/> | ||
); | ||
expect(wrapper.find('LaunchButton').length).toBe(0); | ||
}); | ||
|
||
test('should hide type column when showTypeColumn is false', () => { | ||
expect(wrapper.find('DataListCell[aria-label="type"]').length).toBe(0); | ||
}); | ||
|
||
test('should show type column when showTypeColumn is true', () => { | ||
wrapper = mountWithContexts( | ||
<JobListItem | ||
job={mockJob} | ||
showTypeColumn | ||
isSelected | ||
onSelect={() => {}} | ||
/> | ||
); | ||
expect(wrapper.find('DataListCell[aria-label="type"]').length).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './JobList'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
awx/ui_next/src/screens/Host/HostCompletedJobs/HostCompletedJobs.jsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.