Merge pull request #11023 from nixocio/ui_issue_10933

Show button to cancel inventory source sync
This commit is contained in:
Sarah Akus
2021-09-09 14:16:07 -04:00
committed by GitHub
13 changed files with 1969 additions and 1656 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -4,7 +4,7 @@ import { string, bool, func } from 'prop-types';
import { Button, Label } from '@patternfly/react-core'; import { Button, Label } from '@patternfly/react-core';
import { Tr, Td } from '@patternfly/react-table'; import { Tr, Td } from '@patternfly/react-table';
import { PencilAltIcon } from '@patternfly/react-icons'; import { PencilAltIcon } from '@patternfly/react-icons';
import { t } from '@lingui/macro'; import { t, Plural } from '@lingui/macro';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { timeOfDay } from 'util/dates'; import { timeOfDay } from 'util/dates';
import { InventoriesAPI } from 'api'; import { InventoriesAPI } from 'api';
@@ -58,7 +58,13 @@ function InventoryListItem({
let tooltipContent = ''; let tooltipContent = '';
if (inventory.has_inventory_sources) { if (inventory.has_inventory_sources) {
if (inventory.inventory_sources_with_failures > 0) { if (inventory.inventory_sources_with_failures > 0) {
tooltipContent = t`${inventory.inventory_sources_with_failures} sources with sync failures.`; tooltipContent = (
<Plural
value={inventory.inventory_sources_with_failures}
one="# source with sync failures."
other="# sources with sync failures."
/>
);
} else { } else {
tooltipContent = t`No inventory sync failures.`; tooltipContent = t`No inventory sync failures.`;
} }
@@ -95,9 +95,7 @@ describe('<InventoryListItem />', () => {
</table> </table>
); );
expect(wrapper.find('StatusLabel').length).toBe(1); expect(wrapper.find('StatusLabel').length).toBe(1);
expect(wrapper.find('StatusLabel').prop('tooltipContent')).toBe( expect(wrapper.find('StatusLabel').prop('status')).toBe('error');
`${inventory.inventory_sources_with_failures} sources with sync failures.`
);
expect(wrapper.find('Td').at(1).text()).toBe('Inventory'); expect(wrapper.find('Td').at(1).text()).toBe('Inventory');
expect(wrapper.find('Td').at(2).text()).toBe('Error'); expect(wrapper.find('Td').at(2).text()).toBe('Error');
expect(wrapper.find('Td').at(3).text()).toBe('Inventory'); expect(wrapper.find('Td').at(3).text()).toBe('Inventory');
@@ -10,7 +10,7 @@ import {
import styled from 'styled-components'; import styled from 'styled-components';
import { ActionsTd, ActionItem } from 'components/PaginatedTable'; import { ActionsTd, ActionItem } from 'components/PaginatedTable';
import StatusIcon from 'components/StatusIcon'; import StatusLabel from 'components/StatusLabel';
import JobCancelButton from 'components/JobCancelButton'; import JobCancelButton from 'components/JobCancelButton';
import { formatDateString } from 'util/dates'; import { formatDateString } from 'util/dates';
import InventorySourceSyncButton from '../shared/InventorySourceSyncButton'; import InventorySourceSyncButton from '../shared/InventorySourceSyncButton';
@@ -48,6 +48,14 @@ function InventorySourceListItem({
const missingExecutionEnvironment = const missingExecutionEnvironment =
source.custom_virtualenv && !source.execution_environment; source.custom_virtualenv && !source.execution_environment;
let job = null;
if (source.summary_fields?.current_job) {
job = source.summary_fields.current_job;
} else if (source.summary_fields?.last_job) {
job = source.summary_fields.last_job;
}
return ( return (
<> <>
<Tr id={`source-row-${source.id}`}> <Tr id={`source-row-${source.id}`}>
@@ -76,27 +84,27 @@ function InventorySourceListItem({
)} )}
</Td> </Td>
<Td dataLabel={t`Status`}> <Td dataLabel={t`Status`}>
{source.summary_fields.last_job && ( {job && (
<Tooltip <Tooltip
position="top" position="top"
content={generateLastJobTooltip(source.summary_fields.last_job)} content={generateLastJobTooltip(job)}
key={source.summary_fields.last_job.id} key={job.id}
> >
<Link to={`/jobs/inventory/${source.summary_fields.last_job.id}`}> <Link to={`/jobs/inventory/${job.id}`}>
<StatusIcon status={source.summary_fields.last_job.status} /> <StatusLabel status={job.status} />
</Link> </Link>
</Tooltip> </Tooltip>
)} )}
</Td> </Td>
<Td dataLabel={t`Type`}>{label}</Td> <Td dataLabel={t`Type`}>{label}</Td>
<ActionsTd dataLabel={t`Actions`}> <ActionsTd dataLabel={t`Actions`}>
{['running', 'pending', 'waiting'].includes(source?.status) ? ( {['running', 'pending', 'waiting'].includes(job?.status) ? (
<ActionItem visible={source.summary_fields.user_capabilities.start}> <ActionItem visible={source.summary_fields.user_capabilities.start}>
{source.summary_fields?.current_job?.id && ( {source.summary_fields?.current_job?.id && (
<JobCancelButton <JobCancelButton
job={{ job={{
type: 'inventory_update', type: 'inventory_update',
id: source.summary_fields.current_job.id, id: source?.summary_fields?.current_job?.id,
}} }}
errorTitle={t`Inventory Source Sync Error`} errorTitle={t`Inventory Source Sync Error`}
errorMessage={t`Failed to cancel Inventory Source Sync`} errorMessage={t`Failed to cancel Inventory Source Sync`}
@@ -57,7 +57,7 @@ describe('<InventorySourceListItem />', () => {
</tbody> </tbody>
</table> </table>
); );
expect(wrapper.find('StatusIcon').length).toBe(1); expect(wrapper.find('StatusLabel').length).toBe(1);
expect(wrapper.find('Link').at(1).prop('to')).toBe('/jobs/inventory/664'); expect(wrapper.find('Link').at(1).prop('to')).toBe('/jobs/inventory/664');
expect(wrapper.find('.pf-c-table__check').length).toBe(1); expect(wrapper.find('.pf-c-table__check').length).toBe(1);
expect(wrapper.find('Td').at(1).text()).toBe('Foo'); expect(wrapper.find('Td').at(1).text()).toBe('Foo');
@@ -37,7 +37,7 @@ function updateSource(sources, index, message) {
last_updated: message.finished, last_updated: message.finished,
summary_fields: { summary_fields: {
...sources[index].summary_fields, ...sources[index].summary_fields,
last_job: { current_job: {
id: message.unified_job_id, id: message.unified_job_id,
status: message.status, status: message.status,
finished: message.finished, finished: message.finished,
@@ -63,7 +63,7 @@ describe('useWsInventorySources hook', () => {
WS.clean(); WS.clean();
}); });
test('should update last job status', async () => { test('should update current job status', async () => {
global.document.cookie = 'csrftoken=abc123'; global.document.cookie = 'csrftoken=abc123';
const mockServer = new WS('ws://localhost/websocket/'); const mockServer = new WS('ws://localhost/websocket/');
@@ -72,7 +72,7 @@ describe('useWsInventorySources hook', () => {
id: 3, id: 3,
status: 'running', status: 'running',
summary_fields: { summary_fields: {
last_job: { current_job: {
id: 5, id: 5,
status: 'running', status: 'running',
}, },
@@ -112,7 +112,7 @@ describe('useWsInventorySources hook', () => {
status: 'successful', status: 'successful',
last_updated: 'the_time', last_updated: 'the_time',
summary_fields: { summary_fields: {
last_job: { current_job: {
id: 5, id: 5,
status: 'successful', status: 'successful',
finished: 'the_time', finished: 'the_time',