From 79c09e53e98237812622653ab2d26c12fcb8fbbd Mon Sep 17 00:00:00 2001
From: joonhoekim <26rote@gmail.com>
Date: Thu, 23 Oct 2025 19:02:34 +0900
Subject: (김준회) 데이터룸 트리 검색시 재귀적으로 자식들도 검색하도록 로직
 변경
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 components/file-manager/FileManager.tsx | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

(limited to 'components/file-manager/FileManager.tsx')

diff --git a/components/file-manager/FileManager.tsx b/components/file-manager/FileManager.tsx
index b0626eaf..7c5a3771 100644
--- a/components/file-manager/FileManager.tsx
+++ b/components/file-manager/FileManager.tsx
@@ -1048,9 +1048,35 @@ export function FileManager({ projectId }: FileManagerProps) {
     item.name.toLowerCase().includes(searchQuery.toLowerCase())
   );
 
-  const filteredTreeItems = treeItems.filter(item =>
-    item.name.toLowerCase().includes(searchQuery.toLowerCase())
-  );
+  // 재귀적으로 트리 항목 검색
+  const searchTreeItems = (items: FileItem[], query: string): FileItem[] => {
+    const result: FileItem[] = [];
+    
+    for (const item of items) {
+      // 현재 항목이 검색어와 일치하는지 확인
+      const matches = item.name.toLowerCase().includes(query.toLowerCase());
+      
+      // 하위 항목 재귀적으로 검색
+      let childrenMatches: FileItem[] = [];
+      if (item.children && item.children.length > 0) {
+        childrenMatches = searchTreeItems(item.children, query);
+      }
+      
+      // 현재 항목이나 하위 항목 중 하나라도 일치하면 결과에 추가
+      if (matches || childrenMatches.length > 0) {
+        // 하위 항목이 일치하는 경우 현재 항목도 표시하기 위해 확장된 상태로 복제
+        const clonedItem = { ...item };
+        if (childrenMatches.length > 0) {
+          clonedItem.children = childrenMatches;
+        }
+        result.push(clonedItem);
+      }
+    }
+    
+    return result;
+  };
+
+  const filteredTreeItems = searchTreeItems(treeItems, searchQuery);
 
   // Format file size
   const formatFileSize = (bytes?: number) => {
-- 
cgit v1.2.3

