juanmcampos commited on
Commit
6e3b5dc
·
1 Parent(s): 4c81e15

fix: import folder filtering

Browse files
app/components/chat/ImportFolderButton.tsx CHANGED
@@ -16,35 +16,40 @@ export const ImportFolderButton: React.FC<ImportFolderButtonProps> = ({ classNam
16
  const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
17
  const allFiles = Array.from(e.target.files || []);
18
 
19
- if (allFiles.length > MAX_FILES) {
20
- const error = new Error(`Too many files: ${allFiles.length}`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  logStore.logError('File import failed - too many files', error, {
22
- fileCount: allFiles.length,
23
  maxFiles: MAX_FILES,
24
  });
25
  toast.error(
26
- `This folder contains ${allFiles.length.toLocaleString()} files. This product is not yet optimized for very large projects. Please select a folder with fewer than ${MAX_FILES.toLocaleString()} files.`,
27
  );
28
 
29
  return;
30
  }
31
 
32
- const folderName = allFiles[0]?.webkitRelativePath.split('/')[0] || 'Unknown Folder';
33
  setIsLoading(true);
34
 
35
  const loadingToast = toast.loading(`Importing ${folderName}...`);
36
 
37
  try {
38
- const filteredFiles = allFiles.filter((file) => shouldIncludeFile(file.webkitRelativePath));
39
-
40
- if (filteredFiles.length === 0) {
41
- const error = new Error('No valid files found');
42
- logStore.logError('File import failed - no valid files', error, { folderName });
43
- toast.error('No files found in the selected folder');
44
-
45
- return;
46
- }
47
-
48
  const fileChecks = await Promise.all(
49
  filteredFiles.map(async (file) => ({
50
  file,
 
16
  const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
17
  const allFiles = Array.from(e.target.files || []);
18
 
19
+ const filteredFiles = allFiles.filter((file) => {
20
+ const path = file.webkitRelativePath.split('/').slice(1).join('/');
21
+ const include = shouldIncludeFile(path);
22
+
23
+ return include;
24
+ });
25
+
26
+ if (filteredFiles.length === 0) {
27
+ const error = new Error('No valid files found');
28
+ logStore.logError('File import failed - no valid files', error, { folderName: 'Unknown Folder' });
29
+ toast.error('No files found in the selected folder');
30
+
31
+ return;
32
+ }
33
+
34
+ if (filteredFiles.length > MAX_FILES) {
35
+ const error = new Error(`Too many files: ${filteredFiles.length}`);
36
  logStore.logError('File import failed - too many files', error, {
37
+ fileCount: filteredFiles.length,
38
  maxFiles: MAX_FILES,
39
  });
40
  toast.error(
41
+ `This folder contains ${filteredFiles.length.toLocaleString()} files. This product is not yet optimized for very large projects. Please select a folder with fewer than ${MAX_FILES.toLocaleString()} files.`,
42
  );
43
 
44
  return;
45
  }
46
 
47
+ const folderName = filteredFiles[0]?.webkitRelativePath.split('/')[0] || 'Unknown Folder';
48
  setIsLoading(true);
49
 
50
  const loadingToast = toast.loading(`Importing ${folderName}...`);
51
 
52
  try {
 
 
 
 
 
 
 
 
 
 
53
  const fileChecks = await Promise.all(
54
  filteredFiles.map(async (file) => ({
55
  file,