fix: select kind for synthetic folders
This commit is contained in:
parent
48a55c0183
commit
10d5bda2ad
3 changed files with 42 additions and 1 deletions
|
|
@ -70,6 +70,7 @@ describe("RestoreForm", () => {
|
||||||
expect(restoreRequestBody).toEqual({
|
expect(restoreRequestBody).toEqual({
|
||||||
snapshotId: "snap-1",
|
snapshotId: "snap-1",
|
||||||
include: ["/mnt/project"],
|
include: ["/mnt/project"],
|
||||||
|
selectedItemKind: "dir",
|
||||||
overwrite: "always",
|
overwrite: "always",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,26 @@ describe("SnapshotTreeBrowser", () => {
|
||||||
expect(await screen.findByRole("button", { name: "project" })).toBeTruthy();
|
expect(await screen.findByRole("button", { name: "project" })).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("renders a single file when no display base path is available", async () => {
|
||||||
|
const requests = mockListSnapshotFiles({
|
||||||
|
files: [{ name: "report.txt", path: "/mnt/project/report.txt", type: "file" }],
|
||||||
|
});
|
||||||
|
|
||||||
|
renderSnapshotTreeBrowser({
|
||||||
|
queryBasePath: "/mnt/project/report.txt",
|
||||||
|
displayBasePath: undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(await screen.findByRole("button", { name: "report.txt" })).toBeTruthy();
|
||||||
|
expect(requests[0]).toEqual({
|
||||||
|
shortId: "repo-1",
|
||||||
|
snapshotId: "snap-1",
|
||||||
|
path: "/mnt/project/report.txt",
|
||||||
|
offset: null,
|
||||||
|
limit: null,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("returns the ancestor folder path when selecting above the query root", async () => {
|
test("returns the ancestor folder path when selecting above the query root", async () => {
|
||||||
mockListSnapshotFiles({
|
mockListSnapshotFiles({
|
||||||
files: [
|
files: [
|
||||||
|
|
@ -91,6 +111,7 @@ describe("SnapshotTreeBrowser", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
let selectedPaths: Set<string> | undefined;
|
let selectedPaths: Set<string> | undefined;
|
||||||
|
let selectedKind: "file" | "dir" | null = null;
|
||||||
|
|
||||||
renderSnapshotTreeBrowser({
|
renderSnapshotTreeBrowser({
|
||||||
queryBasePath: "/mnt/project/subdir",
|
queryBasePath: "/mnt/project/subdir",
|
||||||
|
|
@ -99,6 +120,9 @@ describe("SnapshotTreeBrowser", () => {
|
||||||
onSelectionChange: (paths) => {
|
onSelectionChange: (paths) => {
|
||||||
selectedPaths = paths;
|
selectedPaths = paths;
|
||||||
},
|
},
|
||||||
|
onSingleSelectionKindChange: (kind) => {
|
||||||
|
selectedKind = kind;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const row = await screen.findByRole("button", { name: "project" });
|
const row = await screen.findByRole("button", { name: "project" });
|
||||||
|
|
@ -107,6 +131,7 @@ describe("SnapshotTreeBrowser", () => {
|
||||||
await userEvent.click(checkbox);
|
await userEvent.click(checkbox);
|
||||||
|
|
||||||
expect(selectedPaths ? Array.from(selectedPaths) : []).toEqual(["/mnt/project"]);
|
expect(selectedPaths ? Array.from(selectedPaths) : []).toEqual(["/mnt/project"]);
|
||||||
|
expect(selectedKind === "dir").toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("shows selected folder state when full paths are provided from the parent", async () => {
|
test("shows selected folder state when full paths are provided from the parent", async () => {
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ export const SnapshotTreeBrowser = (props: SnapshotTreeBrowserProps) => {
|
||||||
const { selectedPaths, onSelectionChange, onSingleSelectionKindChange, ...fileBrowserUiProps } = uiProps;
|
const { selectedPaths, onSelectionChange, onSingleSelectionKindChange, ...fileBrowserUiProps } = uiProps;
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const normalizedQueryBasePath = normalizeAbsolutePath(queryBasePath);
|
const normalizedQueryBasePath = normalizeAbsolutePath(queryBasePath);
|
||||||
const normalizedDisplayBasePath = normalizeAbsolutePath(displayBasePath ?? normalizedQueryBasePath);
|
const normalizedDisplayBasePath = normalizeAbsolutePath(displayBasePath ?? "/");
|
||||||
|
|
||||||
const { data, isLoading, error } = useQuery({
|
const { data, isLoading, error } = useQuery({
|
||||||
...listSnapshotFilesOptions({
|
...listSnapshotFilesOptions({
|
||||||
|
|
@ -98,6 +98,21 @@ export const SnapshotTreeBrowser = (props: SnapshotTreeBrowserProps) => {
|
||||||
const kinds = new Map<string, "file" | "dir">();
|
const kinds = new Map<string, "file" | "dir">();
|
||||||
for (const entry of fileBrowser.fileArray) {
|
for (const entry of fileBrowser.fileArray) {
|
||||||
kinds.set(entry.path, entry.type === "file" ? "file" : "dir");
|
kinds.set(entry.path, entry.type === "file" ? "file" : "dir");
|
||||||
|
|
||||||
|
let parentPath = entry.path;
|
||||||
|
while (true) {
|
||||||
|
const lastSlashIndex = parentPath.lastIndexOf("/");
|
||||||
|
if (lastSlashIndex <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
parentPath = parentPath.slice(0, lastSlashIndex);
|
||||||
|
if (kinds.has(parentPath)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
kinds.set(parentPath, "dir");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return kinds;
|
return kinds;
|
||||||
}, [fileBrowser.fileArray]);
|
}, [fileBrowser.fileArray]);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue