From 4f8fa415d89dae17de22435b99b273ff5d012dde Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Sun, 22 Nov 2026 22:39:02 -0800 Subject: [PATCH 1/2] fix(frontend): highlight the file picked in the dataset file tree The dataset file tree's click handler overrode the tree library's default click (TOGGLE_ACTIVE) with an emit of selectedTreeNode alone, so the tree never had an active node and the library never marked the clicked row: in the dataset-selection modal, where the host only stores the path, the picked file looked like every other and the one sign of the pick was the Select button turning enabled. The handler now activates the clicked file (ACTIVATE, not TOGGLE_ACTIVE, so a second click on the picked file keeps it highlighted, as the selection it emits stands either way), Enter and Space on the focused node do the same rather than the library's toggle, and the component styles the active row like the app's selected rows, with an inset shadow so the row keeps the height the virtual scroll pins. Folders toggle as before. A host that browses a version's files without holding one -- the dataset picker in version mode, the model picker -- sets isFileSelectable false, and a file click there activates and emits nothing: a highlighted row would promise a pick nothing takes. Every other host keeps the click it has and gains the highlight. Co-Authored-By: Claude Fable 5.1 --- ...version-filetree.component.browser.spec.ts | 42 ++++++ ...er-dataset-version-filetree.component.scss | 15 ++ ...dataset-version-filetree.component.spec.ts | 137 ++++++++++++++---- ...user-dataset-version-filetree.component.ts | 36 +++-- .../dataset-selection-modal.component.html | 1 + .../dataset-selection-modal.component.ts | 5 + .../model-selection-modal.component.html | 3 +- 7 files changed, 199 insertions(+), 40 deletions(-) diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.browser.spec.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.browser.spec.ts index bdb87cd8f37..038309f6f0f 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.browser.spec.ts +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.browser.spec.ts @@ -82,6 +82,48 @@ describe("UserDatasetVersionFiletreeComponent (browser)", () => { expect(buttonRect.bottom).toBeLessThanOrEqual(rowRect.bottom); }); + // Measured on a deployment: clicking the only file left its row's class at exactly + // "node-content-wrapper", so nothing told the user which file they had picked. Needs real rows, + // which the virtual scroll only renders here. + it("highlights the row of the clicked file", async () => { + await renderTree(makeFlatFileNodes(5)); + + const rowAt = (index: number): HTMLElement => + fixture.nativeElement.querySelectorAll(".node-content-wrapper")[index] as HTMLElement; + rowAt(1).click(); + fixture.detectChanges(); + + expect(rowAt(1).classList.contains("node-content-wrapper-active")).toBe(true); + expect(rowAt(0).classList.contains("node-content-wrapper-active")).toBe(false); + // The class alone is invisible unless the component styles it. The library transitions + // background-color and box-shadow over 150ms, so the computed values only reach the highlight + // once that has run. + await vi.waitFor(() => { + const highlighted = getComputedStyle(rowAt(1)); + expect(highlighted.backgroundColor).toBe("rgb(230, 247, 255)"); + expect(highlighted.boxShadow).toBe("rgb(24, 144, 255) 0px 0px 0px 1px inset"); + expect(highlighted.color).toBe("rgb(24, 144, 255)"); + }); + // The ring takes no layout space: the row's content box is still the full node height, where a + // 1px border would have left 2px less for the icon buttons under the app's border-box sizing. + expect(rowAt(1).clientHeight).toBe(component.TREE_NODE_HEIGHT_PX); + }); + + // The highlight is feedback for a pick, so where no file can be picked (the dataset picker in + // version mode, the model picker) a click must leave the row exactly as it was. + it("leaves the row untouched where files cannot be picked", async () => { + component.isFileSelectable = false; + await renderTree(makeFlatFileNodes(5)); + + const row = fixture.nativeElement.querySelectorAll(".node-content-wrapper")[1] as HTMLElement; + const before = getComputedStyle(row).backgroundColor; + row.click(); + fixture.detectChanges(); + + expect(row.classList.contains("node-content-wrapper-active")).toBe(false); + expect(getComputedStyle(row).backgroundColor).toBe(before); + }); + // Both hosts create the tree empty and fill it when data arrives; the // height change must trigger a viewport re-measure or the 0px initial // measurement sticks and the tree stays blank. diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.scss b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.scss index eb1171a0158..589e2a23cfb 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.scss +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.scss @@ -61,3 +61,18 @@ display: flex; align-items: center; } + +/* The picked file has to read as picked. The library's own active colours (#beebff behind a 1px + grey inset shadow) belong to no palette this app uses, so the row takes the ant blue-1 (#e6f7ff) + fill the dashboard's selected list rows and the workspace's selected cards share, with ant's + primary blue as the ring and text colour, as the workspace's selected cards ring. The :hover copy + keeps this fill on the picked row rather than the library's hover tint. */ +:host ::ng-deep .file-tree-container .node-content-wrapper.node-content-wrapper-active, +:host ::ng-deep .file-tree-container .node-content-wrapper.node-content-wrapper-active:hover { + background-color: #e6f7ff; + color: #1890ff; + /* An inset shadow rather than a border: with the row's height pinned to --tree-node-height for + the virtual scroll, a border would eat 2px of the content box the row's icon buttons and + centring rely on; a shadow takes no layout space at all. */ + box-shadow: inset 0 0 0 1px #1890ff; +} diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.spec.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.spec.ts index ce9fe30cf5f..26139d34403 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.spec.ts +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.spec.ts @@ -18,6 +18,7 @@ */ import { ComponentFixture } from "@angular/core/testing"; +import { KEYS } from "@ali-hm/angular-tree-component"; import { UserDatasetVersionFiletreeComponent } from "./user-dataset-version-filetree.component"; import { DatasetFileNode } from "../../../../../../common/type/datasetVersionFileTree"; import { createFiletreeFixture, FILE_COUNT, makeFlatFileNodes } from "./user-dataset-version-filetree.test-utils"; @@ -109,38 +110,116 @@ describe("UserDatasetVersionFiletreeComponent", () => { expect(component.tree.treeModel.roots[0].isExpanded).toBe(true); }); - it("toggles expansion without emitting selectedTreeNode when a folder is clicked", () => { - const emitted: DatasetFileNode[] = []; - component.selectedTreeNode.subscribe((n: DatasetFileNode) => emitted.push(n)); - - // The folder branch delegates to TOGGLE_EXPANDED, which only calls - // node.toggleExpanded(). - let toggleCalls = 0; - const onClick = component.fileTreeDisplayOptions.actionMapping!.mouse!.click!; - const folderNode = { - hasChildren: true, - toggleExpanded: () => { - toggleCalls++; - }, - data: { name: "dir", type: "directory", parentDir: "/owner/dataset/v1" }, - } as never; - onClick(undefined as never, folderNode, undefined as never); - - expect(toggleCalls).toBe(1); - expect(emitted).toEqual([]); - }); + // Clicks go through the library's own mouseAction dispatch on real tree nodes, so what these + // pin is the state a row's node-content-wrapper-active class is bound to -- not only that the + // handler was reached. + describe("clicking a node", () => { + function renderAndClick(nodes: DatasetFileNode[], rootIndex: number): any { + component.fileTreeNodes = nodes; + fixture.detectChanges(); + const node = component.tree.treeModel.roots[rootIndex]; + node.mouseAction("click", new MouseEvent("click")); + return node; + } - it("emits selectedTreeNode when a leaf node is clicked", () => { - component.fileTreeNodes = makeFlatFileNodes(1); - const emitted: DatasetFileNode[] = []; - component.selectedTreeNode.subscribe((n: DatasetFileNode) => emitted.push(n)); + const activeNames = (): string[] => + component.tree.treeModel.activeNodes.map((node: any) => node.data.name as string); - // The handler only reads hasChildren and data; tree and $event are unused. - const onClick = component.fileTreeDisplayOptions.actionMapping!.mouse!.click!; - const leafNode = { hasChildren: false, data: component.fileTreeNodes[0] } as never; - onClick(undefined as never, leafNode, undefined as never); + it("emits selectedTreeNode and makes the file the active node", () => { + const emitted: DatasetFileNode[] = []; + component.selectedTreeNode.subscribe((n: DatasetFileNode) => emitted.push(n)); - expect(emitted).toEqual([component.fileTreeNodes[0]]); + const files = makeFlatFileNodes(3); + const node = renderAndClick(files, 1); + + expect(emitted).toEqual([files[1]]); + expect(node.isActive).toBe(true); + expect(activeNames()).toEqual([files[1].name]); + }); + + // ACTIVATE, not TOGGLE_ACTIVE: a second click on the file the user already picked must not + // strip the highlight off a selection that still stands. + it("keeps the file active when the same file is clicked again, and emits it again", () => { + const emitted: DatasetFileNode[] = []; + component.selectedTreeNode.subscribe((n: DatasetFileNode) => emitted.push(n)); + const files = makeFlatFileNodes(3); + const node = renderAndClick(files, 1); + + node.mouseAction("click", new MouseEvent("click")); + + expect(node.isActive).toBe(true); + expect(activeNames()).toEqual([files[1].name]); + expect(emitted).toEqual([files[1], files[1]]); + }); + + // The library maps Enter and Space to TOGGLE_ACTIVE by default: Enter on the picked file would + // strip its highlight while the host's selection stands, and on another row would mark a file + // the host never heard of. Both keys now do what a click does. + it("activates and emits on Enter or Space, as on a click, without toggling the pick off", () => { + const emitted: DatasetFileNode[] = []; + component.selectedTreeNode.subscribe((n: DatasetFileNode) => emitted.push(n)); + const files = makeFlatFileNodes(3); + component.fileTreeNodes = files; + fixture.detectChanges(); + const keys = component.fileTreeDisplayOptions.actionMapping!.keys!; + const node = component.tree.treeModel.roots[1]; + + keys[KEYS.ENTER](component.tree.treeModel, node, new KeyboardEvent("keydown")); + expect(node.isActive).toBe(true); + keys[KEYS.SPACE](component.tree.treeModel, node, new KeyboardEvent("keydown")); + + expect(node.isActive).toBe(true); + expect(activeNames()).toEqual([files[1].name]); + expect(emitted).toEqual([files[1], files[1]]); + }); + + // A host that browses a version's files without being able to hold one (the dataset picker in + // version mode, the model picker) gets no trace of a click: a blue row there would promise a + // pick nothing takes. Folders still open. + it("neither activates nor emits a file where files cannot be picked, and still expands a folder", () => { + const emitted: DatasetFileNode[] = []; + component.selectedTreeNode.subscribe((n: DatasetFileNode) => emitted.push(n)); + component.isFileSelectable = false; + + const files = makeFlatFileNodes(3); + const node = renderAndClick(files, 1); + expect(emitted).toEqual([]); + // Never activated at all, so the library leaves the flag unset rather than false. + expect(node.isActive).toBeFalsy(); + expect(activeNames()).toEqual([]); + + const folder = renderAndClick([folderWith(makeFlatFileNodes(2))], 0); + expect(folder.isExpanded).toBe(true); + }); + + // Every host that never binds the input (the dataset and model pages, the file selector) keeps + // the click it has today. + it("picks files by default, for a host that never binds the input", () => { + expect(component.isFileSelectable).toBe(true); + }); + + it("moves the highlight to the newly clicked file", () => { + const files = makeFlatFileNodes(3); + renderAndClick(files, 1); + + component.tree.treeModel.roots[2].mouseAction("click", new MouseEvent("click")); + + expect(activeNames()).toEqual([files[2].name]); + }); + + it("toggles a folder's expansion, activating nothing and emitting nothing", () => { + const emitted: DatasetFileNode[] = []; + component.selectedTreeNode.subscribe((n: DatasetFileNode) => emitted.push(n)); + + const folder = renderAndClick([folderWith(makeFlatFileNodes(2))], 0); + expect(folder.isExpanded).toBe(true); + + folder.mouseAction("click", new MouseEvent("click")); + expect(folder.isExpanded).toBe(false); + + expect(activeNames()).toEqual([]); + expect(emitted).toEqual([]); + }); }); it("emits deletedTreeNode when a node deletion is requested", () => { diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.ts index 2e53d5dffa4..6c48f125762 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.ts +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.ts @@ -34,7 +34,7 @@ import { DatasetFileNode, getRelativePathFromDatasetFileNode, } from "../../../../../../common/type/datasetVersionFileTree"; -import { ITreeOptions, TREE_ACTIONS, TreeModule } from "@ali-hm/angular-tree-component"; +import { ITreeOptions, KEYS, TREE_ACTIONS, TreeModule } from "@ali-hm/angular-tree-component"; import { NgIf } from "@angular/common"; import { ɵNzTransitionPatchDirective } from "ng-zorro-antd/core/transition-patch"; import { NzIconDirective } from "ng-zorro-antd/icon"; @@ -104,6 +104,29 @@ export class UserDatasetVersionFiletreeComponent implements AfterViewInit, OnDes @Input() public isExpandAllAfterViewInit = false; + // Whether a file in this tree is an answer the host can take. A host that browses the files of a + // version without holding one (the dataset picker in version mode, the model picker) leaves + // nothing for a click to mean, and a highlighted row there would promise a pick that is never + // made. Defaults to true, which is what every host that never binds it gets. + @Input() + public isFileSelectable = true; + + // One handler for a click and for Enter/Space on the focused node: the library maps the keys to + // TOGGLE_ACTIVE by default, which would strip the highlight off the picked file, or mark a file + // the host never heard of. + private readonly activateOrExpand = (tree: any, node: any, $event: any): void => { + if (node.hasChildren) { + TREE_ACTIONS.TOGGLE_EXPANDED(tree, node, $event); + } else if (this.isFileSelectable) { + // Overriding the library's click replaced its default (TOGGLE_ACTIVE) with the emit alone, + // so the tree never had an active node and the clicked row looked like every other. + // ACTIVATE rather than TOGGLE_ACTIVE: a second click on the picked file leaves it + // highlighted, since the selection it emits stands either way. + TREE_ACTIONS.ACTIVATE(tree, node, $event); + this.selectedTreeNode.emit(node.data); + } + }; + @ViewChild("tree") tree: any; @ViewChild("container") container?: ElementRef; @@ -126,15 +149,8 @@ export class UserDatasetVersionFiletreeComponent implements AfterViewInit, OnDes useVirtualScroll: true, nodeHeight: this.TREE_NODE_HEIGHT_PX, actionMapping: { - mouse: { - click: (tree: any, node: any, $event: any) => { - if (node.hasChildren) { - TREE_ACTIONS.TOGGLE_EXPANDED(tree, node, $event); - } else { - this.selectedTreeNode.emit(node.data); - } - }, - }, + mouse: { click: this.activateOrExpand }, + keys: { [KEYS.ENTER]: this.activateOrExpand, [KEYS.SPACE]: this.activateOrExpand }, }, }; diff --git a/frontend/src/app/workspace/component/dataset-selection-modal/dataset-selection-modal.component.html b/frontend/src/app/workspace/component/dataset-selection-modal/dataset-selection-modal.component.html index 4412fb350fb..ebd2f19f15d 100644 --- a/frontend/src/app/workspace/component/dataset-selection-modal/dataset-selection-modal.component.html +++ b/frontend/src/app/workspace/component/dataset-selection-modal/dataset-selection-modal.component.html @@ -58,6 +58,7 @@
diff --git a/frontend/src/app/workspace/component/dataset-selection-modal/dataset-selection-modal.component.ts b/frontend/src/app/workspace/component/dataset-selection-modal/dataset-selection-modal.component.ts index 8d5d517a8ad..75447828f04 100644 --- a/frontend/src/app/workspace/component/dataset-selection-modal/dataset-selection-modal.component.ts +++ b/frontend/src/app/workspace/component/dataset-selection-modal/dataset-selection-modal.component.ts @@ -132,6 +132,11 @@ export class DatasetSelectionModalComponent implements OnInit { } } + /** Whether a file is the answer here (file mode) or only browsed (version mode); see the tree's isFileSelectable. */ + get fileMode(): boolean { + return this.data.fileMode; + } + onFileSelected(node: DatasetFileNode) { if (this.data.fileMode) { this.selectedPath = getFullPathFromDatasetFileNode(node); diff --git a/frontend/src/app/workspace/component/model-selection-modal/model-selection-modal.component.html b/frontend/src/app/workspace/component/model-selection-modal/model-selection-modal.component.html index 9643d7bb714..4afef29eebc 100644 --- a/frontend/src/app/workspace/component/model-selection-modal/model-selection-modal.component.html +++ b/frontend/src/app/workspace/component/model-selection-modal/model-selection-modal.component.html @@ -57,7 +57,8 @@
+ [fileTreeNodes]="fileTree" + [isFileSelectable]="false">