Add job status on expand row for hosts

Add job status on expand row for hosts.

Also, update HostDetail to remove the addition of `type=job` since it is
already present on the API hosts endpoint.

See: https://github.com/ansible/awx/issues/5236
This commit is contained in:
nixocio
2021-06-24 14:30:58 -04:00
parent c09cad3e6d
commit 21de95862e
3 changed files with 81 additions and 50 deletions

View File

@@ -29,7 +29,7 @@ function HostDetail({ host }) {
variables, variables,
summary_fields: { summary_fields: {
inventory, inventory,
recent_jobs, recent_jobs: recentJobs,
created_by, created_by,
modified_by, modified_by,
user_capabilities, user_capabilities,
@@ -66,17 +66,13 @@ function HostDetail({ host }) {
); );
} }
const recentPlaybookJobs = recent_jobs.map(job => ({ ...job, type: 'job' }));
return ( return (
<CardBody> <CardBody>
<HostToggle host={host} css="padding-bottom: 40px" /> <HostToggle host={host} css="padding-bottom: 40px" />
<DetailList gutter="sm"> <DetailList gutter="sm">
<Detail label={t`Name`} value={name} dataCy="host-name" /> <Detail label={t`Name`} value={name} dataCy="host-name" />
{recentPlaybookJobs?.length > 0 && ( {recentJobs?.length > 0 && (
<Detail <Detail label={t`Activity`} value={<Sparkline jobs={recentJobs} />} />
label={t`Activity`}
value={<Sparkline jobs={recentPlaybookJobs} />}
/>
)} )}
<Detail label={t`Description`} value={description} /> <Detail label={t`Description`} value={description} />
<Detail <Detail

View File

@@ -162,7 +162,7 @@ function HostList() {
toolbarSearchableKeys={searchableKeys} toolbarSearchableKeys={searchableKeys}
toolbarRelatedSearchableKeys={relatedSearchableKeys} toolbarRelatedSearchableKeys={relatedSearchableKeys}
headerRow={ headerRow={
<HeaderRow qsConfig={QS_CONFIG}> <HeaderRow qsConfig={QS_CONFIG} isExpandable>
<HeaderCell sortKey="name">{t`Name`}</HeaderCell> <HeaderCell sortKey="name">{t`Name`}</HeaderCell>
<HeaderCell>{t`Inventory`}</HeaderCell> <HeaderCell>{t`Inventory`}</HeaderCell>
<HeaderCell>{t`Actions`}</HeaderCell> <HeaderCell>{t`Actions`}</HeaderCell>

View File

@@ -1,21 +1,36 @@
import 'styled-components/macro'; import 'styled-components/macro';
import React from 'react'; import React, { useState } from 'react';
import { string, bool, func } from 'prop-types'; import { string, bool, func } from 'prop-types';
import { t } from '@lingui/macro'; import { t } from '@lingui/macro';
import { Button } from '@patternfly/react-core'; import { Button } from '@patternfly/react-core';
import { Tr, Td } from '@patternfly/react-table'; import { Tr, Td, ExpandableRowContent } from '@patternfly/react-table';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { PencilAltIcon } from '@patternfly/react-icons'; import { PencilAltIcon } from '@patternfly/react-icons';
import { ActionsTd, ActionItem } from '../../../components/PaginatedTable'; import { ActionsTd, ActionItem } from '../../../components/PaginatedTable';
import { Host } from '../../../types'; import { Host } from '../../../types';
import HostToggle from '../../../components/HostToggle'; import HostToggle from '../../../components/HostToggle';
import { DetailList, Detail } from '../../../components/DetailList';
import Sparkline from '../../../components/Sparkline';
function HostListItem({ host, isSelected, onSelect, detailUrl, rowIndex }) { function HostListItem({ host, isSelected, onSelect, detailUrl, rowIndex }) {
const labelId = `check-action-${host.id}`; const labelId = `check-action-${host.id}`;
const [isExpanded, setIsExpanded] = useState(false);
const {
summary_fields: { recent_jobs: recentJobs = [] },
} = host;
return ( return (
<>
<Tr id={`host-row-${host.id}`}> <Tr id={`host-row-${host.id}`}>
<Td
expand={{
rowIndex,
isExpanded,
onToggle: () => setIsExpanded(!isExpanded),
}}
/>
<Td <Td
data-cy={labelId} data-cy={labelId}
select={{ select={{
@@ -57,6 +72,26 @@ function HostListItem({ host, isSelected, onSelect, detailUrl, rowIndex }) {
</ActionItem> </ActionItem>
</ActionsTd> </ActionsTd>
</Tr> </Tr>
<Tr isExpanded={isExpanded}>
<Td colSpan={2} />
<Td colSpan={4}>
<ExpandableRowContent>
<DetailList gutter="sm">
<Detail
label={t`Activity`}
value={
recentJobs.length > 0 ? (
<Sparkline jobs={recentJobs} />
) : (
t`No job data available`
)
}
/>
</DetailList>
</ExpandableRowContent>
</Td>
</Tr>
</>
); );
} }