From 221fd18820a37d52bc5fde817024f0a7e2d3bc1e Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Wed, 18 Feb 2026 19:58:20 +0100 Subject: [PATCH] chore: pr feedbacks --- .../file-browsers/snapshot-tree-browser.tsx | 34 +++++++++++++++++-- app/client/components/path-selector.tsx | 17 +++------- app/client/components/restore-form.tsx | 15 +------- .../local-repository-form.tsx | 17 ++-------- .../volume-forms/directory-form.tsx | 16 ++------- app/utils/common-ancestor.ts | 2 +- 6 files changed, 42 insertions(+), 59 deletions(-) diff --git a/app/client/components/file-browsers/snapshot-tree-browser.tsx b/app/client/components/file-browsers/snapshot-tree-browser.tsx index faa2db6f..3eb93026 100644 --- a/app/client/components/file-browsers/snapshot-tree-browser.tsx +++ b/app/client/components/file-browsers/snapshot-tree-browser.tsx @@ -1,4 +1,4 @@ -import { useCallback } from "react"; +import { useCallback, useMemo } from "react"; import { useQuery, useQueryClient } from "@tanstack/react-query"; import { listSnapshotFilesOptions } from "~/client/api-client/@tanstack/react-query.gen"; import { FileBrowser, type FileBrowserUiProps } from "~/client/components/file-browsers/file-browser"; @@ -28,6 +28,7 @@ export const SnapshotTreeBrowser = ({ enabled = true, ...uiProps }: SnapshotTreeBrowserProps) => { + const { selectedPaths, onSelectionChange, ...fileBrowserUiProps } = uiProps; const queryClient = useQueryClient(); const normalizedBasePath = normalizeAbsolutePath(basePath); @@ -60,6 +61,31 @@ export const SnapshotTreeBrowser = ({ [normalizedBasePath], ); + const displaySelectedPaths = useMemo(() => { + if (!selectedPaths) return undefined; + + const displayPaths = new Set(); + for (const fullPath of selectedPaths) { + displayPaths.add(stripBasePath(fullPath)); + } + + return displayPaths; + }, [selectedPaths, stripBasePath]); + + const handleSelectionChange = useCallback( + (nextDisplayPaths: Set) => { + if (!onSelectionChange) return; + + const nextFullPaths = new Set(); + for (const displayPath of nextDisplayPaths) { + nextFullPaths.add(addBasePath(displayPath)); + } + + onSelectionChange(nextFullPaths); + }, + [onSelectionChange, addBasePath], + ); + const fileBrowser = useFileBrowser({ initialData: data, isLoading, @@ -102,7 +128,7 @@ export const SnapshotTreeBrowser = ({ return ( ); }; diff --git a/app/client/components/path-selector.tsx b/app/client/components/path-selector.tsx index fc490d94..8ad41779 100644 --- a/app/client/components/path-selector.tsx +++ b/app/client/components/path-selector.tsx @@ -1,5 +1,5 @@ import { useState } from "react"; -import { LocalFileBrowser } from "./file-browsers/local-file-browser"; +import { DirectoryBrowser } from "./file-browsers/directory-browser"; import { Button } from "./ui/button"; type Props = { @@ -14,21 +14,12 @@ export const PathSelector = ({ value, onChange }: Props) => { if (showBrowser) { return (
- { + { onChange(path); setShowBrowser(false); }} - showSelectedPathFooter - selectedPath={value} - loadingMessage="Loading directories..." - emptyMessage="No subdirectories found" />
) : ( - field.onChange(path)} - selectedFolder={field.value} - showSelectedPathFooter - selectedPath={field.value} - loadingMessage="Loading directories..." - emptyMessage="No subdirectories found" - /> + )} Browse and select a directory on the host filesystem to track. diff --git a/app/utils/common-ancestor.ts b/app/utils/common-ancestor.ts index 3065bfd4..5263c5de 100644 --- a/app/utils/common-ancestor.ts +++ b/app/utils/common-ancestor.ts @@ -5,7 +5,7 @@ export const findCommonAncestor = (paths: string[]): string => { const splitPaths = paths.map((path) => path.split("/").filter(Boolean)); const minLength = Math.min(...splitPaths.map((parts) => parts.length)); - let commonParts: string[] = []; + const commonParts: string[] = []; for (let i = 0; i < minLength; i++) { const partSet = new Set(splitPaths.map((parts) => parts[i])); if (partSet.size === 1) {