Skip to content

Commit e7d2bab

Browse files
Error boundary integration (#490)
* added the error boundary UI * added the docs link * wording change * changed the link
1 parent e435c59 commit e7d2bab

File tree

6 files changed

+70
-23
lines changed

6 files changed

+70
-23
lines changed

frontend/src/App.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,27 @@ import './App.css';
22
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';
33
import ThemeWrapper from './context/ThemeWrapper';
44
import QuickStarter from './components/QuickStarter';
5-
65
import { GoogleOAuthProvider } from '@react-oauth/google';
76
import { APP_SOURCES } from './utils/Constants';
7+
import ErrorBoundary from './components/UI/ErrroBoundary';
8+
89
const App: React.FC = () => {
910
return (
1011
<>
1112
{APP_SOURCES != undefined && APP_SOURCES.includes('gcs') ? (
12-
<GoogleOAuthProvider clientId={process.env.GOOGLE_CLIENT_ID as string}>
13+
<ErrorBoundary>
14+
<GoogleOAuthProvider clientId={process.env.GOOGLE_CLIENT_ID as string}>
15+
<ThemeWrapper>
16+
<QuickStarter />
17+
</ThemeWrapper>
18+
</GoogleOAuthProvider>
19+
</ErrorBoundary>
20+
) : (
21+
<ErrorBoundary>
1322
<ThemeWrapper>
1423
<QuickStarter />
1524
</ThemeWrapper>
16-
</GoogleOAuthProvider>
17-
) : (
18-
<ThemeWrapper>
19-
<QuickStarter />
20-
</ThemeWrapper>
25+
</ErrorBoundary>
2126
)}
2227
</>
2328
);

frontend/src/components/ChatBot/Info/InfoModal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ const InfoModal: React.FC<chatInfoMessage> = ({ sources, model, total_tokens, re
175175
</Typography>
176176
</HoverableLink>
177177
</TextLink>
178-
179178
</div>
180179
</>
181180
)}

frontend/src/components/Content.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ const Content: React.FC<ContentProps> = ({
228228
}
229229
};
230230

231-
232231
const handleGenerateGraph = (allowLargeFiles: boolean, selectedFilesFromAllfiles: CustomFile[]) => {
233232
setIsLargeFile(false);
234233
const data = [];
@@ -268,8 +267,9 @@ const Content: React.FC<ContentProps> = ({
268267
const handleOpenGraphClick = () => {
269268
const bloomUrl = process.env.BLOOM_URL;
270269
const uriCoded = userCredentials?.uri.replace(/:\d+$/, '');
271-
const connectURL = `${uriCoded?.split('//')[0]}//${userCredentials?.userName}@${uriCoded?.split('//')[1]}:${userCredentials?.port ?? '7687'
272-
}`;
270+
const connectURL = `${uriCoded?.split('//')[0]}//${userCredentials?.userName}@${uriCoded?.split('//')[1]}:${
271+
userCredentials?.port ?? '7687'
272+
}`;
273273
const encodedURL = encodeURIComponent(connectURL);
274274
const replacedUrl = bloomUrl?.replace('{CONNECT_URL}', encodedURL);
275275
window.open(replacedUrl, '_blank');
@@ -279,10 +279,10 @@ const Content: React.FC<ContentProps> = ({
279279
isLeftExpanded && isRightExpanded
280280
? 'contentWithExpansion'
281281
: isRightExpanded
282-
? 'contentWithChatBot'
283-
: !isLeftExpanded && !isRightExpanded
284-
? 'w-[calc(100%-128px)]'
285-
: 'contentWithDropzoneExpansion';
282+
? 'contentWithChatBot'
283+
: !isLeftExpanded && !isRightExpanded
284+
? 'w-[calc(100%-128px)]'
285+
: 'contentWithDropzoneExpansion';
286286

287287
const handleGraphView = () => {
288288
setOpenGraphView(true);
@@ -585,8 +585,9 @@ const Content: React.FC<ContentProps> = ({
585585
}}
586586
></FileTable>
587587
<Flex
588-
className={`${!isLeftExpanded && !isRightExpanded ? 'w-[calc(100%-128px)]' : 'w-full'
589-
} p-2.5 absolute bottom-4 mt-1.5 self-start`}
588+
className={`${
589+
!isLeftExpanded && !isRightExpanded ? 'w-[calc(100%-128px)]' : 'w-full'
590+
} p-2.5 absolute bottom-4 mt-1.5 self-start`}
590591
justifyContent='space-between'
591592
flexDirection='row'
592593
>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React from 'react';
2+
import { Banner} from '@neo4j-ndl/react';
3+
4+
export default class ErrorBoundary extends React.Component<any, any> {
5+
state = { hasError: false, errorMessage: '' };
6+
7+
static getDerivedStateFromError(_error: unknown) {
8+
return { hasError: true };
9+
}
10+
11+
componentDidCatch(error: Error, errorInfo: any) {
12+
this.setState({ ...this.state, errorMessage: error.message });
13+
console.log({ error });
14+
console.log({ errorInfo });
15+
}
16+
17+
render() {
18+
if (this.state.hasError) {
19+
return (
20+
<div className='n-size-full n-flex n-flex-col n-items-center n-justify-center n-rounded-md n-bg-palette-neutral-bg-weak n-box-border'>
21+
<Banner
22+
icon
23+
type='info'
24+
description={
25+
this.state.errorMessage === 'Missing required parameter client_id.'
26+
? 'Please Provide The Google Client ID For GCS Source'
27+
: 'Sorry there was a problem loading this page'
28+
}
29+
title='Something went wrong'
30+
floating
31+
className='mt-8'
32+
actions={[
33+
{
34+
label: 'Documentation',
35+
href: 'https://github.com/neo4j-labs/llm-graph-builder',
36+
target: '_blank',
37+
},
38+
]}
39+
></Banner>
40+
</div>
41+
);
42+
}
43+
return this.props.children;
44+
}
45+
}

frontend/src/utils/Constants.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export const llms =
3939
export const defaultLLM = llms?.includes('gpt-3.5')
4040
? 'gpt-3.5'
4141
: llms?.includes('gemini-1.0-pro')
42-
? 'gemini-1.0-pro'
43-
: 'diffbot';
42+
? 'gemini-1.0-pro'
43+
: 'diffbot';
4444

4545
export const chunkSize = process.env.CHUNK_SIZE ? parseInt(process.env.CHUNK_SIZE) : 1 * 1024 * 1024;
4646
export const timeperpage = process.env.TIME_PER_PAGE ? parseInt(process.env.TIME_PER_PAGE) : 50;
@@ -146,6 +146,4 @@ export const ChatModeOptions = [
146146
{ Icon: 'abc', value: 'graph+vector' },
147147
];
148148

149-
150149
export const taskParam: string[] = ['update_similarity_graph', 'create_fulltext_index'];
151-

frontend/src/utils/Utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ export const wikiValidation = (url: string) => {
2222
export const webLinkValidation = (url: string) => {
2323
return (
2424
url.trim() != '' &&
25-
/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g.test(url) !=
26-
false
25+
/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_.~#?&//=]*)/g.test(url) != false
2726
);
2827
};
2928
export const youtubeLinkValidation = (url: string) => {

0 commit comments

Comments
 (0)