mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 18:09:57 -03:30
remove NotFoundError and use ContentError instead
This commit is contained in:
parent
db1dddb95e
commit
eeb86b3105
@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import { t } from '@lingui/macro';
|
||||
import styled from 'styled-components';
|
||||
import { bool, instanceOf } from 'prop-types';
|
||||
import { t } from '@lingui/macro';
|
||||
import { withI18n } from '@lingui/react';
|
||||
import {
|
||||
Title,
|
||||
@ -11,7 +12,6 @@ import {
|
||||
import { ExclamationTriangleIcon } from '@patternfly/react-icons';
|
||||
import { RootAPI } from '@api';
|
||||
import ErrorDetail from '@components/ErrorDetail';
|
||||
import NotFoundError from './NotFoundError';
|
||||
|
||||
const EmptyState = styled(PFEmptyState)`
|
||||
width: var(--pf-c-empty-state--m-lg--MaxWidth);
|
||||
@ -22,33 +22,41 @@ async function logout() {
|
||||
window.location.replace('/#/login');
|
||||
}
|
||||
|
||||
class ContentError extends React.Component {
|
||||
render() {
|
||||
const { error, children, i18n } = this.props;
|
||||
if (error && error.response && error.response.status === 401) {
|
||||
if (!error.response.headers['session-timeout']) {
|
||||
logout();
|
||||
return null;
|
||||
}
|
||||
function ContentError({ error, children, isNotFound, i18n }) {
|
||||
if (error && error.response && error.response.status === 401) {
|
||||
if (!error.response.headers['session-timeout']) {
|
||||
logout();
|
||||
return null;
|
||||
}
|
||||
if (error && error.response && error.response.status === 404) {
|
||||
return <NotFoundError error={error}>{children}</NotFoundError>;
|
||||
}
|
||||
return (
|
||||
<EmptyState>
|
||||
<EmptyStateIcon icon={ExclamationTriangleIcon} />
|
||||
<Title size="lg">{i18n._(t`Something went wrong...`)}</Title>
|
||||
<EmptyStateBody>
|
||||
{children ||
|
||||
i18n._(
|
||||
}
|
||||
const is404 =
|
||||
isNotFound || (error && error.response && error.response.status === 404);
|
||||
return (
|
||||
<EmptyState>
|
||||
<EmptyStateIcon icon={ExclamationTriangleIcon} />
|
||||
<Title size="lg">
|
||||
{is404 ? i18n._(t`Not Found`) : i18n._(t`Something went wrong...`)}
|
||||
</Title>
|
||||
<EmptyStateBody>
|
||||
{is404
|
||||
? i18n._(t`The page you requested could not be found.`)
|
||||
: i18n._(
|
||||
t`There was an error loading this content. Please reload the page.`
|
||||
)}
|
||||
</EmptyStateBody>
|
||||
{error && <ErrorDetail error={error} />}
|
||||
</EmptyState>
|
||||
);
|
||||
}
|
||||
{children}
|
||||
</EmptyStateBody>
|
||||
{error && <ErrorDetail error={error} />}
|
||||
</EmptyState>
|
||||
);
|
||||
}
|
||||
ContentError.propTypes = {
|
||||
error: instanceOf(Error),
|
||||
isNotFound: bool,
|
||||
};
|
||||
ContentError.defaultProps = {
|
||||
error: null,
|
||||
isNotFound: false,
|
||||
};
|
||||
|
||||
export { ContentError as _ContentError };
|
||||
export default withI18n()(ContentError);
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
import React from 'react';
|
||||
import { t } from '@lingui/macro';
|
||||
import styled from 'styled-components';
|
||||
import { withI18n } from '@lingui/react';
|
||||
import {
|
||||
Title,
|
||||
EmptyState as PFEmptyState,
|
||||
EmptyStateIcon,
|
||||
EmptyStateBody,
|
||||
} from '@patternfly/react-core';
|
||||
import { ExclamationTriangleIcon } from '@patternfly/react-icons';
|
||||
import ErrorDetail from '@components/ErrorDetail';
|
||||
|
||||
const EmptyState = styled(PFEmptyState)`
|
||||
width: var(--pf-c-empty-state--m-lg--MaxWidth);
|
||||
`;
|
||||
|
||||
function NotFoundError({ i18n, error, children }) {
|
||||
return (
|
||||
<EmptyState>
|
||||
<EmptyStateIcon icon={ExclamationTriangleIcon} />
|
||||
<Title size="lg">{i18n._(t`Not Found`)}</Title>
|
||||
<EmptyStateBody>
|
||||
{children || i18n._(`The page you requested could not be found.`)}
|
||||
</EmptyStateBody>
|
||||
{error && <ErrorDetail error={error} />}
|
||||
</EmptyState>
|
||||
);
|
||||
}
|
||||
|
||||
export { NotFoundError as _NotFoundError };
|
||||
export default withI18n()(NotFoundError);
|
||||
@ -1,2 +1 @@
|
||||
export { default } from './ContentError';
|
||||
export { default as NotFoundError } from './NotFoundError';
|
||||
|
||||
@ -9,7 +9,7 @@ import {
|
||||
PageSection,
|
||||
} from '@patternfly/react-core';
|
||||
import { JobsAPI } from '@api';
|
||||
import ContentError, { NotFoundError } from '@components/ContentError';
|
||||
import ContentError from '@components/ContentError';
|
||||
import CardCloseButton from '@components/CardCloseButton';
|
||||
import RoutedTabs from '@components/RoutedTabs';
|
||||
|
||||
@ -150,14 +150,13 @@ class Job extends Component {
|
||||
key="not-found"
|
||||
path="*"
|
||||
render={() => (
|
||||
<NotFoundError>
|
||||
{i18n._(`The page you requested could not be found.`)}{' '}
|
||||
<ContentError isNotFound>
|
||||
<Link
|
||||
to={`/jobs/${match.params.type}/${match.params.id}/details`}
|
||||
>
|
||||
{i18n._(`View Job Details`)}
|
||||
</Link>
|
||||
</NotFoundError>
|
||||
</ContentError>
|
||||
)}
|
||||
/>,
|
||||
]}
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import React, { Component } from 'react';
|
||||
import { Redirect, Link } from 'react-router-dom';
|
||||
import { PageSection, Card } from '@patternfly/react-core';
|
||||
import { withI18n } from '@lingui/react';
|
||||
import { UnifiedJobsAPI } from '@api';
|
||||
import ContentError, { NotFoundError } from '@components/ContentError';
|
||||
import ContentError from '@components/ContentError';
|
||||
import { JOB_TYPE_URL_SEGMENTS } from '../../constants';
|
||||
|
||||
const NOT_FOUND = 'not found';
|
||||
@ -47,7 +48,7 @@ class JobTypeRedirect extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { path, view } = this.props;
|
||||
const { path, view, i18n } = this.props;
|
||||
const { error, job, isLoading } = this.state;
|
||||
|
||||
if (error) {
|
||||
@ -55,10 +56,9 @@ class JobTypeRedirect extends Component {
|
||||
<PageSection>
|
||||
<Card className="awx-c-card">
|
||||
{error === NOT_FOUND ? (
|
||||
<NotFoundError>
|
||||
The requested job could not be found.{' '}
|
||||
<Link to="/jobs">View all Jobs.</Link>
|
||||
</NotFoundError>
|
||||
<ContentError isNotFound>
|
||||
<Link to="/jobs">{i18n._(`View all Jobs`)}</Link>
|
||||
</ContentError>
|
||||
) : (
|
||||
<ContentError error={error} />
|
||||
)}
|
||||
@ -75,4 +75,4 @@ class JobTypeRedirect extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
export default JobTypeRedirect;
|
||||
export default withI18n()(JobTypeRedirect);
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import React from 'react';
|
||||
import { PageSection, Card } from '@patternfly/react-core';
|
||||
import { NotFoundError } from '@components/ContentError';
|
||||
import ContentError from '@components/ContentError';
|
||||
|
||||
function NotFound() {
|
||||
return (
|
||||
<PageSection>
|
||||
<Card className="awx-c-card">
|
||||
<NotFoundError />
|
||||
<ContentError isNotFound />
|
||||
</Card>
|
||||
</PageSection>
|
||||
);
|
||||
|
||||
@ -10,7 +10,7 @@ import {
|
||||
import styled from 'styled-components';
|
||||
import CardCloseButton from '@components/CardCloseButton';
|
||||
import RoutedTabs from '@components/RoutedTabs';
|
||||
import ContentError, { NotFoundError } from '@components/ContentError';
|
||||
import ContentError from '@components/ContentError';
|
||||
import { OrganizationAccess } from './OrganizationAccess';
|
||||
import OrganizationDetail from './OrganizationDetail';
|
||||
import OrganizationEdit from './OrganizationEdit';
|
||||
@ -239,14 +239,13 @@ class Organization extends Component {
|
||||
key="not-found"
|
||||
path="*"
|
||||
render={() => (
|
||||
<NotFoundError>
|
||||
{i18n._(`The page you requested could not be found.`)}{' '}
|
||||
<ContentError isNotFound>
|
||||
{match.params.id && (
|
||||
<Link to={`/organizations/${match.params.id}/details`}>
|
||||
{i18n._(`View Organization Details`)}
|
||||
</Link>
|
||||
)}
|
||||
</NotFoundError>
|
||||
</ContentError>
|
||||
)}
|
||||
/>
|
||||
,
|
||||
|
||||
@ -4,7 +4,7 @@ import { withI18n } from '@lingui/react';
|
||||
import { Card, CardHeader, PageSection } from '@patternfly/react-core';
|
||||
import { Switch, Route, Redirect, withRouter, Link } from 'react-router-dom';
|
||||
import CardCloseButton from '@components/CardCloseButton';
|
||||
import ContentError, { NotFoundError } from '@components/ContentError';
|
||||
import ContentError from '@components/ContentError';
|
||||
import RoutedTabs from '@components/RoutedTabs';
|
||||
import JobTemplateDetail from './JobTemplateDetail';
|
||||
import { JobTemplatesAPI } from '@api';
|
||||
@ -120,8 +120,7 @@ class Template extends Component {
|
||||
key="not-found"
|
||||
path="*"
|
||||
render={() => (
|
||||
<NotFoundError>
|
||||
{i18n._(`The page you requested could not be found.`)}{' '}
|
||||
<ContentError isNotFound>
|
||||
{match.params.id && (
|
||||
<Link
|
||||
to={`/templates/${match.params.templateType}/${match.params.id}/details`}
|
||||
@ -129,7 +128,7 @@ class Template extends Component {
|
||||
{i18n._(`View Template Details`)}
|
||||
</Link>
|
||||
)}
|
||||
</NotFoundError>
|
||||
</ContentError>
|
||||
)}
|
||||
/>,
|
||||
]}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user