mirror of
https://github.com/ansible/awx.git
synced 2026-03-18 17:37:30 -02:30
Merge pull request #4435 from keithjgrant/4244-not-found-route
Add NotFound route handling Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { t } from '@lingui/macro';
|
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import { bool, instanceOf } from 'prop-types';
|
||||||
|
import { t } from '@lingui/macro';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import {
|
import {
|
||||||
Title,
|
Title,
|
||||||
@@ -9,30 +11,53 @@ import {
|
|||||||
EmptyStateBody,
|
EmptyStateBody,
|
||||||
} from '@patternfly/react-core';
|
} from '@patternfly/react-core';
|
||||||
import { ExclamationTriangleIcon } from '@patternfly/react-icons';
|
import { ExclamationTriangleIcon } from '@patternfly/react-icons';
|
||||||
|
import { RootAPI } from '@api';
|
||||||
import ErrorDetail from '@components/ErrorDetail';
|
import ErrorDetail from '@components/ErrorDetail';
|
||||||
|
|
||||||
const EmptyState = styled(PFEmptyState)`
|
const EmptyState = styled(PFEmptyState)`
|
||||||
width: var(--pf-c-empty-state--m-lg--MaxWidth);
|
width: var(--pf-c-empty-state--m-lg--MaxWidth);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
class ContentError extends React.Component {
|
async function logout() {
|
||||||
render() {
|
await RootAPI.logout();
|
||||||
const { error, i18n } = this.props;
|
window.location.replace('/#/login');
|
||||||
return (
|
|
||||||
<EmptyState>
|
|
||||||
<EmptyStateIcon icon={ExclamationTriangleIcon} />
|
|
||||||
<Title size="lg">{i18n._(t`Something went wrong...`)}</Title>
|
|
||||||
<EmptyStateBody>
|
|
||||||
{i18n._(
|
|
||||||
t`There was an error loading this content. Please reload the page.`
|
|
||||||
)}
|
|
||||||
</EmptyStateBody>
|
|
||||||
{error && <ErrorDetail error={error} />}
|
|
||||||
</EmptyState>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ContentError({ error, children, isNotFound, i18n }) {
|
||||||
|
if (error && error.response && error.response.status === 401) {
|
||||||
|
if (!error.response.headers['session-timeout']) {
|
||||||
|
logout();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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.`
|
||||||
|
)}{' '}
|
||||||
|
{children || <Link to="/home">{i18n._(t`Back to Dashboard.`)}</Link>}
|
||||||
|
</EmptyStateBody>
|
||||||
|
{error && <ErrorDetail error={error} />}
|
||||||
|
</EmptyState>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ContentError.propTypes = {
|
||||||
|
error: instanceOf(Error),
|
||||||
|
isNotFound: bool,
|
||||||
|
};
|
||||||
|
ContentError.defaultProps = {
|
||||||
|
error: null,
|
||||||
|
isNotFound: false,
|
||||||
|
};
|
||||||
|
|
||||||
export { ContentError as _ContentError };
|
export { ContentError as _ContentError };
|
||||||
export default withI18n()(ContentError);
|
export default withI18n()(ContentError);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import License from '@screens/License';
|
|||||||
import Teams from '@screens/Team';
|
import Teams from '@screens/Team';
|
||||||
import Templates from '@screens/Template';
|
import Templates from '@screens/Template';
|
||||||
import Users from '@screens/User';
|
import Users from '@screens/User';
|
||||||
|
import NotFound from '@screens/NotFound';
|
||||||
|
|
||||||
import App from './App';
|
import App from './App';
|
||||||
import RootProvider from './RootProvider';
|
import RootProvider from './RootProvider';
|
||||||
@@ -224,8 +225,8 @@ export function main(render) {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
render={({ routeGroups }) =>
|
render={({ routeGroups }) => {
|
||||||
routeGroups
|
const routeList = routeGroups
|
||||||
.reduce(
|
.reduce(
|
||||||
(allRoutes, { routes }) => allRoutes.concat(routes),
|
(allRoutes, { routes }) => allRoutes.concat(routes),
|
||||||
[]
|
[]
|
||||||
@@ -238,8 +239,16 @@ export function main(render) {
|
|||||||
<PageComponent match={match} />
|
<PageComponent match={match} />
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
))
|
));
|
||||||
}
|
routeList.push(
|
||||||
|
<Route
|
||||||
|
key="not-found"
|
||||||
|
path="*"
|
||||||
|
component={NotFound}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
return <Switch>{routeList}</Switch>;
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { Route, withRouter, Switch, Redirect } from 'react-router-dom';
|
import { Route, withRouter, Switch, Redirect, Link } from 'react-router-dom';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
@@ -99,7 +99,14 @@ class Job extends Component {
|
|||||||
return (
|
return (
|
||||||
<PageSection>
|
<PageSection>
|
||||||
<Card className="awx-c-card">
|
<Card className="awx-c-card">
|
||||||
<ContentError error={contentError} />
|
<ContentError error={contentError}>
|
||||||
|
{contentError.response.status === 404 && (
|
||||||
|
<span>
|
||||||
|
{i18n._(`The page you requested could not be found.`)}{' '}
|
||||||
|
<Link to="/jobs">{i18n._(`View all Jobs.`)}</Link>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</ContentError>
|
||||||
</Card>
|
</Card>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
);
|
);
|
||||||
@@ -139,6 +146,19 @@ class Job extends Component {
|
|||||||
path="/jobs/:type/:id/output"
|
path="/jobs/:type/:id/output"
|
||||||
render={() => <JobOutput type={match.params.type} job={job} />}
|
render={() => <JobOutput type={match.params.type} job={job} />}
|
||||||
/>,
|
/>,
|
||||||
|
<Route
|
||||||
|
key="not-found"
|
||||||
|
path="*"
|
||||||
|
render={() => (
|
||||||
|
<ContentError isNotFound>
|
||||||
|
<Link
|
||||||
|
to={`/jobs/${match.params.type}/${match.params.id}/details`}
|
||||||
|
>
|
||||||
|
{i18n._(`View Job Details`)}
|
||||||
|
</Link>
|
||||||
|
</ContentError>
|
||||||
|
)}
|
||||||
|
/>,
|
||||||
]}
|
]}
|
||||||
</Switch>
|
</Switch>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { Redirect } from 'react-router-dom';
|
import { Redirect, Link } from 'react-router-dom';
|
||||||
|
import { PageSection, Card } from '@patternfly/react-core';
|
||||||
|
import { withI18n } from '@lingui/react';
|
||||||
import { UnifiedJobsAPI } from '@api';
|
import { UnifiedJobsAPI } from '@api';
|
||||||
|
import ContentError from '@components/ContentError';
|
||||||
import { JOB_TYPE_URL_SEGMENTS } from '../../constants';
|
import { JOB_TYPE_URL_SEGMENTS } from '../../constants';
|
||||||
|
|
||||||
|
const NOT_FOUND = 'not found';
|
||||||
|
|
||||||
class JobTypeRedirect extends Component {
|
class JobTypeRedirect extends Component {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
view: 'details',
|
view: 'details',
|
||||||
@@ -12,8 +17,9 @@ class JobTypeRedirect extends Component {
|
|||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
hasError: false,
|
error: null,
|
||||||
job: null,
|
job: null,
|
||||||
|
isLoading: true,
|
||||||
};
|
};
|
||||||
this.loadJob = this.loadJob.bind(this);
|
this.loadJob = this.loadJob.bind(this);
|
||||||
}
|
}
|
||||||
@@ -24,24 +30,44 @@ class JobTypeRedirect extends Component {
|
|||||||
|
|
||||||
async loadJob() {
|
async loadJob() {
|
||||||
const { id } = this.props;
|
const { id } = this.props;
|
||||||
|
this.setState({ isLoading: true });
|
||||||
try {
|
try {
|
||||||
const { data } = await UnifiedJobsAPI.read({ id });
|
const { data } = await UnifiedJobsAPI.read({ id });
|
||||||
|
const job = data.results[0];
|
||||||
this.setState({
|
this.setState({
|
||||||
job: data.results[0],
|
job,
|
||||||
|
isLoading: false,
|
||||||
|
error: job ? null : NOT_FOUND,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
this.setState({
|
||||||
|
error,
|
||||||
|
isLoading: false,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
|
||||||
this.setState({ hasError: true });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { path, view } = this.props;
|
const { path, view, i18n } = this.props;
|
||||||
const { hasError, job } = this.state;
|
const { error, job, isLoading } = this.state;
|
||||||
|
|
||||||
if (hasError) {
|
if (error) {
|
||||||
return <div>Error</div>;
|
return (
|
||||||
|
<PageSection>
|
||||||
|
<Card className="awx-c-card">
|
||||||
|
{error === NOT_FOUND ? (
|
||||||
|
<ContentError isNotFound>
|
||||||
|
<Link to="/jobs">{i18n._(`View all Jobs`)}</Link>
|
||||||
|
</ContentError>
|
||||||
|
) : (
|
||||||
|
<ContentError error={error} />
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
</PageSection>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (!job) {
|
if (isLoading) {
|
||||||
|
// TODO show loading state
|
||||||
return <div>Loading...</div>;
|
return <div>Loading...</div>;
|
||||||
}
|
}
|
||||||
const type = JOB_TYPE_URL_SEGMENTS[job.type];
|
const type = JOB_TYPE_URL_SEGMENTS[job.type];
|
||||||
@@ -49,4 +75,4 @@ class JobTypeRedirect extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default JobTypeRedirect;
|
export default withI18n()(JobTypeRedirect);
|
||||||
|
|||||||
15
awx/ui_next/src/screens/NotFound.jsx
Normal file
15
awx/ui_next/src/screens/NotFound.jsx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { PageSection, Card } from '@patternfly/react-core';
|
||||||
|
import ContentError from '@components/ContentError';
|
||||||
|
|
||||||
|
function NotFound() {
|
||||||
|
return (
|
||||||
|
<PageSection>
|
||||||
|
<Card className="awx-c-card">
|
||||||
|
<ContentError isNotFound />
|
||||||
|
</Card>
|
||||||
|
</PageSection>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NotFound;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { Switch, Route, withRouter, Redirect } from 'react-router-dom';
|
import { Switch, Route, withRouter, Redirect, Link } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardHeader as PFCardHeader,
|
CardHeader as PFCardHeader,
|
||||||
@@ -168,7 +168,16 @@ class Organization extends Component {
|
|||||||
return (
|
return (
|
||||||
<PageSection>
|
<PageSection>
|
||||||
<Card className="awx-c-card">
|
<Card className="awx-c-card">
|
||||||
<ContentError error={contentError} />
|
<ContentError error={contentError}>
|
||||||
|
{contentError.response.status === 404 && (
|
||||||
|
<span>
|
||||||
|
{i18n._(`Organization not found.`)}{' '}
|
||||||
|
<Link to="/organizations">
|
||||||
|
{i18n._(`View all Organizations.`)}
|
||||||
|
</Link>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</ContentError>
|
||||||
</Card>
|
</Card>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
);
|
);
|
||||||
@@ -226,6 +235,20 @@ class Organization extends Component {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
<Route
|
||||||
|
key="not-found"
|
||||||
|
path="*"
|
||||||
|
render={() => (
|
||||||
|
<ContentError isNotFound>
|
||||||
|
{match.params.id && (
|
||||||
|
<Link to={`/organizations/${match.params.id}/details`}>
|
||||||
|
{i18n._(`View Organization Details`)}
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</ContentError>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
,
|
||||||
</Switch>
|
</Switch>
|
||||||
</Card>
|
</Card>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ class OrganizationsList extends Component {
|
|||||||
<PageSection variant={medium}>
|
<PageSection variant={medium}>
|
||||||
<Card>
|
<Card>
|
||||||
<PaginatedDataList
|
<PaginatedDataList
|
||||||
error={contentError}
|
contentError={contentError}
|
||||||
hasContentLoading={hasContentLoading}
|
hasContentLoading={hasContentLoading}
|
||||||
items={organizations}
|
items={organizations}
|
||||||
itemCount={itemCount}
|
itemCount={itemCount}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React, { Component } from 'react';
|
|||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { Card, CardHeader, PageSection } from '@patternfly/react-core';
|
import { Card, CardHeader, PageSection } from '@patternfly/react-core';
|
||||||
import { Switch, Route, Redirect, withRouter } from 'react-router-dom';
|
import { Switch, Route, Redirect, withRouter, Link } from 'react-router-dom';
|
||||||
import CardCloseButton from '@components/CardCloseButton';
|
import CardCloseButton from '@components/CardCloseButton';
|
||||||
import ContentError from '@components/ContentError';
|
import ContentError from '@components/ContentError';
|
||||||
import RoutedTabs from '@components/RoutedTabs';
|
import RoutedTabs from '@components/RoutedTabs';
|
||||||
@@ -77,7 +77,14 @@ class Template extends Component {
|
|||||||
return (
|
return (
|
||||||
<PageSection>
|
<PageSection>
|
||||||
<Card className="awx-c-card">
|
<Card className="awx-c-card">
|
||||||
<ContentError error={contentError} />
|
<ContentError error={contentError}>
|
||||||
|
{contentError.response.status === 404 && (
|
||||||
|
<span>
|
||||||
|
{i18n._(`Template not found.`)}{' '}
|
||||||
|
<Link to="/templates">{i18n._(`View all Templates.`)}</Link>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</ContentError>
|
||||||
</Card>
|
</Card>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
);
|
);
|
||||||
@@ -92,8 +99,9 @@ class Template extends Component {
|
|||||||
to="/templates/:templateType/:id/details"
|
to="/templates/:templateType/:id/details"
|
||||||
exact
|
exact
|
||||||
/>
|
/>
|
||||||
{template && (
|
{template && [
|
||||||
<Route
|
<Route
|
||||||
|
key="details"
|
||||||
path="/templates/:templateType/:id/details"
|
path="/templates/:templateType/:id/details"
|
||||||
render={() => (
|
render={() => (
|
||||||
<JobTemplateDetail
|
<JobTemplateDetail
|
||||||
@@ -102,14 +110,28 @@ class Template extends Component {
|
|||||||
template={template}
|
template={template}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>,
|
||||||
)}
|
|
||||||
{template && (
|
|
||||||
<Route
|
<Route
|
||||||
|
key="edit"
|
||||||
path="/templates/:templateType/:id/edit"
|
path="/templates/:templateType/:id/edit"
|
||||||
render={() => <JobTemplateEdit template={template} />}
|
render={() => <JobTemplateEdit template={template} />}
|
||||||
/>
|
/>,
|
||||||
)}
|
<Route
|
||||||
|
key="not-found"
|
||||||
|
path="*"
|
||||||
|
render={() => (
|
||||||
|
<ContentError isNotFound>
|
||||||
|
{match.params.id && (
|
||||||
|
<Link
|
||||||
|
to={`/templates/${match.params.templateType}/${match.params.id}/details`}
|
||||||
|
>
|
||||||
|
{i18n._(`View Template Details`)}
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</ContentError>
|
||||||
|
)}
|
||||||
|
/>,
|
||||||
|
]}
|
||||||
</Switch>
|
</Switch>
|
||||||
</Card>
|
</Card>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ class TemplatesList extends Component {
|
|||||||
<PageSection variant={medium}>
|
<PageSection variant={medium}>
|
||||||
<Card>
|
<Card>
|
||||||
<PaginatedDataList
|
<PaginatedDataList
|
||||||
err={contentError}
|
contentError={contentError}
|
||||||
hasContentLoading={hasContentLoading}
|
hasContentLoading={hasContentLoading}
|
||||||
items={templates}
|
items={templates}
|
||||||
itemCount={itemCount}
|
itemCount={itemCount}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { Route, withRouter, Switch } from 'react-router-dom';
|
|||||||
|
|
||||||
import { Config } from '@contexts/Config';
|
import { Config } from '@contexts/Config';
|
||||||
import Breadcrumbs from '@components/Breadcrumbs/Breadcrumbs';
|
import Breadcrumbs from '@components/Breadcrumbs/Breadcrumbs';
|
||||||
|
|
||||||
import { TemplateList } from './TemplateList';
|
import { TemplateList } from './TemplateList';
|
||||||
import Template from './Template';
|
import Template from './Template';
|
||||||
import JobTemplateAdd from './JobTemplateAdd';
|
import JobTemplateAdd from './JobTemplateAdd';
|
||||||
|
|||||||
Reference in New Issue
Block a user