From 9759a29d75124c4713a63817cbddf0389fc5c360 Mon Sep 17 00:00:00 2001 From: Jimmy Domagala-Tang Date: Fri, 22 Sep 2023 10:10:42 -0400 Subject: [PATCH] Merge pull request #14703 from overleaf/jdt-collapse-history-folders collapse folders with no changes in history view GitOrigin-RevId: 120845bfb3d645ab9ebb287b00516b5a0f6666c0 --- .../file-tree/history-file-tree-folder.tsx | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/services/web/frontend/js/features/history/components/file-tree/history-file-tree-folder.tsx b/services/web/frontend/js/features/history/components/file-tree/history-file-tree-folder.tsx index 1ef4866996..52e572682d 100644 --- a/services/web/frontend/js/features/history/components/file-tree/history-file-tree-folder.tsx +++ b/services/web/frontend/js/features/history/components/file-tree/history-file-tree-folder.tsx @@ -13,6 +13,22 @@ type HistoryFileTreeFolderProps = { docs: HistoryDoc[] } +function hasChanges(fileTree: HistoryFileTree): boolean { + const hasSameLevelChanges = fileTree.docs?.some( + (doc: HistoryDoc) => (doc as any).operation !== undefined + ) + if (hasSameLevelChanges) { + return true + } + const hasNestedChanges = fileTree.folders?.some(folder => { + return hasChanges(folder) + }) + if (hasNestedChanges) { + return true + } + return false +} + function HistoryFileTreeFolder({ name, folders, @@ -20,7 +36,9 @@ function HistoryFileTreeFolder({ }: HistoryFileTreeFolderProps) { const { t } = useTranslation() - const [expanded, setExpanded] = useState(true) + const [expanded, setExpanded] = useState(() => { + return hasChanges({ name, folders, docs }) + }) const icons = ( <>