Skip to content

Commit

Permalink
feat: use error boundary lib and setup fallback component
Browse files Browse the repository at this point in the history
  • Loading branch information
YounixM committed Nov 15, 2023
1 parent f2f89eb commit 6144234
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 46 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"react-dnd-html5-backend": "16.0.1",
"react-dom": "18.2.0",
"react-drag-listview": "2.0.0",
"react-error-boundary": "4.0.11",
"react-force-graph": "^1.43.0",
"react-grid-layout": "^1.3.4",
"react-helmet-async": "1.3.0",
Expand Down
17 changes: 11 additions & 6 deletions frontend/src/container/AppLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import Header from 'container/Header';
import SideNav from 'container/SideNav';
import TopNav from 'container/TopNav';
import { useNotifications } from 'hooks/useNotifications';
import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';
import { ReactNode, useEffect, useMemo, useRef } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { Helmet } from 'react-helmet-async';
import { useTranslation } from 'react-i18next';
import { useQueries } from 'react-query';
Expand Down Expand Up @@ -203,12 +205,15 @@ function AppLayout(props: AppLayoutProps): JSX.Element {
{isToDisplayLayout && <Header />}
<Layout>
{isToDisplayLayout && !renderFullScreen && <SideNav />}
<LayoutContent>
<ChildrenContainer>
{isToDisplayLayout && !renderFullScreen && <TopNav />}
{children}
</ChildrenContainer>
</LayoutContent>

<ErrorBoundary FallbackComponent={ErrorBoundaryFallback}>
<LayoutContent>
<ChildrenContainer>
{isToDisplayLayout && !renderFullScreen && <TopNav />}
{children}
</ChildrenContainer>
</LayoutContent>
</ErrorBoundary>
</Layout>
</Layout>
);
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/container/ServiceApplication/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { FeatureKeys } from 'constants/features';
import useFeatureFlag from 'hooks/useFeatureFlag';
import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';
import { ErrorBoundary } from 'react-error-boundary';

