balibabu
commited on
Commit
·
71d280d
1
Parent(s):
633d85b
feat: Add sidebar to SearchPage #2247 (#2267)
Browse files### What problem does this PR solve?
feat: Add sidebar to SearchPage #2247
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
web/src/pages/search/index.less
CHANGED
|
@@ -1,17 +1,23 @@
|
|
| 1 |
.searchSide {
|
| 2 |
-
|
| 3 |
-
height: 100vh;
|
| 4 |
position: fixed !important;
|
| 5 |
inset-inline-start: 0;
|
| 6 |
-
top:
|
| 7 |
bottom: 0;
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
.checkGroup {
|
| 10 |
width: 100%;
|
| 11 |
height: 100%;
|
| 12 |
}
|
| 13 |
.list {
|
| 14 |
width: 100%;
|
|
|
|
|
|
|
| 15 |
}
|
| 16 |
.checkbox {
|
| 17 |
width: 100%;
|
|
|
|
| 1 |
.searchSide {
|
| 2 |
+
height: calc(100vh - 72px);
|
|
|
|
| 3 |
position: fixed !important;
|
| 4 |
inset-inline-start: 0;
|
| 5 |
+
top: 72px;
|
| 6 |
bottom: 0;
|
| 7 |
|
| 8 |
+
.modelForm {
|
| 9 |
+
display: flex;
|
| 10 |
+
padding: 24px;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
.checkGroup {
|
| 14 |
width: 100%;
|
| 15 |
height: 100%;
|
| 16 |
}
|
| 17 |
.list {
|
| 18 |
width: 100%;
|
| 19 |
+
height: 100%;
|
| 20 |
+
overflow: auto;
|
| 21 |
}
|
| 22 |
.checkbox {
|
| 23 |
width: 100%;
|
web/src/pages/search/index.tsx
CHANGED
|
@@ -1,42 +1,13 @@
|
|
| 1 |
-
import {
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
|
| 6 |
-
import styles from './index.less';
|
| 7 |
-
|
| 8 |
-
const { Header, Content, Footer, Sider } = Layout;
|
| 9 |
|
| 10 |
const SearchPage = () => {
|
| 11 |
-
const { list } = useNextFetchKnowledgeList();
|
| 12 |
-
|
| 13 |
-
const handleChange = useCallback((checkedValue: CheckboxValueType[]) => {
|
| 14 |
-
console.log('🚀 ~ handleChange ~ args:', checkedValue);
|
| 15 |
-
}, []);
|
| 16 |
-
|
| 17 |
return (
|
| 18 |
<Layout hasSider>
|
| 19 |
-
<
|
| 20 |
-
<Checkbox.Group className={styles.checkGroup} onChange={handleChange}>
|
| 21 |
-
<List
|
| 22 |
-
bordered
|
| 23 |
-
dataSource={list}
|
| 24 |
-
className={styles.list}
|
| 25 |
-
renderItem={(item) => (
|
| 26 |
-
<List.Item>
|
| 27 |
-
<Checkbox value={item.id} className={styles.checkbox}>
|
| 28 |
-
<Typography.Text
|
| 29 |
-
ellipsis={{ tooltip: item.name }}
|
| 30 |
-
className={styles.knowledgeName}
|
| 31 |
-
>
|
| 32 |
-
{item.name}
|
| 33 |
-
</Typography.Text>
|
| 34 |
-
</Checkbox>
|
| 35 |
-
</List.Item>
|
| 36 |
-
)}
|
| 37 |
-
/>
|
| 38 |
-
</Checkbox.Group>
|
| 39 |
-
</Sider>
|
| 40 |
<Layout style={{ marginInlineStart: 200 }}>
|
| 41 |
<Header style={{ padding: 0 }} />
|
| 42 |
<Content style={{ margin: '24px 16px 0', overflow: 'initial' }}>
|
|
|
|
| 1 |
+
import { Layout } from 'antd';
|
| 2 |
+
import React from 'react';
|
| 3 |
+
import SearchSidebar from './sidebar';
|
| 4 |
|
| 5 |
+
const { Header, Content, Footer } = Layout;
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
const SearchPage = () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
return (
|
| 9 |
<Layout hasSider>
|
| 10 |
+
<SearchSidebar></SearchSidebar>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
<Layout style={{ marginInlineStart: 200 }}>
|
| 12 |
<Header style={{ padding: 0 }} />
|
| 13 |
<Content style={{ margin: '24px 16px 0', overflow: 'initial' }}>
|
web/src/pages/search/sidebar.tsx
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useNextFetchKnowledgeList } from '@/hooks/knowledge-hooks';
|
| 2 |
+
import type { CheckboxProps } from 'antd';
|
| 3 |
+
import { Checkbox, Layout, List, Typography } from 'antd';
|
| 4 |
+
import { CheckboxValueType } from 'antd/es/checkbox/Group';
|
| 5 |
+
import { useCallback, useMemo, useState } from 'react';
|
| 6 |
+
|
| 7 |
+
import { CheckboxChangeEvent } from 'antd/es/checkbox';
|
| 8 |
+
import styles from './index.less';
|
| 9 |
+
|
| 10 |
+
const { Sider } = Layout;
|
| 11 |
+
|
| 12 |
+
const SearchSidebar = () => {
|
| 13 |
+
const { list } = useNextFetchKnowledgeList();
|
| 14 |
+
const ids = useMemo(() => list.map((x) => x.id), [list]);
|
| 15 |
+
|
| 16 |
+
const [checkedList, setCheckedList] = useState<string[]>(ids);
|
| 17 |
+
|
| 18 |
+
const checkAll = list.length === checkedList.length;
|
| 19 |
+
|
| 20 |
+
const indeterminate =
|
| 21 |
+
checkedList.length > 0 && checkedList.length < list.length;
|
| 22 |
+
|
| 23 |
+
const onChange = useCallback((list: CheckboxValueType[]) => {
|
| 24 |
+
setCheckedList(list as string[]);
|
| 25 |
+
}, []);
|
| 26 |
+
|
| 27 |
+
const onCheckAllChange: CheckboxProps['onChange'] = useCallback(
|
| 28 |
+
(e: CheckboxChangeEvent) => {
|
| 29 |
+
setCheckedList(e.target.checked ? ids : []);
|
| 30 |
+
},
|
| 31 |
+
[ids],
|
| 32 |
+
);
|
| 33 |
+
|
| 34 |
+
return (
|
| 35 |
+
<Sider className={styles.searchSide} theme={'light'} width={260}>
|
| 36 |
+
<Checkbox
|
| 37 |
+
className={styles.modelForm}
|
| 38 |
+
indeterminate={indeterminate}
|
| 39 |
+
onChange={onCheckAllChange}
|
| 40 |
+
checked={checkAll}
|
| 41 |
+
>
|
| 42 |
+
Check all
|
| 43 |
+
</Checkbox>
|
| 44 |
+
<Checkbox.Group
|
| 45 |
+
className={styles.checkGroup}
|
| 46 |
+
onChange={onChange}
|
| 47 |
+
value={checkedList}
|
| 48 |
+
>
|
| 49 |
+
<List
|
| 50 |
+
bordered
|
| 51 |
+
dataSource={list}
|
| 52 |
+
className={styles.list}
|
| 53 |
+
renderItem={(item) => (
|
| 54 |
+
<List.Item>
|
| 55 |
+
<Checkbox value={item.id} className={styles.checkbox}>
|
| 56 |
+
<Typography.Text
|
| 57 |
+
ellipsis={{ tooltip: item.name }}
|
| 58 |
+
className={styles.knowledgeName}
|
| 59 |
+
>
|
| 60 |
+
{item.name}
|
| 61 |
+
</Typography.Text>
|
| 62 |
+
</Checkbox>
|
| 63 |
+
</List.Item>
|
| 64 |
+
)}
|
| 65 |
+
/>
|
| 66 |
+
</Checkbox.Group>
|
| 67 |
+
</Sider>
|
| 68 |
+
);
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
export default SearchSidebar;
|