mirror of
https://github.com/ansible/awx.git
synced 2026-03-19 18:07:33 -02:30
Add support for launching job templates from the templates list (#277)
Add support for launching job templates from the templates list
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
import styled from 'styled-components';
|
||||
|
||||
import VerticalSeparator from '@components/VerticalSeparator';
|
||||
import LaunchButton from '@components/LaunchButton';
|
||||
import { toTitleCase } from '@util/strings';
|
||||
|
||||
const DataListCell = styled(PFDataListCell)`
|
||||
@@ -17,6 +18,7 @@ const DataListCell = styled(PFDataListCell)`
|
||||
align-items: center;
|
||||
@media screen and (min-width: 768px) {
|
||||
padding-bottom: 0;
|
||||
justify-content: ${props => (props.lastcolumn ? 'flex-end' : 'inherit')};
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -27,6 +29,7 @@ class TemplateListItem extends Component {
|
||||
isSelected,
|
||||
onSelect,
|
||||
} = this.props;
|
||||
const canLaunch = template.summary_fields.user_capabilities.start;
|
||||
|
||||
return (
|
||||
<DataListItem
|
||||
@@ -49,7 +52,14 @@ class TemplateListItem extends Component {
|
||||
</Link>
|
||||
</span>
|
||||
</DataListCell>,
|
||||
<DataListCell key="type">{toTitleCase(template.type)}</DataListCell>
|
||||
<DataListCell key="type">{toTitleCase(template.type)}</DataListCell>,
|
||||
<DataListCell lastcolumn="true" key="launch">
|
||||
{canLaunch && template.type === 'job_template' && (
|
||||
<LaunchButton
|
||||
templateId={template.id}
|
||||
/>
|
||||
)}
|
||||
</DataListCell>
|
||||
]}
|
||||
/>
|
||||
</DataListItemRow>
|
||||
|
||||
@@ -5,14 +5,36 @@ import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
import TemplatesListItem from './TemplateListItem';
|
||||
|
||||
describe('<TemplatesListItem />', () => {
|
||||
test('initially render successfully', () => {
|
||||
mountWithContexts(<TemplatesListItem
|
||||
test('launch button shown to users with start capabilities', () => {
|
||||
const wrapper = mountWithContexts(<TemplatesListItem
|
||||
template={{
|
||||
id: 1,
|
||||
name: 'Template 1',
|
||||
url: '/templates/job_template/1',
|
||||
type: 'job_template'
|
||||
type: 'job_template',
|
||||
summary_fields: {
|
||||
user_capabilities: {
|
||||
start: true
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>);
|
||||
expect(wrapper.find('LaunchButton').exists()).toBeTruthy();
|
||||
});
|
||||
test('launch button hidden from users without start capabilities', () => {
|
||||
const wrapper = mountWithContexts(<TemplatesListItem
|
||||
template={{
|
||||
id: 1,
|
||||
name: 'Template 1',
|
||||
url: '/templates/job_template/1',
|
||||
type: 'job_template',
|
||||
summary_fields: {
|
||||
user_capabilities: {
|
||||
start: false
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>);
|
||||
expect(wrapper.find('LaunchButton').exists()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user