fix(file-tree): propagate path simplification to parents

When all childs of a folder are selected in the tree, the selected path
was only simplifiyng one level. But if the reduction was also making its
own parent "fully selected" it was not correctly reporting only the
parent as selected
This commit is contained in:
Nicolas Meienberger 2026-01-02 15:49:09 +01:00
parent f836e2f9df
commit cd1d65167a
2 changed files with 43 additions and 36 deletions

View file

@ -182,7 +182,8 @@ export const FileTree = memo((props: Props) => {
if ( if (
item.fullPath.startsWith(`${selectedParentPath}/`) && item.fullPath.startsWith(`${selectedParentPath}/`) &&
!item.fullPath.startsWith(`${path}/`) && !item.fullPath.startsWith(`${path}/`) &&
item.fullPath !== path item.fullPath !== path &&
!path.startsWith(`${item.fullPath}/`)
) { ) {
newSelection.add(item.fullPath); newSelection.add(item.fullPath);
} }
@ -190,6 +191,9 @@ export const FileTree = memo((props: Props) => {
} }
} }
let changed = true;
while (changed) {
changed = false;
const childrenByParent = new Map<string, string[]>(); const childrenByParent = new Map<string, string[]>();
for (const selectedPath of newSelection) { for (const selectedPath of newSelection) {
const lastSlashIndex = selectedPath.lastIndexOf("/"); const lastSlashIndex = selectedPath.lastIndexOf("/");
@ -223,6 +227,9 @@ export const FileTree = memo((props: Props) => {
} }
// Add the parent // Add the parent
newSelection.add(parentPath); newSelection.add(parentPath);
changed = true;
break;
}
} }
} }
} }

View file

@ -57,7 +57,7 @@ export const VolumeFileBrowser = ({
if (fileBrowser.isLoading) { if (fileBrowser.isLoading) {
return ( return (
<div className="flex items-center justify-center h-full min-h-[200px]"> <div className="flex items-center justify-center h-full min-h-50">
<p className="text-muted-foreground">Loading files...</p> <p className="text-muted-foreground">Loading files...</p>
</div> </div>
); );
@ -65,7 +65,7 @@ export const VolumeFileBrowser = ({
if (error) { if (error) {
return ( return (
<div className="flex items-center justify-center h-full min-h-[200px]"> <div className="flex items-center justify-center h-full min-h-50">
<p className="text-destructive">Failed to load files: {(error as Error).message}</p> <p className="text-destructive">Failed to load files: {(error as Error).message}</p>
</div> </div>
); );
@ -73,7 +73,7 @@ export const VolumeFileBrowser = ({
if (fileBrowser.isEmpty) { if (fileBrowser.isEmpty) {
return ( return (
<div className="flex flex-col items-center justify-center h-full text-center p-8 min-h-[200px]"> <div className="flex flex-col items-center justify-center h-full text-center p-8 min-h-50">
<FolderOpen className="mb-4 h-12 w-12 text-muted-foreground" /> <FolderOpen className="mb-4 h-12 w-12 text-muted-foreground" />
<p className="text-muted-foreground">{emptyMessage}</p> <p className="text-muted-foreground">{emptyMessage}</p>
{emptyDescription && <p className="text-sm text-muted-foreground mt-2">{emptyDescription}</p>} {emptyDescription && <p className="text-sm text-muted-foreground mt-2">{emptyDescription}</p>}