Skip to content

Commit

Permalink
fix: disable sending messages if both application and conversation ar…
Browse files Browse the repository at this point in the history
…e empty and add loading to all pages (#134)

* feat: add loading to all pages

* fix: disable sending messages if both application and conversation are empty

* feat: add chatSpin class to Spin of chat
  • Loading branch information
cike8899 authored Mar 20, 2024
1 parent d38e92a commit 78727c8
Show file tree
Hide file tree
Showing 24 changed files with 629 additions and 473 deletions.
6 changes: 4 additions & 2 deletions web/src/components/rename-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ const RenameModal = ({
};

useEffect(() => {
form.setFieldValue('name', initialName);
}, [initialName, form]);
if (visible) {
form.setFieldValue('name', initialName);
}
}, [initialName, form, visible]);

return (
<Modal
Expand Down
24 changes: 24 additions & 0 deletions web/src/hooks/chunkHooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useCallback } from 'react';
import { useDispatch } from 'umi';
import { useGetKnowledgeSearchParams } from './routeHook';

interface PayloadType {
doc_id: string;
keywords?: string;
}

export const useFetchChunkList = () => {
const dispatch = useDispatch();
const { documentId } = useGetKnowledgeSearchParams();

const fetchChunkList = useCallback(() => {
dispatch({
type: 'chunkModel/chunk_list',
payload: {
doc_id: documentId,
},
});
}, [dispatch, documentId]);

return fetchChunkList;
};
45 changes: 31 additions & 14 deletions web/src/hooks/knowledgeHook.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import showDeleteConfirm from '@/components/deleting-confirm';
import { KnowledgeSearchParams } from '@/constants/knowledge';
import { IKnowledge } from '@/interfaces/database/knowledge';
import { useCallback, useEffect, useMemo } from 'react';
import { useDispatch, useSearchParams, useSelector } from 'umi';
import { useGetKnowledgeSearchParams } from './routeHook';
import { useOneNamespaceEffectsLoading } from './storeHooks';

