Skip to content

Commit 0a17018

Browse files
committed
Fixes #39256 - relying on emptystate page from foreman
1 parent afbb4da commit 0a17018

2 files changed

Lines changed: 32 additions & 73 deletions

File tree

webpack/JobInvocationDetail/JobInvocationEmptyState.js

Lines changed: 28 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,36 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
3-
import { useHistory } from 'react-router-dom';
4-
import {
5-
Button,
6-
EmptyStateVariant,
7-
PageSection,
8-
PageSectionVariants,
9-
} from '@patternfly/react-core';
10-
import { SearchIcon } from '@patternfly/react-icons';
11-
import { translate as __, sprintf } from 'foremanReact/common/I18n';
12-
import { foremanUrl } from 'foremanReact/common/helpers';
13-
import EmptyStatePattern from 'foremanReact/components/common/EmptyState/EmptyStatePattern';
3+
import { PageSection, PageSectionVariants } from '@patternfly/react-core';
4+
import { translate as __ } from 'foremanReact/common/I18n';
5+
import { foremanUrl, visit } from 'foremanReact/common/helpers';
6+
import ResourceLoadFailedEmptyState from 'foremanReact/components/common/EmptyState/ResourceLoadFailedEmptyState';
147

158
const jobInvocationsIndexPath = '/job_invocations';
169

17-
const JobInvocationEmptyState = ({ jobInvocationId, errorMessage = null }) => {
18-
const history = useHistory();
19-
20-
const descriptionContent = (
21-
<>
22-
<p>
23-
{sprintf(
24-
__(
25-
'There is no job invocation with id %s or there are access permissions needed. Opening this page requires the view_job_invocations permission. Please contact your administrator if this issue continues.'
26-
),
27-
jobInvocationId
28-
)}
29-
</p>
30-
{errorMessage ? (
31-
<p className="pf-v5-u-text-break" style={{ whiteSpace: 'pre-wrap' }}>
32-
{sprintf(__('The server returned: %s'), errorMessage)}
33-
</p>
34-
) : null}
35-
</>
36-
);
37-
38-
return (
39-
<PageSection variant={PageSectionVariants.light}>
40-
<EmptyStatePattern
41-
variant={EmptyStateVariant.lg}
42-
icon={<SearchIcon />}
43-
header={__('Job invocation not found')}
44-
description={descriptionContent}
45-
action={
46-
<Button
47-
ouiaId="job-invocation-empty-state-go-to-job-invocations-button"
48-
variant="primary"
49-
component="a"
50-
href={foremanUrl(jobInvocationsIndexPath)}
51-
isInline
52-
>
53-
{__('Go to job invocations')}
54-
</Button>
55-
}
56-
secondaryActions={
57-
<>
58-
<Button
59-
ouiaId="job-invocation-empty-state-create-new-job-invocation-button"
60-
variant="link"
61-
component="a"
62-
href={foremanUrl('/job_invocations/new')}
63-
>
64-
{__('Create a new job invocation')}
65-
</Button>
66-
<Button
67-
ouiaId="job-invocation-empty-state-return-to-last-page-button"
68-
variant="link"
69-
onClick={() => history.goBack()}
70-
>
71-
{__('Return to the last page')}
72-
</Button>
73-
</>
74-
}
75-
/>
76-
</PageSection>
77-
);
78-
};
10+
const JobInvocationEmptyState = ({ jobInvocationId, errorMessage }) => (
11+
<PageSection variant={PageSectionVariants.light}>
12+
<ResourceLoadFailedEmptyState
13+
resourceLabel={__('job invocation')}
14+
resourceId={jobInvocationId}
15+
errorMessage={errorMessage}
16+
requiredPermissions={['view_job_invocations']}
17+
primaryAction={{
18+
label: __('Go to job invocations'),
19+
onClick: () => visit(foremanUrl(jobInvocationsIndexPath)),
20+
ouiaId: 'job-invocation-empty-state-go-to-job-invocations-button',
21+
}}
22+
secondaryActions={[
23+
{
24+
label: __('Create a new job invocation'),
25+
onClick: () => visit(foremanUrl('/job_invocations/new')),
26+
ouiaId: 'job-invocation-empty-state-create-new-job-invocation-button',
27+
},
28+
]}
29+
backButtonLabel={__('Return to the last page')}
30+
ouiaIdPrefix="job-invocation-empty-state"
31+
/>
32+
</PageSection>
33+
);
7934

8035
JobInvocationEmptyState.propTypes = {
8136
jobInvocationId: PropTypes.string.isRequired,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
export const foremanUrl = path => `foreman${path}`;
2+
3+
export const visit = jest.fn(url => {
4+
global.window.location.href = url;
5+
});

0 commit comments

Comments
 (0)