balibabu
commited on
Commit
·
b40a87c
1
Parent(s):
04d557b
feat: login with github and if it is not a pdf file, set the width of chunkContainer to 100% (#106)
Browse files* feat: if it is not a pdf file, set the width of chunkContainer to 100%
* feat: login with github
- web/src/hooks/authHook.ts +27 -1
- web/src/layouts/index.tsx +3 -0
- web/src/pages/add-knowledge/components/knowledge-chunk/index.less +8 -0
- web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx +12 -6
- web/src/pages/add-knowledge/components/knowledge-testing/testing-control/index.tsx +1 -1
- web/src/pages/login/index.tsx +2 -2
web/src/hooks/authHook.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import authorizationUtil from '@/utils/authorizationUtil';
|
| 2 |
-
import { useState } from 'react';
|
|
|
|
| 3 |
|
| 4 |
export const useAuth = () => {
|
| 5 |
const [isLogin, setIsLogin] = useState(
|
|
@@ -8,3 +9,28 @@ export const useAuth = () => {
|
|
| 8 |
|
| 9 |
return { isLogin };
|
| 10 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import authorizationUtil from '@/utils/authorizationUtil';
|
| 2 |
+
import { useMemo, useState } from 'react';
|
| 3 |
+
import { useNavigate, useSearchParams } from 'umi';
|
| 4 |
|
| 5 |
export const useAuth = () => {
|
| 6 |
const [isLogin, setIsLogin] = useState(
|
|
|
|
| 9 |
|
| 10 |
return { isLogin };
|
| 11 |
};
|
| 12 |
+
|
| 13 |
+
export const useLoginWithGithub = () => {
|
| 14 |
+
const [currentQueryParameters, setSearchParams] = useSearchParams();
|
| 15 |
+
const error = currentQueryParameters.get('error');
|
| 16 |
+
const newQueryParameters: URLSearchParams = useMemo(
|
| 17 |
+
() => new URLSearchParams(currentQueryParameters.toString()),
|
| 18 |
+
[currentQueryParameters],
|
| 19 |
+
);
|
| 20 |
+
const navigate = useNavigate();
|
| 21 |
+
|
| 22 |
+
if (error) {
|
| 23 |
+
navigate('/login');
|
| 24 |
+
newQueryParameters.delete('error');
|
| 25 |
+
setSearchParams(newQueryParameters);
|
| 26 |
+
return;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
const auth = currentQueryParameters.get('auth');
|
| 30 |
+
|
| 31 |
+
if (auth) {
|
| 32 |
+
authorizationUtil.setAuthorization(auth);
|
| 33 |
+
newQueryParameters.delete('auth');
|
| 34 |
+
setSearchParams(newQueryParameters);
|
| 35 |
+
}
|
| 36 |
+
};
|
web/src/layouts/index.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import { Outlet } from 'umi';
|
|
| 4 |
import '../locales/config';
|
| 5 |
import Header from './components/header';
|
| 6 |
|
|
|
|
| 7 |
import styles from './index.less';
|
| 8 |
|
| 9 |
const { Content } = Layout;
|
|
@@ -13,6 +14,8 @@ const App: React.FC = () => {
|
|
| 13 |
token: { colorBgContainer, borderRadiusLG },
|
| 14 |
} = theme.useToken();
|
| 15 |
|
|
|
|
|
|
|
| 16 |
return (
|
| 17 |
<Layout className={styles.layout}>
|
| 18 |
<Layout>
|
|
|
|
| 4 |
import '../locales/config';
|
| 5 |
import Header from './components/header';
|
| 6 |
|
| 7 |
+
import { useLoginWithGithub } from '@/hooks/authHook';
|
| 8 |
import styles from './index.less';
|
| 9 |
|
| 10 |
const { Content } = Layout;
|
|
|
|
| 14 |
token: { colorBgContainer, borderRadiusLG },
|
| 15 |
} = theme.useToken();
|
| 16 |
|
| 17 |
+
useLoginWithGithub();
|
| 18 |
+
|
| 19 |
return (
|
| 20 |
<Layout className={styles.layout}>
|
| 21 |
<Layout>
|
web/src/pages/add-knowledge/components/knowledge-chunk/index.less
CHANGED
|
@@ -16,6 +16,10 @@
|
|
| 16 |
width: 60%;
|
| 17 |
}
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
.pageContent {
|
| 20 |
flex: 1;
|
| 21 |
width: 100%;
|
|
@@ -36,6 +40,10 @@
|
|
| 36 |
height: calc(100vh - 332px);
|
| 37 |
}
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
.pageFooter {
|
| 40 |
padding-top: 10px;
|
| 41 |
height: 32px;
|
|
|
|
| 16 |
width: 60%;
|
| 17 |
}
|
| 18 |
|
| 19 |
+
.pageWrapper {
|
| 20 |
+
width: 100%;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
.pageContent {
|
| 24 |
flex: 1;
|
| 25 |
width: 100%;
|
|
|
|
| 40 |
height: calc(100vh - 332px);
|
| 41 |
}
|
| 42 |
|
| 43 |
+
.chunkOtherContainer {
|
| 44 |
+
width: 100%;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
.pageFooter {
|
| 48 |
padding-top: 10px;
|
| 49 |
height: 32px;
|
web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
|
|
| 1 |
import { getOneNamespaceEffectsLoading } from '@/utils/storeUtil';
|
| 2 |
import type { PaginationProps } from 'antd';
|
| 3 |
import { Divider, Flex, Pagination, Space, Spin, message } from 'antd';
|
| 4 |
import { useCallback, useEffect, useState } from 'react';
|
| 5 |
import { useDispatch, useSearchParams, useSelector } from 'umi';
|
| 6 |
-
import CreatingModal from './components/chunk-creating-modal';
|
| 7 |
-
|
| 8 |
-
import { useDeleteChunkByIds } from '@/hooks/knowledgeHook';
|
| 9 |
import ChunkCard from './components/chunk-card';
|
|
|
|
| 10 |
import ChunkToolBar from './components/chunk-toolbar';
|
| 11 |
// import DocumentPreview from './components/document-preview';
|
|
|
|
| 12 |
import DocumentPreview from './components/document-preview/preview';
|
| 13 |
import { useHandleChunkCardClick, useSelectDocumentInfo } from './hooks';
|
| 14 |
-
import styles from './index.less';
|
| 15 |
import { ChunkModelState } from './model';
|
| 16 |
|
|
|
|
| 17 |
interface PayloadType {
|
| 18 |
doc_id: string;
|
| 19 |
keywords?: string;
|
|
@@ -165,13 +165,18 @@ const Chunk = () => {
|
|
| 165 |
></ChunkToolBar>
|
| 166 |
<Divider></Divider>
|
| 167 |
<Flex flex={1} gap={'middle'}>
|
| 168 |
-
<Flex
|
|
|
|
|
|
|
|
|
|
| 169 |
<div className={styles.pageContent}>
|
| 170 |
<Spin spinning={loading} className={styles.spin} size="large">
|
| 171 |
<Space
|
| 172 |
direction="vertical"
|
| 173 |
size={'middle'}
|
| 174 |
-
className={styles.chunkContainer
|
|
|
|
|
|
|
| 175 |
>
|
| 176 |
{data.map((item) => (
|
| 177 |
<ChunkCard
|
|
@@ -200,6 +205,7 @@ const Chunk = () => {
|
|
| 200 |
pageSize={pagination.pageSize}
|
| 201 |
pageSizeOptions={[10, 30, 60, 90]}
|
| 202 |
current={pagination.current}
|
|
|
|
| 203 |
total={total}
|
| 204 |
/>
|
| 205 |
</div>
|
|
|
|
| 1 |
+
import { useDeleteChunkByIds } from '@/hooks/knowledgeHook';
|
| 2 |
import { getOneNamespaceEffectsLoading } from '@/utils/storeUtil';
|
| 3 |
import type { PaginationProps } from 'antd';
|
| 4 |
import { Divider, Flex, Pagination, Space, Spin, message } from 'antd';
|
| 5 |
import { useCallback, useEffect, useState } from 'react';
|
| 6 |
import { useDispatch, useSearchParams, useSelector } from 'umi';
|
|
|
|
|
|
|
|
|
|
| 7 |
import ChunkCard from './components/chunk-card';
|
| 8 |
+
import CreatingModal from './components/chunk-creating-modal';
|
| 9 |
import ChunkToolBar from './components/chunk-toolbar';
|
| 10 |
// import DocumentPreview from './components/document-preview';
|
| 11 |
+
import classNames from 'classnames';
|
| 12 |
import DocumentPreview from './components/document-preview/preview';
|
| 13 |
import { useHandleChunkCardClick, useSelectDocumentInfo } from './hooks';
|
|
|
|
| 14 |
import { ChunkModelState } from './model';
|
| 15 |
|
| 16 |
+
import styles from './index.less';
|
| 17 |
interface PayloadType {
|
| 18 |
doc_id: string;
|
| 19 |
keywords?: string;
|
|
|
|
| 165 |
></ChunkToolBar>
|
| 166 |
<Divider></Divider>
|
| 167 |
<Flex flex={1} gap={'middle'}>
|
| 168 |
+
<Flex
|
| 169 |
+
vertical
|
| 170 |
+
className={isPdf ? styles.pagePdfWrapper : styles.pageWrapper}
|
| 171 |
+
>
|
| 172 |
<div className={styles.pageContent}>
|
| 173 |
<Spin spinning={loading} className={styles.spin} size="large">
|
| 174 |
<Space
|
| 175 |
direction="vertical"
|
| 176 |
size={'middle'}
|
| 177 |
+
className={classNames(styles.chunkContainer, {
|
| 178 |
+
[styles.chunkOtherContainer]: !isPdf,
|
| 179 |
+
})}
|
| 180 |
>
|
| 181 |
{data.map((item) => (
|
| 182 |
<ChunkCard
|
|
|
|
| 205 |
pageSize={pagination.pageSize}
|
| 206 |
pageSizeOptions={[10, 30, 60, 90]}
|
| 207 |
current={pagination.current}
|
| 208 |
+
size={'small'}
|
| 209 |
total={total}
|
| 210 |
/>
|
| 211 |
</div>
|
web/src/pages/add-knowledge/components/knowledge-testing/testing-control/index.tsx
CHANGED
|
@@ -55,7 +55,7 @@ const TestingControl = ({ form, handleTesting }: IProps) => {
|
|
| 55 |
>
|
| 56 |
<SimilaritySlider></SimilaritySlider>
|
| 57 |
<Form.Item<FieldType> label="Top k" name={'top_k'}>
|
| 58 |
-
<Slider marks={{ 0: 0, 2048: 2048 }}
|
| 59 |
</Form.Item>
|
| 60 |
<Card size="small" title="Test text">
|
| 61 |
<Form.Item<FieldType>
|
|
|
|
| 55 |
>
|
| 56 |
<SimilaritySlider></SimilaritySlider>
|
| 57 |
<Form.Item<FieldType> label="Top k" name={'top_k'}>
|
| 58 |
+
<Slider marks={{ 0: 0, 2048: 2048 }} max={2048} />
|
| 59 |
</Form.Item>
|
| 60 |
<Card size="small" title="Test text">
|
| 61 |
<Form.Item<FieldType>
|
web/src/pages/login/index.tsx
CHANGED
|
@@ -152,7 +152,7 @@ const Login = () => {
|
|
| 152 |
</Button>
|
| 153 |
{title === 'login' && (
|
| 154 |
<>
|
| 155 |
-
<Button
|
| 156 |
block
|
| 157 |
size="large"
|
| 158 |
onClick={toGoogle}
|
|
@@ -165,7 +165,7 @@ const Login = () => {
|
|
| 165 |
/>
|
| 166 |
Sign in with Google
|
| 167 |
</div>
|
| 168 |
-
</Button>
|
| 169 |
<Button
|
| 170 |
block
|
| 171 |
size="large"
|
|
|
|
| 152 |
</Button>
|
| 153 |
{title === 'login' && (
|
| 154 |
<>
|
| 155 |
+
{/* <Button
|
| 156 |
block
|
| 157 |
size="large"
|
| 158 |
onClick={toGoogle}
|
|
|
|
| 165 |
/>
|
| 166 |
Sign in with Google
|
| 167 |
</div>
|
| 168 |
+
</Button> */}
|
| 169 |
<Button
|
| 170 |
block
|
| 171 |
size="large"
|