export const useKnowledgeBaseId = (): string => {
const [searchParams] = useSearchParams();
Expand All @@ -11,17 +12,6 @@ export const useKnowledgeBaseId = (): string => {
return knowledgeBaseId || '';
};

export const useGetKnowledgeSearchParams = () => {
const [currentQueryParameters] = useSearchParams();

return {
documentId:
currentQueryParameters.get(KnowledgeSearchParams.DocumentId) || '',
knowledgeId:
currentQueryParameters.get(KnowledgeSearchParams.KnowledgeId) || '',
};
};

export const useDeleteDocumentById = (): {
removeDocument: (documentId: string) => Promise<number>;
} => {
Expand Down Expand Up @@ -135,8 +125,9 @@ export const useFetchKnowledgeBaseConfiguration = () => {

export const useFetchKnowledgeList = (
shouldFilterListWithoutDocument: boolean = false,
): IKnowledge[] => {
): { list: IKnowledge[]; loading: boolean } => {
const dispatch = useDispatch();
const loading = useOneNamespaceEffectsLoading('knowledgeModel', ['getList']);

const knowledgeModel = useSelector((state: any) => state.knowledgeModel);
const { data = [] } = knowledgeModel;
Expand All @@ -156,7 +147,7 @@ export const useFetchKnowledgeList = (
fetchList();
}, [fetchList]);

return list;
return { list, loading };
};

export const useSelectFileThumbnails = () => {
Expand Down Expand Up @@ -189,3 +180,29 @@ export const useFetchFileThumbnails = (docIds?: Array<string>) => {

return { fileThumbnails, fetchFileThumbnails };
};

//#region knowledge configuration

export const useUpdateKnowledge = () => {
const dispatch = useDispatch();

const saveKnowledgeConfiguration = useCallback(
(payload: any) => {
dispatch({
type: 'kSModel/updateKb',
payload,
});
},
[dispatch],
);

return saveKnowledgeConfiguration;
};

export const useSelectKnowledgeDetails = () => {
const knowledgeDetails: IKnowledge = useSelector(
(state: any) => state.kSModel.knowledgeDetails,
);
return knowledgeDetails;
};
//#endregion
2 changes: 1 addition & 1 deletion web/src/hooks/llmHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { useCallback, useEffect, useMemo } from 'react';
import { useDispatch, useSelector } from 'umi';

export const useFetchLlmList = (
isOnMountFetching: boolean = true,
modelType?: LlmModelType,
isOnMountFetching: boolean = true,
) => {
const dispatch = useDispatch();

Expand Down
14 changes: 13 additions & 1 deletion web/src/hooks/routeHook.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useLocation } from 'umi';
import { KnowledgeSearchParams } from '@/constants/knowledge';
import { useLocation, useSearchParams } from 'umi';

export enum SegmentIndex {
Second = '2',
Expand All @@ -19,3 +20,14 @@ export const useSecondPathName = () => {
export const useThirdPathName = () => {
return useSegmentedPathName(SegmentIndex.Third);
};

export const useGetKnowledgeSearchParams = () => {
const [currentQueryParameters] = useSearchParams();

return {
documentId:
currentQueryParameters.get(KnowledgeSearchParams.DocumentId) || '',
knowledgeId:
currentQueryParameters.get(KnowledgeSearchParams.KnowledgeId) || '',
};
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useGetKnowledgeSearchParams } from '@/hooks/knowledgeHook';
import { useGetKnowledgeSearchParams } from '@/hooks/routeHook';
import { api_host } from '@/utils/api';
import { useSize } from 'ahooks';
import { CustomTextRenderer } from 'node_modules/react-pdf/dist/esm/shared/types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useOneNamespaceEffectsLoading } from '@/hooks/storeHooks';
import { IChunk, IKnowledgeFile } from '@/interfaces/database/knowledge';
import { buildChunkHighlights } from '@/utils/documentUtils';
import { useCallback, useMemo, useState } from 'react';
Expand Down Expand Up @@ -46,3 +47,11 @@ export const useGetChunkHighlights = (

return highlights;
};

export const useSelectChunkListLoading = () => {
return useOneNamespaceEffectsLoading('chunkModel', [
'create_hunk',
'chunk_list',
'switch_chunk',
]);
};
43 changes: 13 additions & 30 deletions web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { useFetchChunkList } from '@/hooks/chunkHooks';
import { useDeleteChunkByIds } from '@/hooks/knowledgeHook';
import { getOneNamespaceEffectsLoading } from '@/utils/storeUtil';
import type { PaginationProps } from 'antd';
import { Divider, Flex, Pagination, Space, Spin, message } from 'antd';
import classNames from 'classnames';
import { useCallback, useEffect, useState } from 'react';
import { useDispatch, useSearchParams, useSelector } from 'umi';
import ChunkCard from './components/chunk-card';
import CreatingModal from './components/chunk-creating-modal';
import ChunkToolBar from './components/chunk-toolbar';
// import DocumentPreview from './components/document-preview';
import classNames from 'classnames';
import DocumentPreview from './components/document-preview/preview';
import { useHandleChunkCardClick, useSelectDocumentInfo } from './hooks';
import {
useHandleChunkCardClick,
useSelectChunkListLoading,
useSelectDocumentInfo,
} from './hooks';
import { ChunkModelState } from './model';

import styles from './index.less';
interface PayloadType {
doc_id: string;
keywords?: string;
}

const Chunk = () => {
const dispatch = useDispatch();
Expand All @@ -27,31 +26,15 @@ const Chunk = () => {
const [selectedChunkIds, setSelectedChunkIds] = useState<string[]>([]);
const [searchParams] = useSearchParams();
const { data = [], total, pagination } = chunkModel;
const effects = useSelector((state: any) => state.loading.effects);
const loading = getOneNamespaceEffectsLoading('chunkModel', effects, [
'create_hunk',
'chunk_list',
'switch_chunk',
]);
const loading = useSelectChunkListLoading();
const documentId: string = searchParams.get('doc_id') || '';
const [chunkId, setChunkId] = useState<string | undefined>();
const { removeChunk } = useDeleteChunkByIds();
const documentInfo = useSelectDocumentInfo();
const { handleChunkCardClick, selectedChunkId } = useHandleChunkCardClick();
const isPdf = documentInfo.type === 'pdf';

const getChunkList = useCallback(() => {
const payload: PayloadType = {
doc_id: documentId,
};

dispatch({
type: 'chunkModel/chunk_list',
payload: {
...payload,
},
});
}, [dispatch, documentId]);
const getChunkList = useFetchChunkList();

const handleEditChunk = useCallback(
(chunk_id?: string) => {
Expand Down Expand Up @@ -169,8 +152,8 @@ const Chunk = () => {
vertical
className={isPdf ? styles.pagePdfWrapper : styles.pageWrapper}
>
<div className={styles.pageContent}>
<Spin spinning={loading} className={styles.spin} size="large">
<Spin spinning={loading} className={styles.spin} size="large">
<div className={styles.pageContent}>
<Space
direction="vertical"
size={'middle'}
Expand All @@ -193,8 +176,8 @@ const Chunk = () => {
></ChunkCard>
))}
</Space>
</Spin>
</div>
</div>
</Spin>
<div className={styles.pageFooter}>
<Pagination
responsive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ const RenameModal = () => {
};

useEffect(() => {
form.setFieldValue('name', initialName);
}, [initialName, documentId, form]);
if (isModalOpen) {
form.setFieldValue('name', initialName);
}
}, [initialName, documentId, form, isModalOpen]);

return (
<Modal
Expand Down
Loading

0 comments on commit 78727c8

Please sign in to comment.