Skip to content

Commit

Permalink
feat: create base level error boundry component
Browse files Browse the repository at this point in the history
  • Loading branch information
YounixM committed Oct 31, 2023
1 parent eddb607 commit 92c15bd
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 86 deletions.
44 changes: 44 additions & 0 deletions frontend/src/components/ErrorBoundry/ErrorBoundry.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* eslint-disable @typescript-eslint/ban-types */
import { Component, ErrorInfo, ReactNode } from 'react';

type ErrorBoundaryProps = {
children: ReactNode;
};

type ErrorBoundaryState = {
hasError: boolean;
};

class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
constructor(props: ErrorBoundaryProps) {
super(props);
this.state = { hasError: false };
}

componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
// Handle the error and update the state
this.setState({ hasError: true });
// You can also log the error to a service like Sentry or report it to the server.
console.error(error, errorInfo);
}

render(): JSX.Element {
const { hasError } = this.state;
const { children } = this.props;

if (hasError) {
// Render a fallback UI when an error occurs
return (
<div>
<h1>Something went wrong</h1>
<p>We apologize for the inconvenience.</p>
</div>
);
}

// Render the children if no error occurred
return <> {children} </>;
}
}

export default ErrorBoundary;
143 changes: 73 additions & 70 deletions frontend/src/container/MetricsApplication/Tabs/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import getTopLevelOperations, {
ServiceDataProps,
} from 'api/metrics/getTopLevelOperations';
import { ActiveElement, Chart, ChartData, ChartEvent } from 'chart.js';
import ErrorBoundary from 'components/ErrorBoundry/ErrorBoundry';
import { FeatureKeys } from 'constants/features';
import { QueryParams } from 'constants/query';
import { PANEL_TYPES } from 'constants/queryBuilder';
Expand Down Expand Up @@ -190,51 +191,25 @@ function Application(): JSX.Element {
};

