Skip to content

Commit 8fab6fe

Browse files
committed
Address comments
Signed-off-by: Daishan Peng <[email protected]>
1 parent 771d602 commit 8fab6fe

File tree

4 files changed

+100
-67
lines changed

4 files changed

+100
-67
lines changed

components/edit/configure.tsx

+32-30
Original file line numberDiff line numberDiff line change
@@ -229,39 +229,41 @@ const Configure: React.FC<ConfigureProps> = ({ collapsed }) => {
229229
>
230230
<div className="grid grid-cols-1 gap-2 w-full mb-2">
231231
<div className="max-h-[30vh] flex flex-col space-y-2 overflow-auto">
232-
{Array.from(droppedFiles.entries()).map((fileDetail, i) => (
233-
<div key={i} className="flex space-x-2">
234-
<div className="flex flex-row w-full border-2 justify-between truncate dark:border-zinc-700 text-sm pl-2 rounded-lg">
235-
<div className="flex items-center">
236-
{fileDetail[1].type === 'local' && (
237-
<RiFileSearchLine className="justify-start mr-2" />
238-
)}
239-
{fileDetail[1].type === 'notion' && (
240-
<RiNotionFill className="justify-start mr-2" />
241-
)}
242-
<div className="flex flex-row justify-start overflow-x-auto">
243-
<p className="capitalize text-left">
244-
{fileDetail[1].fileName}
245-
</p>
246-
<p className="text-xs text-zinc-400 ml-2">{`${fileDetail[1].size} KB`}</p>
232+
{Array.from(droppedFiles.entries()).map(
233+
([key, fileDetail], _) => (
234+
<div key={key} className="flex space-x-2">
235+
<div className="flex flex-row w-full border-2 justify-between truncate dark:border-zinc-700 text-sm pl-2 rounded-lg">
236+
<div className="flex items-center">
237+
{fileDetail.type === 'local' && (
238+
<RiFileSearchLine className="justify-start mr-2" />
239+
)}
240+
{fileDetail.type === 'notion' && (
241+
<RiNotionFill className="justify-start mr-2" />
242+
)}
243+
<div className="flex flex-row justify-start overflow-x-auto">
244+
<p className="capitalize text-left">
245+
{fileDetail.fileName}
246+
</p>
247+
<p className="text-xs text-zinc-400 ml-2">{`${fileDetail.size} KB`}</p>
248+
</div>
247249
</div>
250+
<Button
251+
variant="light"
252+
isIconOnly
253+
size="sm"
254+
startContent={<GoTrash />}
255+
onPress={() => {
256+
setDroppedFiles((prev) => {
257+
const newMap = new Map(prev);
258+
newMap.delete(key);
259+
return newMap;
260+
});
261+
}}
262+
/>
248263
</div>
249-
<Button
250-
variant="light"
251-
isIconOnly
252-
size="sm"
253-
startContent={<GoTrash />}
254-
onPress={() => {
255-
setDroppedFiles((prev) => {
256-
const newMap = new Map(prev);
257-
newMap.delete(fileDetail[0]);
258-
return newMap;
259-
});
260-
}}
261-
/>
262264
</div>
263-
</div>
264-
))}
265+
)
266+
)}
265267
</div>
266268
<div className="flex justify-end mt-2">
267269
{droppedFiles?.size > 0 && !ingesting && !ingestionError && (

components/knowledge/FileModal.tsx

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
Button,
23
Modal,
34
ModalBody,
45
ModalContent,
@@ -20,16 +21,22 @@ const FileModal = ({ isOpen, onClose, handleAddFile }: FileModalProps) => {
2021
const notionModal = useDisclosure();
2122
const [isSyncing, setIsSyncing] = useState(false);
2223
const [notionConfigured, setNotionConfigured] = useState(false);
24+
const [notionSyncError, setNotionSyncError] = useState('');
2325

2426
const onClickNotion = async () => {
2527
onClose();
2628
notionModal.onOpen();
2729
const isConfigured = await isNotionConfigured();
2830
if (!isConfigured) {
2931
setIsSyncing(true);
30-
await runNotionSync(false);
31-
setIsSyncing(false);
32-
setNotionConfigured(true);
32+
try {
33+
await runNotionSync(false);
34+
setNotionConfigured(true);
35+
} catch (e) {
36+
setNotionSyncError((e as Error).toString());
37+
} finally {
38+
setIsSyncing(false);
39+
}
3340
}
3441
};
3542

@@ -44,7 +51,7 @@ const FileModal = ({ isOpen, onClose, handleAddFile }: FileModalProps) => {
4451
>
4552
<ModalContent className="p-4">
4653
<ModalBody>
47-
<div
54+
<Button
4855
onClick={() => {
4956
handleAddFile();
5057
onClose();
@@ -55,17 +62,17 @@ const FileModal = ({ isOpen, onClose, handleAddFile }: FileModalProps) => {
5562
<span className="text-sm font-semibold leading-6">
5663
Add Local Files
5764
</span>
58-
</div>
65+
</Button>
5966

60-
<div
67+
<Button
6168
onClick={onClickNotion}
6269
className="flex w-full items-center justify-center gap-3 rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus-visible:ring-transparent hover:cursor-pointer"
6370
>
6471
<Image className="h-5 w-5" src="notion.svg" alt="Notion Icon" />
6572
<span className="text-sm font-semibold leading-6">
6673
Sync From Notion
6774
</span>
68-
</div>
75+
</Button>
6976
</ModalBody>
7077
</ModalContent>
7178
</Modal>
@@ -76,6 +83,8 @@ const FileModal = ({ isOpen, onClose, handleAddFile }: FileModalProps) => {
7683
setIsSyncing={setIsSyncing}
7784
notionConfigured={notionConfigured}
7885
setNotionConfigured={setNotionConfigured}
86+
syncError={notionSyncError}
87+
setSyncError={setNotionSyncError}
7988
/>
8089
</>
8190
);

components/knowledge/Notion.tsx

+52-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
Button,
3+
Input,
34
Modal,
45
ModalBody,
56
ModalContent,
@@ -20,7 +21,7 @@ import {
2021
isNotionConfigured,
2122
runNotionSync,
2223
} from '@/actions/knowledge/notion';
23-
import { CiShare1 } from 'react-icons/ci';
24+
import { CiSearch, CiShare1 } from 'react-icons/ci';
2425
import { EditContext } from '@/contexts/edit';
2526
import { importFiles } from '@/actions/knowledge/filehelper';
2627

@@ -31,6 +32,8 @@ interface NotionFileModalProps {
3132
setIsSyncing: React.Dispatch<React.SetStateAction<boolean>>;
3233
notionConfigured: boolean;
3334
setNotionConfigured: React.Dispatch<React.SetStateAction<boolean>>;
35+
syncError: string;
36+
setSyncError: React.Dispatch<React.SetStateAction<string>>;
3437
}
3538

3639
export const NotionFileModal = ({
@@ -40,14 +43,16 @@ export const NotionFileModal = ({
4043
setNotionConfigured,
4144
isSyncing,
4245
setIsSyncing,
46+
syncError,
47+
setSyncError,
4348
}: NotionFileModalProps) => {
4449
const { droppedFiles, setDroppedFiles } = useContext(EditContext);
50+
const [searchQuery, setSearchQuery] = useState<string>('');
4551

4652
const [notionFiles, setNotionFiles] = useState<
4753
Map<string, { url: string; fileName: string }>
4854
>(new Map());
4955

50-
const [syncError, setSyncError] = useState('');
5156
const [selectedFile, setSelectedFile] = useState<string[]>(
5257
Array.from(droppedFiles.keys())
5358
);
@@ -76,13 +81,13 @@ export const NotionFileModal = ({
7681
const files = await importFiles(selectedFile, 'notion');
7782
setDroppedFiles((prev) => {
7883
const newMap = new Map(prev);
79-
for (const file of Array.from(newMap.entries())) {
80-
if (file[1].type === 'notion') {
81-
newMap.delete(file[0]);
84+
for (const [key, file] of Array.from(newMap.entries())) {
85+
if (file.type === 'notion') {
86+
newMap.delete(key);
8287
}
8388
}
84-
for (const file of Array.from(files.entries())) {
85-
newMap.set(file[0], file[1]);
89+
for (const [key, file] of Array.from(files.entries())) {
90+
newMap.set(key, file);
8691
}
8792
return newMap;
8893
});
@@ -146,12 +151,23 @@ export const NotionFileModal = ({
146151
</div>
147152
</ModalHeader>
148153
<ModalBody>
154+
<Input
155+
className="w-[20%] flex justify-end"
156+
placeholder="Search"
157+
size="sm"
158+
value={searchQuery}
159+
onChange={(e) => {
160+
setSearchQuery(e.target.value);
161+
}}
162+
startContent={<CiSearch />}
163+
/>
149164
{notionConfigured && notionFiles.size > 0 ? (
150165
<div className="flex flex-col gap-1">
151166
<Table
152167
selectionMode="multiple"
153168
selectionBehavior="toggle"
154169
aria-label="notion-files"
170+
isCompact={true}
155171
selectedKeys={selectedFile}
156172
onSelectionChange={(selected) => {
157173
handleSelectedFileChange(selected);
@@ -162,26 +178,34 @@ export const NotionFileModal = ({
162178
<TableColumn>Link</TableColumn>
163179
</TableHeader>
164180
<TableBody>
165-
{Array.from(notionFiles.entries()).map(([key, value]) => (
166-
<TableRow key={key}>
167-
<TableCell>
168-
<div className="flex flex-col">
169-
<p>{value.fileName}</p>
170-
</div>
171-
</TableCell>
172-
<TableCell>
173-
<Button
174-
isIconOnly
175-
color="primary"
176-
variant="flat"
177-
startContent={<CiShare1 />}
178-
onClick={() => {
179-
window.open(value.url);
180-
}}
181-
/>
182-
</TableCell>
183-
</TableRow>
184-
))}
181+
{Array.from(notionFiles.entries())
182+
.filter(([_, file]) => {
183+
if (!searchQuery) return true;
184+
return file.fileName
185+
.toLowerCase()
186+
.includes(searchQuery.toLowerCase());
187+
})
188+
.map(([key, value]) => (
189+
<TableRow key={key}>
190+
<TableCell>
191+
<div className="flex flex-col">
192+
<p>{value.fileName}</p>
193+
</div>
194+
</TableCell>
195+
<TableCell>
196+
<Button
197+
isIconOnly
198+
size="sm"
199+
color="primary"
200+
variant="flat"
201+
startContent={<CiShare1 />}
202+
onClick={() => {
203+
window.open(value.url);
204+
}}
205+
/>
206+
</TableCell>
207+
</TableRow>
208+
))}
185209
</TableBody>
186210
</Table>
187211
</div>
@@ -194,7 +218,7 @@ export const NotionFileModal = ({
194218
)}
195219
</ModalBody>
196220
<ModalFooter>
197-
<Button color="primary" onClick={onClickImport}>
221+
<Button color="primary" size="sm" onClick={onClickImport}>
198222
Import
199223
</Button>
200224
</ModalFooter>

contexts/edit.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ const EditContextProvider: React.FC<EditContextProps> = ({
147147
setFiles();
148148
}, [scriptId]);
149149

150-
useEffect(() => {}, [droppedFiles]);
151-
152150
const ingest = useCallback(async () => {
153151
setIngesting(true);
154152
const first = await firstIngestion(scriptId.toString(), droppedFiles);

0 commit comments

Comments
 (0)