-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #36823 - Create job invocations detail page with main info
- Loading branch information
Showing
10 changed files
with
222 additions
and
0 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
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
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
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
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,21 @@ | ||
import { get } from 'foremanReact/redux/API'; | ||
import { | ||
withInterval, | ||
stopInterval, | ||
} from 'foremanReact/redux/middlewares/IntervalMiddleware'; | ||
import { JOB_INVOCATION_KEY } from './JobInvocationConstants'; | ||
|
||
export const getData = url => dispatch => { | ||
const fetchData = withInterval( | ||
get({ | ||
key: JOB_INVOCATION_KEY, | ||
url, | ||
handleError: () => { | ||
dispatch(stopInterval(JOB_INVOCATION_KEY)); | ||
}, | ||
}), | ||
1000 | ||
); | ||
|
||
dispatch(fetchData); | ||
}; |
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,7 @@ | ||
export const JOB_INVOCATION_KEY = 'JOB_INVOCATION_KEY'; | ||
|
||
export const STATUS = { | ||
PENDING: 'pending', | ||
SUCCEEDED: 'succeeded', | ||
FAILED: 'failed', | ||
}; |
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,93 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
Button, | ||
DescriptionList, | ||
DescriptionListTerm, | ||
DescriptionListGroup, | ||
DescriptionListDescription, | ||
} from '@patternfly/react-core'; | ||
import DefaultLoaderEmptyState from 'foremanReact/components/HostDetails/DetailsCard/DefaultLoaderEmptyState'; | ||
import { translate as __, documentLocale } from 'foremanReact/common/I18n'; | ||
|
||
const JobInvocationOverview = ({ data }) => { | ||
const { | ||
start_at: startAt, | ||
ssh_user: sshUser, | ||
template_id: templateId, | ||
template_name: templateName, | ||
effective_user: effectiveUser, | ||
} = data; | ||
|
||
const dateOptions = { | ||
day: 'numeric', | ||
month: 'short', | ||
year: 'numeric', | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
hour12: false, | ||
timeZoneName: 'short', | ||
}; | ||
const dateConverted = new Date(startAt); | ||
const dateLocaleFormatted = dateConverted | ||
.toLocaleString(documentLocale(), dateOptions) | ||
.replace(/(\d{4}) /, '$1, '); | ||
const dateCurrent = new Date(); | ||
|
||
return ( | ||
<DescriptionList | ||
columnModifier={{ | ||
default: '2Col', | ||
}} | ||
isHorizontal | ||
isCompact | ||
isFluid | ||
isAutoColumnWidths | ||
> | ||
<DescriptionListGroup> | ||
<DescriptionListTerm>{__('Effective user:')}</DescriptionListTerm> | ||
<DescriptionListDescription> | ||
{effectiveUser || <DefaultLoaderEmptyState />} | ||
</DescriptionListDescription> | ||
</DescriptionListGroup> | ||
<DescriptionListGroup> | ||
<DescriptionListTerm>{__('Started at:')}</DescriptionListTerm> | ||
<DescriptionListDescription> | ||
{startAt && dateConverted <= dateCurrent | ||
? dateLocaleFormatted | ||
: __('Not yet')} | ||
</DescriptionListDescription> | ||
</DescriptionListGroup> | ||
<DescriptionListGroup> | ||
<DescriptionListTerm>{__('SSH user:')}</DescriptionListTerm> | ||
<DescriptionListDescription> | ||
{sshUser || <DefaultLoaderEmptyState />} | ||
</DescriptionListDescription> | ||
</DescriptionListGroup> | ||
<DescriptionListGroup> | ||
<DescriptionListTerm>{__('Template:')}</DescriptionListTerm> | ||
<DescriptionListDescription> | ||
{templateName ? ( | ||
<Button | ||
ouiaId="subnet-link" | ||
variant="link" | ||
component="a" | ||
isInline | ||
href={`/job_templates/${templateId}/edit`} | ||
> | ||
{templateName} | ||
</Button> | ||
) : ( | ||
<DefaultLoaderEmptyState /> | ||
)} | ||
</DescriptionListDescription> | ||
</DescriptionListGroup> | ||
</DescriptionList> | ||
); | ||
}; | ||
|
||
JobInvocationOverview.propTypes = { | ||
data: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default JobInvocationOverview; |
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,4 @@ | ||
import { selectAPIResponse } from 'foremanReact/redux/API/APISelectors'; | ||
|
||
export const selectItems = state => | ||
selectAPIResponse(state, 'JOB_INVOCATION_KEY'); |
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,77 @@ | ||
import React, { useEffect } from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import { Divider, PageSection, Flex, FlexItem } from '@patternfly/react-core'; | ||
import { translate as __ } from 'foremanReact/common/I18n'; | ||
import PageLayout from 'foremanReact/routes/common/PageLayout/PageLayout'; | ||
import { stopInterval } from 'foremanReact/redux/middlewares/IntervalMiddleware'; | ||
import { getData } from './JobInvocationActions'; | ||
import { selectItems } from './JobInvocationSelectors'; | ||
import JobInvocationOverview from './JobInvocationOverview'; | ||
import { JOB_INVOCATION_KEY, STATUS } from './JobInvocationConstants'; | ||
|
||
const JobInvocationDetailPage = ({ | ||
match: { | ||
params: { id }, | ||
}, | ||
}) => { | ||
const dispatch = useDispatch(); | ||
const items = useSelector(selectItems); | ||
const { description, status_label: statusLabel, task } = items; | ||
const finished = | ||
statusLabel === STATUS.FAILED || statusLabel === STATUS.SUCCEEDED; | ||
const autoRefresh = task?.state === STATUS.PENDING || false; | ||
|
||
useEffect(() => { | ||
dispatch(getData(`/api/job_invocations/${id}`)); | ||
if (finished && !autoRefresh) { | ||
dispatch(stopInterval(JOB_INVOCATION_KEY)); | ||
} | ||
return () => { | ||
dispatch(stopInterval(JOB_INVOCATION_KEY)); | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [dispatch, id, finished, autoRefresh]); | ||
|
||
const breadcrumbOptions = { | ||
breadcrumbItems: [ | ||
{ caption: __('Jobs'), url: `/job_invocations` }, | ||
{ caption: description }, | ||
], | ||
isPf4: true, | ||
}; | ||
|
||
return ( | ||
<PageLayout | ||
header={description} | ||
breadcrumbOptions={breadcrumbOptions} | ||
searchable={false} | ||
> | ||
<React.Fragment> | ||
<PageSection isFilled variant="light"> | ||
<Flex> | ||
<FlexItem> </FlexItem> | ||
<Divider | ||
orientation={{ | ||
default: 'vertical', | ||
}} | ||
/> | ||
<FlexItem> | ||
<JobInvocationOverview data={items} /> | ||
</FlexItem> | ||
</Flex> | ||
</PageSection> | ||
</React.Fragment> | ||
</PageLayout> | ||
); | ||
}; | ||
|
||
JobInvocationDetailPage.propTypes = { | ||
match: PropTypes.shape({ | ||
params: PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
}), | ||
}).isRequired, | ||
}; | ||
|
||
export default JobInvocationDetailPage; |
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