Skip to content

[UI] Applications/Sources pages crash the UI if a cluster cannot be reached #920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions ui-cra/src/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as React from 'react';
import { ContentWrapper } from './Layout/ContentWrapper';
import { PageTemplate } from './Layout/PageTemplate';
import { SectionHeader } from './Layout/SectionHeader';

export default class ErrorBoundary extends React.Component<
any,
{ hasError: boolean; error: Error | null }
> {
constructor(props: any) {
super(props);
this.state = { hasError: false, error: null };
}

static getDerivedStateFromError(error: Error) {
// Update state so the next render will show the fallback UI.
return { hasError: true, error };
}

componentDidCatch(error: Error) {
// You can also log the error to an error reporting service
console.error(error);
}

render() {
if (this.state.hasError) {
// You can render any custom fallback UI
return (
<PageTemplate documentTitle="Error">
<SectionHeader path={[{ label: 'Error' }]} />
<ContentWrapper>
<h3>Something went wrong.</h3>
<pre>{this.state.error?.message}</pre>
<pre>{this.state.error?.stack}</pre>
</ContentWrapper>
</PageTemplate>
);
}

return this.props.children;
}
}
236 changes: 119 additions & 117 deletions ui-cra/src/components/ResponsiveDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ import WGApplicationsFluxRuntime from './Applications/FluxRuntime';
import qs from 'query-string';
import { theme as weaveTheme } from '@weaveworks/weave-gitops';
import { GitProvider } from '@weaveworks/weave-gitops/ui/lib/api/applications/applications.pb';

import Policies from './Policies';
import PolicyDetails from './Policies/PolicyDetails';
import PoliciesViolations from './PolicyViolations';
import PolicyViolationDetails from './PolicyViolations/ViolationDetails';
import { ClustersService } from '../cluster-services/cluster_services.pb';
import EnterpriseClientProvider from '../contexts/EnterpriseClient/Provider';
import ErrorBoundary from './ErrorBoundary';

