Browse Source

fix(library): "All Files" view now shows files inside subfolders (#1499)

  The File Manager sidebar's "All Files" entry was passing
  include_root=true to GET /library/files because the boolean was
  derived from `selectedFolderId === null`. The backend's include_root
  flag means *root files only* when folder_id is null, so a library
  where every file lived in a subfolder rendered as empty.

  Pass include_root=false from "All Files" so the backend returns every
  active file across folders. Adds a regression test that mounts the
  page, mocks the endpoint to distinguish include_root=true vs false,
  and asserts both a root file and a nested file appear.
maziggy 4 days ago
parent
commit
32fcd85827

File diff suppressed because it is too large
+ 1 - 0
CHANGELOG.md


+ 51 - 0
frontend/src/__tests__/pages/FileManagerPage.test.tsx

@@ -932,4 +932,55 @@ describe('FileManagerPage', () => {
       expect(setItemMock).toHaveBeenCalledWith('library-collapse-folders', 'false');
       expect(setItemMock).toHaveBeenCalledWith('library-collapse-folders', 'false');
     });
     });
   });
   });
+
+  describe('"All Files" view (#1499)', () => {
+    it('requests every file (include_root=false) so subfolder contents are visible', async () => {
+      const rootFile = {
+        id: 10,
+        filename: 'root-file.3mf',
+        file_path: '/library/root-file.3mf',
+        file_size: 1024,
+        file_type: '3mf',
+        folder_id: null,
+        thumbnail_path: null,
+        print_name: 'Root File',
+        print_time_seconds: 0,
+        print_count: 0,
+        duplicate_count: 0,
+        created_at: '2024-01-01T00:00:00Z',
+      };
+      const nestedFile = {
+        ...rootFile,
+        id: 11,
+        filename: 'nested-file.3mf',
+        file_path: '/library/Functional Parts/nested-file.3mf',
+        folder_id: 1,
+        print_name: 'Nested File',
+      };
+
+      const includeRootValues: string[] = [];
+      server.use(
+        http.get('/api/v1/library/files', ({ request }) => {
+          const url = new URL(request.url);
+          const includeRoot = url.searchParams.get('include_root');
+          includeRootValues.push(includeRoot ?? '');
+          // Mirror the backend: include_root=false returns everything; true
+          // returns only files with folder_id IS NULL.
+          if (includeRoot === 'false') {
+            return HttpResponse.json([rootFile, nestedFile]);
+          }
+          return HttpResponse.json([rootFile]);
+        }),
+      );
+
+      render(<FileManagerPage />);
+
+      await waitFor(() => {
+        expect(screen.getByText('Root File')).toBeInTheDocument();
+        expect(screen.getByText('Nested File')).toBeInTheDocument();
+      });
+      // Sanity-check: the buggy call would have sent include_root=true here.
+      expect(includeRootValues).toContain('false');
+    });
+  });
 });
 });

+ 4 - 1
frontend/src/pages/FileManagerPage.tsx

@@ -1049,7 +1049,10 @@ export function FileManagerPage() {
 
 
   const { data: files, isLoading: filesLoading } = useQuery({
   const { data: files, isLoading: filesLoading } = useQuery({
     queryKey: ['library-files', selectedFolderId],
     queryKey: ['library-files', selectedFolderId],
-    queryFn: () => api.getLibraryFiles(selectedFolderId, selectedFolderId === null),
+    // "All Files" (selectedFolderId === null) lists every file across folders,
+    // so include_root must be false — true would scope the result to files at
+    // the library root only and hide everything nested in subfolders (#1499).
+    queryFn: () => api.getLibraryFiles(selectedFolderId, false),
   });
   });
 
 
   const { data: stats } = useQuery({
   const { data: stats } = useQuery({

File diff suppressed because it is too large
+ 0 - 0
static/assets/index-B5qvYtQq.js


+ 1 - 1
static/index.html

@@ -26,7 +26,7 @@
 
 
     <!-- Splash screens for iOS -->
     <!-- Splash screens for iOS -->
     <link rel="apple-touch-startup-image" href="/img/android-chrome-512x512.png" />
     <link rel="apple-touch-startup-image" href="/img/android-chrome-512x512.png" />
-    <script type="module" crossorigin src="/assets/index-BL4kzp1A.js"></script>
+    <script type="module" crossorigin src="/assets/index-B5qvYtQq.js"></script>
     <link rel="stylesheet" crossorigin href="/assets/index-BzucE4G0.css">
     <link rel="stylesheet" crossorigin href="/assets/index-BzucE4G0.css">
   </head>
   </head>
   <body>
   <body>

Some files were not shown because too many files changed in this diff