Skip to content
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

feat: Catching errors with IndentedTree #2247 #2380

Merged
merged 1 commit into from
Sep 12, 2024
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
12 changes: 12 additions & 0 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"openai-speech-stream-player": "^1.0.8",
"rc-tween-one": "^3.0.6",
"react-copy-to-clipboard": "^5.1.0",
"react-error-boundary": "^4.0.13",
"react-force-graph": "^1.44.4",
"react-i18next": "^14.0.0",
"react-markdown": "^9.0.1",
Expand Down
34 changes: 24 additions & 10 deletions web/src/components/indented-tree/indented-tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { TreeData } from '@antv/g6/lib/types';
import isEmpty from 'lodash/isEmpty';
import React, { useCallback, useEffect, useRef } from 'react';
import { ErrorBoundary, FallbackProps } from 'react-error-boundary';

const rootId = 'root';

Expand Down Expand Up @@ -297,6 +298,17 @@ interface IProps {
style?: React.CSSProperties;
}

function fallbackRender({ error }: FallbackProps) {
// Call resetErrorBoundary() to reset the error boundary and retry the render.

return (
<div role="alert">
<p>Something went wrong:</p>
<pre style={{ color: 'red' }}>{error.message}</pre>
</div>
);
}

const IndentedTree = ({ data, show, style = {} }: IProps) => {
const containerRef = useRef<HTMLDivElement>(null);
const graphRef = useRef<Graph | null>(null);
Expand Down Expand Up @@ -382,16 +394,18 @@ const IndentedTree = ({ data, show, style = {} }: IProps) => {
}, [render, data]);

return (
<div
id="tree"
ref={containerRef}
style={{
width: '90vw',
height: '80vh',
display: show ? 'block' : 'none',
...style,
}}
/>
<ErrorBoundary fallbackRender={fallbackRender}>
<div
id="tree"
ref={containerRef}
style={{
width: '90vw',
height: '80vh',
display: show ? 'block' : 'none',
...style,
}}
/>
</ErrorBoundary>
);
};

Expand Down
2 changes: 1 addition & 1 deletion web/src/hooks/chat-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export const useFetchMindMap = () => {
mutationFn: async (params: IAskRequestBody) => {
try {
const ret = await chatService.getMindMap(params);
return ret?.data?.data ?? [];
return ret?.data?.data ?? {};
} catch (error) {
if (has(error, 'message')) {
message.error(error.message);
Expand Down
24 changes: 17 additions & 7 deletions web/src/pages/search/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,22 @@

.content {
height: 100%;
.main {
width: 60%;
// background-color: aqua;
.hide {
display: none;
}

.mainMixin() {
overflow: auto;
padding: 20px 10px 10px;
.chunks {
// overflow: auto;
// height: 60vh;
}
}

.largeMain {
width: 100%;
.mainMixin();
}
.main {
width: 60%;
.mainMixin();
}

.graph {
Expand Down Expand Up @@ -111,6 +118,9 @@
}
.partialInput {
width: 100%;
position: sticky;
top: 0;
z-index: 1;
.input();
}

Expand Down
19 changes: 15 additions & 4 deletions web/src/pages/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
Space,
Tag,
} from 'antd';
import { useState } from 'react';
import { useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import MarkdownContent from '../chat/markdown-content';
import { useFetchBackgroundImage, useSendQuestion } from './hooks';
Expand All @@ -35,7 +35,6 @@ const SearchPage = () => {
const { t } = useTranslation();
const [checkedList, setCheckedList] = useState<string[]>([]);
const { chunks, total } = useSelectTestingResult();
// const appConf = useFetchAppConf();
const {
sendQuestion,
handleClickRelatedQuestion,
Expand All @@ -62,6 +61,14 @@ const SearchPage = () => {
handleTestChunk(selectedDocumentIds, pageNumber, pageSize);
};

const isMindMapEmpty = useMemo(() => {
return (
!mindMapLoading &&
((Array.isArray(mindMap?.children) && mindMap.children.length === 0) ||
!Array.isArray(mindMap?.children))
);
}, [mindMap, mindMapLoading]);

const InputSearch = (
<Search
value={searchStr}
Expand Down Expand Up @@ -103,7 +110,9 @@ const SearchPage = () => {
</Flex>
) : (
<Flex className={styles.content}>
<section className={styles.main}>
<section
className={isMindMapEmpty ? styles.largeMain : styles.main}
>
{InputSearch}
{answer.answer && (
<div className={styles.answerWrapper}>
Expand Down Expand Up @@ -165,7 +174,9 @@ const SearchPage = () => {
onChange={onChange}
/>
</section>
<section className={styles.graph}>
<section
className={isMindMapEmpty ? styles.hide : styles.graph}
>
{mindMapLoading ? (
<Skeleton active />
) : (
Expand Down