Merge pull request #10417 from mabashian/10411-inv-src-sync-details

Fixes bug where source list page would crash if first sync was running

SUMMARY
link #10411
The ID being passed to the cancel button was incorrect as well.  We want to reference current_job not last_job.

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

UI

Reviewed-by: Jake McDermott <yo@jakemcdermott.me>
Reviewed-by: Kersom <None>
Reviewed-by: Sarah Akus <sarah.akus@gmail.com>
This commit is contained in:
softwarefactory-project-zuul[bot] 2021-06-11 20:33:33 +00:00 committed by GitHub
commit 8a6656aa90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 13 deletions

View File

@ -25,8 +25,7 @@ import InventorySourceListItem from './InventorySourceListItem';
import useWsInventorySources from './useWsInventorySources';
import { relatedResourceDeleteRequests } from '../../../util/getRelatedResourceDeleteDetails';
const QS_CONFIG = getQSConfig('inventory', {
not__source: '',
const QS_CONFIG = getQSConfig('inventory-sources', {
page: 1,
page_size: 20,
order_by: 'name',

View File

@ -115,7 +115,6 @@ describe('<InventorySourceList />', () => {
test('api calls should be made on mount', async () => {
expect(InventoriesAPI.readSources).toHaveBeenCalledWith('1', {
not__source: '',
order_by: 'name',
page: 1,
page_size: 20,

View File

@ -94,16 +94,18 @@ function InventorySourceListItem({
<ActionsTd dataLabel={t`Actions`}>
{['running', 'pending', 'waiting'].includes(source?.status) ? (
<ActionItem visible={source.summary_fields.user_capabilities.start}>
<JobCancelButton
job={{
type: 'inventory_update',
id: source.summary_fields.last_job.id,
}}
errorTitle={t`Inventory Source Sync Error`}
errorMessage={t`Failed to cancel Inventory Source Sync`}
title={t`Cancel Inventory Source Sync`}
showIconButton
/>
{source.summary_fields?.current_job?.id && (
<JobCancelButton
job={{
type: 'inventory_update',
id: source.summary_fields.current_job.id,
}}
errorTitle={t`Inventory Source Sync Error`}
errorMessage={t`Failed to cancel Inventory Source Sync`}
title={t`Cancel Inventory Source Sync`}
showIconButton
/>
)}
</ActionItem>
) : (
<ActionItem

View File

@ -198,4 +198,33 @@ describe('<InventorySourceListItem />', () => {
'Custom virtual environment /var/lib/awx/env must be replaced by an execution environment.'
);
});
test('should render cancel button while job is running', () => {
const onSelect = jest.fn();
wrapper = mountWithContexts(
<table>
<tbody>
<InventorySourceListItem
source={{
...source,
status: 'running',
summary_fields: {
...source.summary_fields,
current_job: {
id: 1000,
status: 'running',
},
},
custom_virtualenv: '/var/lib/awx/env',
execution_environment: null,
}}
isSelected={false}
onSelect={onSelect}
label="Source Bar"
/>
</tbody>
</table>
);
expect(wrapper.find('JobCancelButton').length).toBe(1);
});
});