return (
<>
<Row gutter={24}>
<Col span={12}>
<ServiceOverview
onDragSelect={onDragSelect}
handleGraphClick={handleGraphClick}
selectedTimeStamp={selectedTimeStamp}
selectedTraceTags={selectedTraceTags}
topLevelOperationsRoute={topLevelOperationsRoute}
topLevelOperationsLoading={topLevelOperationsLoading}
/>
</Col>
<ErrorBoundary>
<>
<Row gutter={24}>
<Col span={12}>
<ServiceOverview
onDragSelect={onDragSelect}
handleGraphClick={handleGraphClick}
selectedTimeStamp={selectedTimeStamp}
selectedTraceTags={selectedTraceTags}
topLevelOperationsRoute={topLevelOperationsRoute}
topLevelOperationsLoading={topLevelOperationsLoading}
/>
</Col>

<Col span={12}>
<Button
type="default"
size="small"
id="Rate_button"
onClick={onViewTracePopupClick({
servicename,
selectedTraceTags,
timestamp: selectedTimeStamp,
})}
>
View Traces
</Button>
<TopLevelOperation
handleGraphClick={handleGraphClick}
onDragSelect={onDragSelect}
topLevelOperationsError={topLevelOperationsError}
topLevelOperationsLoading={topLevelOperationsLoading}
topLevelOperationsIsError={topLevelOperationsIsError}
name="operations_per_sec"
widget={operationPerSecWidget}
opName="Rate"
/>
</Col>
</Row>
<Row gutter={24}>
<Col span={12}>
<ColApDexContainer>
<Col span={12}>
<Button
type="default"
size="small"
id="ApDex_button"
id="Rate_button"
onClick={onViewTracePopupClick({
servicename,
selectedTraceTags,
Expand All @@ -243,43 +218,71 @@ function Application(): JSX.Element {
>
View Traces
</Button>
<ApDex
handleGraphClick={handleGraphClick}
onDragSelect={onDragSelect}
topLevelOperationsRoute={topLevelOperationsRoute}
tagFilterItems={tagFilterItems}
/>
</ColApDexContainer>
<ColErrorContainer>
<Button
type="default"
size="small"
id="Error_button"
onClick={onErrorTrackHandler(selectedTimeStamp)}
>
View Traces
</Button>

<TopLevelOperation
handleGraphClick={handleGraphClick}
onDragSelect={onDragSelect}
topLevelOperationsError={topLevelOperationsError}
topLevelOperationsLoading={topLevelOperationsLoading}
topLevelOperationsIsError={topLevelOperationsIsError}
name="error_percentage_%"
widget={errorPercentageWidget}
opName="Error"
name="operations_per_sec"
widget={operationPerSecWidget}
opName="Rate"
/>
</ColErrorContainer>
</Col>
</Col>
</Row>
<Row gutter={24}>
<Col span={12}>
<ColApDexContainer>
<Button
type="default"
size="small"
id="ApDex_button"
onClick={onViewTracePopupClick({
servicename,
selectedTraceTags,
timestamp: selectedTimeStamp,
})}
>
View Traces
</Button>
<ApDex
handleGraphClick={handleGraphClick}
onDragSelect={onDragSelect}
topLevelOperationsRoute={topLevelOperationsRoute}
tagFilterItems={tagFilterItems}
/>
</ColApDexContainer>
<ColErrorContainer>
<Button
type="default"
size="small"
id="Error_button"
onClick={onErrorTrackHandler(selectedTimeStamp)}
>
View Traces
</Button>

<TopLevelOperation
handleGraphClick={handleGraphClick}
onDragSelect={onDragSelect}
topLevelOperationsError={topLevelOperationsError}
topLevelOperationsLoading={topLevelOperationsLoading}
topLevelOperationsIsError={topLevelOperationsIsError}
name="error_percentage_%"
widget={errorPercentageWidget}
opName="Error"
/>
</ColErrorContainer>
</Col>

<Col span={12}>
<Card>
{isSpanMetricEnabled ? <TopOperationMetrics /> : <TopOperation />}
</Card>
</Col>
</Row>
</>
<Col span={12}>
<Card>
{isSpanMetricEnabled ? <TopOperationMetrics /> : <TopOperation />}
</Card>
</Col>
</Row>
</>
</ErrorBoundary>
);
}

Expand Down
9 changes: 6 additions & 3 deletions frontend/src/container/ServiceApplication/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ErrorBoundary from 'components/ErrorBoundry/ErrorBoundry';
import { FeatureKeys } from 'constants/features';
import useFeatureFlag from 'hooks/useFeatureFlag';

Expand All @@ -10,9 +11,11 @@ function Services(): JSX.Element {
?.active;

return (
<Container>
{isSpanMetricEnabled ? <ServiceMetrics /> : <ServiceTraces />}
</Container>
<ErrorBoundary>
<Container>
{isSpanMetricEnabled ? <ServiceMetrics /> : <ServiceTraces />}
</Container>
</ErrorBoundary>
);
}

Expand Down
30 changes: 17 additions & 13 deletions frontend/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './ReactI18';

import AppRoutes from 'AppRoutes';
import ErrorBoundary from 'components/ErrorBoundry/ErrorBoundry';
import GlobalStyles from 'globalStyles';
import { ThemeProvider } from 'hooks/useDarkMode';
import { createRoot } from 'react-dom/client';
Expand All @@ -24,18 +25,21 @@ if (container) {
const root = createRoot(container);

root.render(
<HelmetProvider>
<ThemeProvider>
<QueryClientProvider client={queryClient}>
<Provider store={store}>
<GlobalStyles />
<AppRoutes />
</Provider>
{process.env.NODE_ENV === 'development' && (
<ReactQueryDevtools initialIsOpen />
)}
</QueryClientProvider>
</ThemeProvider>
</HelmetProvider>,
<ErrorBoundary>
<HelmetProvider>
<ThemeProvider>
<QueryClientProvider client={queryClient}>
<Provider store={store}>
<GlobalStyles />
<AppRoutes />
</Provider>
{process.env.NODE_ENV === 'development' && (
<ReactQueryDevtools initialIsOpen />
)}
</QueryClientProvider>
</ThemeProvider>
</HelmetProvider>
,
</ErrorBoundary>,
);
}

0 comments on commit 92c15bd

Please sign in to comment.