Skip to content

Commit 0379f4b

Browse files
committed
Introduce file metrics
1 parent 1f143c9 commit 0379f4b

File tree

2 files changed

+66
-14
lines changed

2 files changed

+66
-14
lines changed

web/src/gui/deployments/files/FileExplorer.tsx

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ export const FolderEntry: FC<{
124124
}> = ({ node, name, isRoot = false, hideRoot = false }) => {
125125
const [isOpen, setIsOpen] = useState(true);
126126

127+
const { fileCount, directoryCount } = countFilesAndDirectories(node);
128+
127129
if (isRoot && hideRoot) {
128130
return (
129131
<ul className="" role="group">
@@ -142,22 +144,45 @@ export const FolderEntry: FC<{
142144
>
143145
<Collapsible.Trigger asChild>
144146
<div
145-
className="hover:bg-muted flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1"
147+
className="hover:bg-muted flex cursor-pointer items-center justify-between gap-2 rounded-sm px-2 py-1"
146148
role="button"
147149
tabIndex={0}
148150
>
149-
<LuChevronRight
150-
className={clsx(
151-
'transition-transform',
152-
isOpen && 'rotate-90'
151+
<div className="flex items-center gap-2">
152+
<LuChevronRight
153+
className={clsx(
154+
'transition-transform',
155+
isOpen && 'rotate-90'
156+
)}
157+
/>
158+
{isOpen ? (
159+
<LuFolderOpen className="text-blue-500" />
160+
) : (
161+
<LuFolderClosed className="text-blue-500" />
153162
)}
154-
/>
155-
{isOpen ? (
156-
<LuFolderOpen className="text-blue-500" />
157-
) : (
158-
<LuFolderClosed className="text-blue-500" />
159-
)}
160-
<span>{name}</span>
163+
<span>{name}</span>
164+
</div>
165+
<div className="text-muted flex justify-end gap-1.5">
166+
{[
167+
fileCount &&
168+
`${fileCount} file${
169+
fileCount > 1 ? 's' : ''
170+
}`,
171+
directoryCount &&
172+
`${directoryCount} director${
173+
directoryCount > 1 ? 'ies' : 'y'
174+
}`,
175+
]
176+
.filter(Boolean)
177+
.map((count) => (
178+
<div
179+
key={count}
180+
className="text-muted rounded-md border px-2"
181+
>
182+
{count}
183+
</div>
184+
))}
185+
</div>
161186
</div>
162187
</Collapsible.Trigger>
163188

@@ -239,3 +264,30 @@ export const FrameworkDetection: FC<{
239264
</div>
240265
);
241266
};
267+
268+
const countFilesAndDirectories = (
269+
node: TreeNode
270+
): {
271+
fileCount: number;
272+
directoryCount: number;
273+
} => {
274+
if (node.type !== 'directory') return { fileCount: 0, directoryCount: 0 };
275+
276+
let fileCount = 0;
277+
let directoryCount = 0;
278+
279+
for (const fileOrFolder of Object.values(node.files)) {
280+
if (fileOrFolder.type === 'file') {
281+
fileCount++;
282+
} else {
283+
const { fileCount: _fileCount, directoryCount: _directoryCount } =
284+
countFilesAndDirectories(fileOrFolder);
285+
286+
fileCount += _fileCount;
287+
directoryCount += _directoryCount;
288+
directoryCount++;
289+
}
290+
}
291+
292+
return { fileCount, directoryCount };
293+
};

web/src/gui/navigation/ThemeSwitcher.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const ThemeSwitcher = () => {
2121
};
2222

2323
return (
24-
<div className="bg-muted mx-auto flex size-full gap-1 rounded-xl">
24+
<div className="bg-muted mx-auto flex size-full gap-1 rounded-sm shadow-sm">
2525
{(
2626
[
2727
['light', <FiSun key="light" />],
@@ -38,7 +38,7 @@ export const ThemeSwitcher = () => {
3838
}}
3939
className={cn(
4040
currentTheme === theme && 'bg-hover',
41-
'h-full flex items-center px-1 aspect-square rounded-full'
41+
'h-full flex items-center p-2 aspect-square rounded-md'
4242
)}
4343
>
4444
{icon}

0 commit comments

Comments
 (0)