import ServiceMetrics from './ServiceMetrics';
import ServiceTraces from './ServiceTraces';
Expand All @@ -10,9 +12,11 @@ function Services(): JSX.Element {
?.active;

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

Expand Down
29 changes: 17 additions & 12 deletions frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import 'styles.scss';

import AppRoutes from 'AppRoutes';
import { ThemeProvider } from 'hooks/useDarkMode';
import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';
import { createRoot } from 'react-dom/client';
import { ErrorBoundary } from 'react-error-boundary';
import { HelmetProvider } from 'react-helmet-async';
import { QueryClient, QueryClientProvider } from 'react-query';
import { ReactQueryDevtools } from 'react-query/devtools';
Expand All @@ -24,17 +26,20 @@ if (container) {
const root = createRoot(container);

root.render(
<HelmetProvider>
<ThemeProvider>
<QueryClientProvider client={queryClient}>
<Provider store={store}>
<AppRoutes />
</Provider>
{process.env.NODE_ENV === 'development' && (
<ReactQueryDevtools initialIsOpen />
)}
</QueryClientProvider>
</ThemeProvider>
</HelmetProvider>,
<ErrorBoundary FallbackComponent={ErrorBoundaryFallback}>
<HelmetProvider>
<ThemeProvider>
<QueryClientProvider client={queryClient}>
<Provider store={store}>
<AppRoutes />
</Provider>
{process.env.NODE_ENV === 'development' && (
<ReactQueryDevtools initialIsOpen />
)}
</QueryClientProvider>
</ThemeProvider>
</HelmetProvider>
,
</ErrorBoundary>,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.error-boundary-fallback-container {
width: 100%;
}

.actionBtn {
display: flex;
align-items: center;
gap: 4px;
}

.title,
.actions {
display: flex;
align-items: center;
gap: 8px;
}
55 changes: 55 additions & 0 deletions frontend/src/pages/ErrorBoundaryFallback/ErrorBoundaryFallback.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import './ErrorBoundaryFallback.styles.scss';

import { BugOutlined, UndoOutlined } from '@ant-design/icons';
import { Button, Card, Typography } from 'antd';
import Slack from 'container/SideNav/Slack';

function ErrorBoundaryFallback(): JSX.Element {
const onClickSlackHandler = (): void => {
window.open('https://signoz.io/slack', '_blank');
};

const handleReload = (): void => {
window.location.reload();
};
return (
<Card size="small" className="error-boundary-fallback-container">
<div className="title">
<BugOutlined />
<Typography.Title type="danger" level={4} style={{ margin: 0 }}>
{' '}
Oops !!! Something went wrong
</Typography.Title>
</div>

<>
<p>
Don&apos;t worry, our team is here to help. Please contact support if the
issue persists.
</p>

<div className="actions">
<Button
className="actionBtn"
type="default"
onClick={handleReload}
icon={<UndoOutlined />}
>
Reload
</Button>

<Button
className="actionBtn"
type="default"
onClick={onClickSlackHandler}
icon={<Slack />}
>
&nbsp; Support
</Button>
</div>
</>
</Card>
);
}

export default ErrorBoundaryFallback;
6 changes: 4 additions & 2 deletions frontend/src/pages/LogsExplorer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import ExplorerCard from 'components/ExplorerCard/ExplorerCard';
import LogExplorerQuerySection from 'container/LogExplorerQuerySection';
import LogsExplorerViews from 'container/LogsExplorerViews';
import LogsTopNav from 'container/LogsTopNav';
import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';
import { ErrorBoundary } from 'react-error-boundary';
import { DataSource } from 'types/common/queryBuilder';

import { WrapperStyled } from './styles';

function LogsExplorer(): JSX.Element {
return (
<>
<ErrorBoundary FallbackComponent={ErrorBoundaryFallback}>
<LogsTopNav />
<WrapperStyled>
<Row gutter={[0, 16]}>
Expand All @@ -23,7 +25,7 @@ function LogsExplorer(): JSX.Element {
</Col>
</Row>
</WrapperStyled>
</>
</ErrorBoundary>
);
}

Expand Down
6 changes: 4 additions & 2 deletions frontend/src/pages/Trace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import TraceTable from 'container/Trace/TraceTable';
import { useNotifications } from 'hooks/useNotifications';
import getStep from 'lib/getStep';
import history from 'lib/history';
import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';
import { MouseEventHandler, useCallback, useEffect, useState } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { connect, useDispatch, useSelector } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';
import { ThunkDispatch } from 'redux-thunk';
Expand Down Expand Up @@ -144,7 +146,7 @@ function Trace({
);

return (
<>
<ErrorBoundary FallbackComponent={ErrorBoundaryFallback}>
<Search />
<Container>
<div>
Expand All @@ -167,7 +169,7 @@ function Trace({
</Card>
</RightContainer>
</Container>
</>
</ErrorBoundary>
);
}

Expand Down
46 changes: 25 additions & 21 deletions frontend/src/pages/TracesExplorer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { useShareBuilderUrl } from 'hooks/queryBuilder/useShareBuilderUrl';
import { useHandleExplorerTabChange } from 'hooks/useHandleExplorerTabChange';
import { useNotifications } from 'hooks/useNotifications';
import history from 'lib/history';
import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';
import { useCallback, useEffect, useMemo } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { Dashboard } from 'types/api/dashboard/getAll';
import { DataSource } from 'types/common/queryBuilder';
import { generateExportToDashboardLink } from 'utils/dashboard/generateExportToDashboardLink';
Expand Down Expand Up @@ -168,28 +170,30 @@ function TracesExplorer(): JSX.Element {
]);

return (
<>
<ExplorerCard sourcepage={DataSource.TRACES}>
<QuerySection />
</ExplorerCard>

<Container>
<ActionsWrapper>
<ExportPanel
query={exportDefaultQuery}
isLoading={isLoading}
onExport={handleExport}
<ErrorBoundary FallbackComponent={ErrorBoundaryFallback}>
<>
<ExplorerCard sourcepage={DataSource.TRACES}>
<QuerySection />
</ExplorerCard>

<Container>
<ActionsWrapper>
<ExportPanel
query={exportDefaultQuery}
isLoading={isLoading}
onExport={handleExport}
/>
</ActionsWrapper>

<Tabs
defaultActiveKey={currentTab}
activeKey={currentTab}
items={tabsItems}
onChange={handleExplorerTabChange}
/>
</ActionsWrapper>

<Tabs
defaultActiveKey={currentTab}
activeKey={currentTab}
items={tabsItems}
onChange={handleExplorerTabChange}
/>
</Container>
</>
</Container>
</>
</ErrorBoundary>
);
}

Expand Down
7 changes: 7 additions & 0 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12733,6 +12733,13 @@ react-draggable@^4.0.0, react-draggable@^4.0.3:
clsx "^1.1.1"
prop-types "^15.8.1"

react-error-boundary@4.0.11:
version "4.0.11"
resolved "https://registry.yarnpkg.com/react-error-boundary/-/react-error-boundary-4.0.11.tgz#36bf44de7746714725a814630282fee83a7c9a1c"
integrity sha512-U13ul67aP5DOSPNSCWQ/eO0AQEYzEFkVljULQIjMV0KlffTAhxuDoBKdO0pb/JZ8mDhMKFZ9NZi0BmLGUiNphw==
dependencies:
"@babel/runtime" "^7.12.5"

react-fast-compare@^3.2.0:
version "3.2.2"
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.2.tgz#929a97a532304ce9fee4bcae44234f1ce2c21d49"
Expand Down

0 comments on commit 6144234

Please # to comment.