const GITLAB_OAUTH_CALLBACK = '/oauth/gitlab';
const POLICIES = '/policies';
Expand Down Expand Up @@ -159,7 +159,7 @@ const CoreWrapper = styled.div`

const Page404 = () => (
<PageTemplate documentTitle="WeGO · NotFound">
<SectionHeader />
<SectionHeader path={[{ label: 'Error' }]} />
<ContentWrapper>
<Lottie
loop
Expand Down Expand Up @@ -236,123 +236,125 @@ const App = () => {
</Hidden>
</nav>
<main className={classes.content}>
<Switch>
<Route component={MCCP} exact path={['/', '/clusters']} />
<Route component={MCCP} exact path="/clusters/delete" />
<Route
component={AddClusterWithCredentials}
exact
path="/clusters/templates/:templateName/create"
/>
<Route
component={TemplatesDashboard}
exact
path="/clusters/templates"
/>
<Route
component={PoliciesViolations}
exact
path="/clusters/violations"
/>
<Route
component={PolicyViolationDetails}
exact
path="/clusters/violations/:id"
/>
<Route
component={() => (
<CoreWrapper>
<WGApplicationsDashboard />
</CoreWrapper>
)}
exact
path={V2Routes.Automations}
/>
<Route
component={() => (
<CoreWrapper>
<WGApplicationsSources />
</CoreWrapper>
)}
exact
path={V2Routes.Sources}
/>
<Route
component={withSearchParams((props: any) => (
<CoreWrapper>
<WGApplicationsKustomization {...props} />
</CoreWrapper>
))}
path={V2Routes.Kustomization}
/>
<Route
component={withSearchParams((props: any) => (
<CoreWrapper>
<WGApplicationsGitRepository {...props} />
</CoreWrapper>
))}
path={V2Routes.GitRepo}
/>
<Route
component={withSearchParams((props: any) => (
<CoreWrapper>
<WGApplicationsHelmRepository {...props} />
</CoreWrapper>
))}
path={V2Routes.HelmRepo}
/>
<Route
component={withSearchParams((props: any) => (
<CoreWrapper>
<WGApplicationsBucket {...props} />
</CoreWrapper>
))}
path={V2Routes.Bucket}
/>
<Route
component={withSearchParams((props: any) => (
<CoreWrapper>
<WGApplicationsHelmRelease {...props} />
</CoreWrapper>
))}
path={V2Routes.HelmRelease}
/>
<Route
component={withSearchParams((props: any) => (
<CoreWrapper>
<WGApplicationsHelmChart {...props} />
</CoreWrapper>
))}
path={V2Routes.HelmChart}
/>
<Route
component={WGApplicationsFluxRuntime}
exact
path={V2Routes.FluxRuntime}
/>
<ErrorBoundary>
<Switch>
<Route component={MCCP} exact path={['/', '/clusters']} />
<Route component={MCCP} exact path="/clusters/delete" />
<Route
component={AddClusterWithCredentials}
exact
path="/clusters/templates/:templateName/create"
/>
<Route
component={TemplatesDashboard}
exact
path="/clusters/templates"
/>
<Route
component={PoliciesViolations}
exact
path="/clusters/violations"
/>
<Route
component={PolicyViolationDetails}
exact
path="/clusters/violations/:id"
/>
<Route
component={() => (
<CoreWrapper>
<WGApplicationsDashboard />
</CoreWrapper>
)}
exact
path={V2Routes.Automations}
/>
<Route
component={() => (
<CoreWrapper>
<WGApplicationsSources />
</CoreWrapper>
)}
exact
path={V2Routes.Sources}
/>
<Route
component={withSearchParams((props: any) => (
<CoreWrapper>
<WGApplicationsKustomization {...props} />
</CoreWrapper>
))}
path={V2Routes.Kustomization}
/>
<Route
component={withSearchParams((props: any) => (
<CoreWrapper>
<WGApplicationsGitRepository {...props} />
</CoreWrapper>
))}
path={V2Routes.GitRepo}
/>
<Route
component={withSearchParams((props: any) => (
<CoreWrapper>
<WGApplicationsHelmRepository {...props} />
</CoreWrapper>
))}
path={V2Routes.HelmRepo}
/>
<Route
component={withSearchParams((props: any) => (
<CoreWrapper>
<WGApplicationsBucket {...props} />
</CoreWrapper>
))}
path={V2Routes.Bucket}
/>
<Route
component={withSearchParams((props: any) => (
<CoreWrapper>
<WGApplicationsHelmRelease {...props} />
</CoreWrapper>
))}
path={V2Routes.HelmRelease}
/>
<Route
component={withSearchParams((props: any) => (
<CoreWrapper>
<WGApplicationsHelmChart {...props} />
</CoreWrapper>
))}
path={V2Routes.HelmChart}
/>
<Route
component={WGApplicationsFluxRuntime}
exact
path={V2Routes.FluxRuntime}
/>

<Route exact path={POLICIES} component={Policies} />
<Route
exact
path="/policies/:id/:clusterName"
component={PolicyDetails}
/>
<Route exact path={POLICIES} component={Policies} />
<Route
exact
path="/policies/:id/:clusterName"
component={PolicyDetails}
/>

<Route
exact
path={GITLAB_OAUTH_CALLBACK}
component={({ location }: any) => {
const params = qs.parse(location.search);
return (
<OAuthCallback
provider={'GitLab' as GitProvider}
code={params.code as string}
/>
);
}}
/>
<Route exact render={Page404} />
</Switch>
<Route
exact
path={GITLAB_OAUTH_CALLBACK}
component={({ location }: any) => {
const params = qs.parse(location.search);
return (
<OAuthCallback
provider={'GitLab' as GitProvider}
code={params.code as string}
/>
);
}}
/>
<Route exact render={Page404} />
</Switch>
</ErrorBoundary>
</main>
</div>
</Compose>
Expand Down