From fc0129bcfad2a8d0fce220ceb4457f4bef4962c5 Mon Sep 17 00:00:00 2001 From: Xinyuan Lin Date: Wed, 18 Nov 2026 22:08:16 -0800 Subject: [PATCH 1/3] refactor(frontend): remove unused imports, modules, and state --- .../common/service/user/auth-guard.service.ts | 4 +-- .../registration-request-modal.component.ts | 2 +- .../common/service/user/stub-user.service.ts | 8 ----- .../app/common/service/user/user.service.ts | 5 +--- .../warehouse/warehouse-actions.service.ts | 3 +- .../type/datasetVersionFileTree.spec.ts | 29 ------------------- .../app/common/type/datasetVersionFileTree.ts | 15 ---------- .../admin/gmail/admin-gmail.component.spec.ts | 4 +-- .../admin/gmail/admin-gmail.component.ts | 3 +- .../user/search-bar/search-bar.component.html | 3 +- .../user/search-bar/search-bar.component.scss | 10 ------- .../search-results.component.spec.ts | 21 +------------- .../search-results.component.ts | 7 ----- .../user-computing-unit.component.spec.ts | 14 --------- .../user-computing-unit.component.ts | 15 +--------- .../user-dataset-file-renderer.component.ts | 3 +- .../user-dataset/user-dataset.component.html | 1 - .../user/user-model/user-model.component.html | 1 - .../hub-search-result.component.ts | 2 -- .../landing-page.component.spec.ts | 5 +--- .../landing-page/landing-page.component.ts | 2 -- .../dataset-file-selector.component.ts | 3 +- .../dataset-version-selector.component.ts | 3 +- .../jupyter-notebook-panel.component.ts | 3 +- .../left-panel/settings/settings.component.ts | 4 +-- .../port-property-edit-frame.component.ts | 3 +- .../console-frame/console-frame.component.ts | 2 -- .../mini-map/mini-map.component.ts | 2 -- .../ui-udf-parameters-parser.service.ts | 9 ++++-- .../service/preset/preset.service.ts | 3 +- .../model/coeditor-presence.service.ts | 3 -- 31 files changed, 26 insertions(+), 166 deletions(-) diff --git a/frontend/src/app/common/service/user/auth-guard.service.ts b/frontend/src/app/common/service/user/auth-guard.service.ts index b2ac79e6dc0..dfcec3a46c6 100644 --- a/frontend/src/app/common/service/user/auth-guard.service.ts +++ b/frontend/src/app/common/service/user/auth-guard.service.ts @@ -19,7 +19,6 @@ import { Injectable } from "@angular/core"; import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from "@angular/router"; -import { GuiConfigService } from "../gui-config.service"; import { UserService } from "./user.service"; import { LOGIN } from "../../../app-routing.constant"; @@ -31,8 +30,7 @@ import { LOGIN } from "../../../app-routing.constant"; export class AuthGuardService implements CanActivate { constructor( private userService: UserService, - private router: Router, - private config: GuiConfigService + private router: Router ) {} canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { if (this.userService.isLogin()) { diff --git a/frontend/src/app/common/service/user/registration-request-modal/registration-request-modal.component.ts b/frontend/src/app/common/service/user/registration-request-modal/registration-request-modal.component.ts index f68042fd825..8e5303b8a3a 100644 --- a/frontend/src/app/common/service/user/registration-request-modal/registration-request-modal.component.ts +++ b/frontend/src/app/common/service/user/registration-request-modal/registration-request-modal.component.ts @@ -17,7 +17,7 @@ * under the License. */ -import { Component, Inject, Input, TemplateRef, ViewChild } from "@angular/core"; +import { Component, Inject, TemplateRef, ViewChild } from "@angular/core"; import { NZ_MODAL_DATA } from "ng-zorro-antd/modal"; import { NzSpaceCompactItemDirective } from "ng-zorro-antd/space"; import { NzInputDirective } from "ng-zorro-antd/input"; diff --git a/frontend/src/app/common/service/user/stub-user.service.ts b/frontend/src/app/common/service/user/stub-user.service.ts index ab2296877eb..365d3822bea 100644 --- a/frontend/src/app/common/service/user/stub-user.service.ts +++ b/frontend/src/app/common/service/user/stub-user.service.ts @@ -98,12 +98,4 @@ export class StubUserService implements PublicInterfaceOf { getAvatar(avatarUrl: string): Observable { return of(undefined); } - - checkAffiliation(): Observable { - return of(true); - } - - updateAffiliation(_affiliation: string): Observable { - return of(void 0); - } } diff --git a/frontend/src/app/common/service/user/user.service.ts b/frontend/src/app/common/service/user/user.service.ts index 1efaf2177ba..d9f4194c672 100644 --- a/frontend/src/app/common/service/user/user.service.ts +++ b/frontend/src/app/common/service/user/user.service.ts @@ -18,8 +18,6 @@ */ import { Injectable } from "@angular/core"; -import { HttpClient } from "@angular/common/http"; -import { AppSettings } from "../../app-setting"; import { Observable, of, ReplaySubject } from "rxjs"; import { Role, User } from "../../type/user"; import { AuthService } from "./auth.service"; @@ -42,8 +40,7 @@ export class UserService { constructor( private authService: AuthService, - private config: GuiConfigService, - private http: HttpClient + private config: GuiConfigService ) { const user = this.authService.loginWithExistingToken(); this.changeUser(user); diff --git a/frontend/src/app/common/service/warehouse/warehouse-actions.service.ts b/frontend/src/app/common/service/warehouse/warehouse-actions.service.ts index bc8e06545e4..893ea2b3db8 100644 --- a/frontend/src/app/common/service/warehouse/warehouse-actions.service.ts +++ b/frontend/src/app/common/service/warehouse/warehouse-actions.service.ts @@ -19,8 +19,7 @@ import { Injectable } from "@angular/core"; import { NzModalService } from "ng-zorro-antd/modal"; -import { EMPTY, catchError, shareReplay } from "rxjs"; -import { Observable, firstValueFrom } from "rxjs"; +import { Observable, EMPTY, catchError, firstValueFrom, shareReplay } from "rxjs"; import { NotificationService } from "../notification/notification.service"; import { DashboardWarehouse } from "../../type/warehouse"; import { extractErrorMessage } from "../../util/error"; diff --git a/frontend/src/app/common/type/datasetVersionFileTree.spec.ts b/frontend/src/app/common/type/datasetVersionFileTree.spec.ts index 1ee6b94da19..c732580753e 100644 --- a/frontend/src/app/common/type/datasetVersionFileTree.spec.ts +++ b/frontend/src/app/common/type/datasetVersionFileTree.spec.ts @@ -19,7 +19,6 @@ import { DatasetFileNode, getFullPathFromDatasetFileNode, - getPathsUnderOrEqualDatasetFileNode, getRelativePathFromDatasetFileNode, } from "./datasetVersionFileTree"; @@ -72,31 +71,3 @@ describe("getRelativePathFromDatasetFileNode", () => { expect(getRelativePathFromDatasetFileNode(node)).toBe("sub/f.csv"); }); }); - -describe("getPathsUnderOrEqualDatasetFileNode", () => { - it("returns the single path for a file node", () => { - const file: DatasetFileNode = { name: "a.txt", type: "file", parentDir: "/dir" }; - expect(getPathsUnderOrEqualDatasetFileNode(file)).toEqual(["/dir/a.txt"]); - }); - - it("collects every file path under a directory", () => { - const file1: DatasetFileNode = { name: "file1.txt", type: "file", parentDir: "/dir" }; - const file2: DatasetFileNode = { name: "file2.txt", type: "file", parentDir: "/dir" }; - const dir: DatasetFileNode = { name: "dir", type: "directory", parentDir: "", children: [file1, file2] }; - expect(getPathsUnderOrEqualDatasetFileNode(dir)).toEqual(["/dir/file1.txt", "/dir/file2.txt"]); - }); - - it("recurses into nested directories", () => { - const deepFile: DatasetFileNode = { name: "deep.txt", type: "file", parentDir: "/a/b" }; - const subDir: DatasetFileNode = { name: "b", type: "directory", parentDir: "/a", children: [deepFile] }; - const topDir: DatasetFileNode = { name: "a", type: "directory", parentDir: "", children: [subDir] }; - expect(getPathsUnderOrEqualDatasetFileNode(topDir)).toEqual(["/a/b/deep.txt"]); - }); - - it("returns an empty array for an empty directory", () => { - const emptyChildren: DatasetFileNode = { name: "dir", type: "directory", parentDir: "", children: [] }; - const noChildrenProp: DatasetFileNode = { name: "dir", type: "directory", parentDir: "" }; - expect(getPathsUnderOrEqualDatasetFileNode(emptyChildren)).toEqual([]); - expect(getPathsUnderOrEqualDatasetFileNode(noChildrenProp)).toEqual([]); - }); -}); diff --git a/frontend/src/app/common/type/datasetVersionFileTree.ts b/frontend/src/app/common/type/datasetVersionFileTree.ts index 91160b38dd9..5bf87342053 100644 --- a/frontend/src/app/common/type/datasetVersionFileTree.ts +++ b/frontend/src/app/common/type/datasetVersionFileTree.ts @@ -46,18 +46,3 @@ export function getRelativePathFromDatasetFileNode(node: DatasetFileNode): strin return pathSegments.slice(4).join("/"); // Join remaining segments as the relative path } - -export function getPathsUnderOrEqualDatasetFileNode(node: DatasetFileNode): string[] { - // Helper function to recursively gather paths - const gatherPaths = (node: DatasetFileNode): string[] => { - // Base case: if the node is a file, return its path - if (node.type === "file") { - return [getFullPathFromDatasetFileNode(node)]; - } - - // Recursive case: if the node is a directory, explore its children - return node.children ? node.children.flatMap(child => gatherPaths(child)) : []; - }; - - return gatherPaths(node); -} diff --git a/frontend/src/app/dashboard/component/admin/gmail/admin-gmail.component.spec.ts b/frontend/src/app/dashboard/component/admin/gmail/admin-gmail.component.spec.ts index 7c24b30f106..a1d38a21bab 100644 --- a/frontend/src/app/dashboard/component/admin/gmail/admin-gmail.component.spec.ts +++ b/frontend/src/app/dashboard/component/admin/gmail/admin-gmail.component.spec.ts @@ -18,7 +18,7 @@ */ import { ComponentFixture, TestBed } from "@angular/core/testing"; -import { FormsModule, ReactiveFormsModule } from "@angular/forms"; +import { ReactiveFormsModule } from "@angular/forms"; import { NoopAnimationsModule } from "@angular/platform-browser/animations"; import { HttpClientTestingModule } from "@angular/common/http/testing"; import { Subject } from "rxjs"; @@ -50,7 +50,7 @@ describe("AdminGmailComponent", () => { const gmailServiceStub = { getSenderEmail: getSenderEmailSpy, sendEmail: sendEmailSpy }; await TestBed.configureTestingModule({ - imports: [AdminGmailComponent, FormsModule, ReactiveFormsModule, NoopAnimationsModule, HttpClientTestingModule], + imports: [AdminGmailComponent, ReactiveFormsModule, NoopAnimationsModule, HttpClientTestingModule], providers: [{ provide: GmailService, useValue: gmailServiceStub }, ...commonTestProviders], }).compileComponents(); }); diff --git a/frontend/src/app/dashboard/component/admin/gmail/admin-gmail.component.ts b/frontend/src/app/dashboard/component/admin/gmail/admin-gmail.component.ts index 04cf02e85f1..cf32e0c1b01 100644 --- a/frontend/src/app/dashboard/component/admin/gmail/admin-gmail.component.ts +++ b/frontend/src/app/dashboard/component/admin/gmail/admin-gmail.component.ts @@ -19,7 +19,7 @@ import { Component, OnInit } from "@angular/core"; import { GmailService } from "../../../../common/service/gmail/gmail.service"; -import { FormBuilder, FormGroup, Validators, FormsModule, ReactiveFormsModule } from "@angular/forms"; +import { FormBuilder, FormGroup, Validators, ReactiveFormsModule } from "@angular/forms"; import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy"; import { NzCardComponent } from "ng-zorro-antd/card"; import { NzFormDirective, NzFormItemComponent, NzFormLabelComponent, NzFormControlComponent } from "ng-zorro-antd/form"; @@ -36,7 +36,6 @@ import { ɵNzTransitionPatchDirective } from "ng-zorro-antd/core/transition-patc templateUrl: "./admin-gmail.component.html", imports: [ NzCardComponent, - FormsModule, NzFormDirective, ReactiveFormsModule, NzRowDirective, diff --git a/frontend/src/app/dashboard/component/user/search-bar/search-bar.component.html b/frontend/src/app/dashboard/component/user/search-bar/search-bar.component.html index 4b66c6c1311..f9d0ee411ed 100644 --- a/frontend/src/app/dashboard/component/user/search-bar/search-bar.component.html +++ b/frontend/src/app/dashboard/component/user/search-bar/search-bar.component.html @@ -27,8 +27,7 @@ [(ngModel)]="searchParam" (ngModelChange)="onSearchInputChange($event)" (keydown.enter)="performSearch(searchParam)" - [nzAutocomplete]="auto" - #searchInput /> + [nzAutocomplete]="auto" /> { beforeEach(async () => { await TestBed.configureTestingModule({ imports: [SearchResultsComponent, NoopAnimationsModule], - providers: [{ provide: UserService, useClass: StubUserService }, ...commonTestProviders], + providers: [...commonTestProviders], }).compileComponents(); // ListItemComponent is heavy (needs a full service graph); swap it for a @@ -106,25 +106,6 @@ describe("SearchResultsComponent", () => { expect(component).toBeTruthy(); }); - describe("getUid", () => { - it("returns the current user's uid when a user is logged in", () => { - // StubUserService default user has uid = 1 (MOCK_USER_ID). - expect(component.getUid()).toBe(1); - }); - - it("returns a spied uid", () => { - const userService = TestBed.inject(UserService); - vi.spyOn(userService, "getCurrentUser").mockReturnValue({ uid: 42 } as any); - expect(component.getUid()).toBe(42); - }); - - it("returns undefined when no user is logged in", () => { - const userService = TestBed.inject(UserService); - vi.spyOn(userService, "getCurrentUser").mockReturnValue(undefined); - expect(component.getUid()).toBeUndefined(); - }); - }); - describe("reset", () => { it("clears entries and stores the provided loadMoreFunction", async () => { component.entries = [makeEntry("workflow", 1), makeEntry("dataset", 2)]; diff --git a/frontend/src/app/dashboard/component/user/search-results/search-results.component.ts b/frontend/src/app/dashboard/component/user/search-results/search-results.component.ts index 4e122aa4fd4..96eab4139a4 100644 --- a/frontend/src/app/dashboard/component/user/search-results/search-results.component.ts +++ b/frontend/src/app/dashboard/component/user/search-results/search-results.component.ts @@ -19,7 +19,6 @@ import { Component, EventEmitter, Input, Output, TemplateRef } from "@angular/core"; import { DashboardEntry } from "../../../type/dashboard-entry"; -import { UserService } from "../../../../common/service/user/user.service"; import { NzCardComponent } from "ng-zorro-antd/card"; import { ɵɵCdkVirtualScrollViewport, ɵɵCdkFixedSizeVirtualScroll } from "@angular/cdk/overlay"; import { NzListComponent } from "ng-zorro-antd/list"; @@ -72,12 +71,6 @@ export class SearchResultsComponent { @Output() notifyWorkflow = new EventEmitter(); @Output() refresh = new EventEmitter(); - constructor(private userService: UserService) {} - - getUid(): number | undefined { - return this.userService.getCurrentUser()?.uid; - } - reset(loadMoreFunction: LoadMoreFunction): void { this.entries = []; this.loadMoreFunction = loadMoreFunction; diff --git a/frontend/src/app/dashboard/component/user/user-computing-unit/user-computing-unit.component.spec.ts b/frontend/src/app/dashboard/component/user/user-computing-unit/user-computing-unit.component.spec.ts index de190dda424..43408bc30ea 100644 --- a/frontend/src/app/dashboard/component/user/user-computing-unit/user-computing-unit.component.spec.ts +++ b/frontend/src/app/dashboard/component/user/user-computing-unit/user-computing-unit.component.spec.ts @@ -27,8 +27,6 @@ import { NzIconModule } from "ng-zorro-antd/icon"; import { NzModalService } from "ng-zorro-antd/modal"; import { FileAddOutline } from "@ant-design/icons-angular/icons"; import { HttpClientTestingModule } from "@angular/common/http/testing"; -import { UserService } from "../../../../common/service/user/user.service"; -import { StubUserService } from "../../../../common/service/user/stub-user.service"; import { commonTestProviders } from "../../../../common/testing/test-utils"; import { WorkflowComputingUnitManagingService } from "../../../../common/service/computing-unit/workflow-computing-unit/workflow-computing-unit-managing.service"; import { ComputingUnitStatusService } from "../../../../common/service/computing-unit/computing-unit-status/computing-unit-status.service"; @@ -59,7 +57,6 @@ describe("UserComputingUnitComponent", () => { await TestBed.configureTestingModule({ providers: [ NzModalService, - { provide: UserService, useClass: StubUserService }, { provide: WorkflowComputingUnitManagingService, useValue: mockComputingUnitService }, { provide: ComputingUnitStatusService, useClass: MockComputingUnitStatusService }, ...commonTestProviders, @@ -134,17 +131,6 @@ describe("UserComputingUnitComponent", () => { fixture.destroy(); }); - it("follows the signed-in user when the session changes", () => { - fixture.detectChanges(); - const stubUserService = TestBed.inject(UserService) as unknown as StubUserService; - - stubUserService.user = undefined; - stubUserService.userChangeSubject.next(undefined); - - expect(component.isLogin).toBe(false); - expect(component.currentUid).toBeUndefined(); - }); - it("maps the fetched computing units into dashboard entries", () => { const statusService = TestBed.inject(ComputingUnitStatusService); vi.spyOn(statusService, "getAllComputingUnits").mockReturnValue(of([makeUnit(7)])); diff --git a/frontend/src/app/dashboard/component/user/user-computing-unit/user-computing-unit.component.ts b/frontend/src/app/dashboard/component/user/user-computing-unit/user-computing-unit.component.ts index 7f62d81540f..5e58ca9c4f8 100644 --- a/frontend/src/app/dashboard/component/user/user-computing-unit/user-computing-unit.component.ts +++ b/frontend/src/app/dashboard/component/user/user-computing-unit/user-computing-unit.component.ts @@ -23,7 +23,6 @@ import { DashboardEntry } from "../../../type/dashboard-entry"; import { DashboardWorkflowComputingUnit } from "../../../../common/type/workflow-computing-unit"; import { NotificationService } from "../../../../common/service/notification/notification.service"; import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy"; -import { UserService } from "../../../../common/service/user/user.service"; import { ComputingUnitActionsService } from "../../../../common/service/computing-unit/computing-unit-actions/computing-unit-actions.service"; import { interval } from "rxjs"; import { NzCardComponent } from "ng-zorro-antd/card"; @@ -59,9 +58,6 @@ import { ComputingUnitCreateModalComponent } from "../../../../common/component/ }) export class UserComputingUnitComponent implements OnInit { public entries: DashboardEntry[] = []; - public isLogin = this.userService.isLogin(); - public currentUid = this.userService.getCurrentUser()?.uid; - allComputingUnits: DashboardWorkflowComputingUnit[] = []; // visibility of the shared create-computing-unit modal @@ -69,18 +65,9 @@ export class UserComputingUnitComponent implements OnInit { constructor( private notificationService: NotificationService, - private userService: UserService, private computingUnitStatusService: ComputingUnitStatusService, private computingUnitActionsService: ComputingUnitActionsService - ) { - this.userService - .userChanged() - .pipe(untilDestroyed(this)) - .subscribe(() => { - this.isLogin = this.userService.isLogin(); - this.currentUid = this.userService.getCurrentUser()?.uid; - }); - } + ) {} ngOnInit() { this.computingUnitStatusService diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-file-renderer/user-dataset-file-renderer.component.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-file-renderer/user-dataset-file-renderer.component.ts index 871ac4cf0d3..d0e3c2716d1 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-file-renderer/user-dataset-file-renderer.component.ts +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-file-renderer/user-dataset-file-renderer.component.ts @@ -23,7 +23,6 @@ import { EntityType } from "../../../../../../hub/service/hub.service"; import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy"; import { Subscription } from "rxjs"; import * as Papa from "papaparse"; -import { ParseResult } from "papaparse"; import { DomSanitizer, SafeUrl } from "@angular/platform-browser"; import readXlsxFile from "read-excel-file"; import { NotificationService } from "../../../../../../common/service/notification/notification.service"; @@ -270,7 +269,7 @@ export class UserDatasetFileRendererComponent implements OnInit, OnChanges, OnDe this.displayCSV = true; // Handle CSV display Papa.parse(this.currentFile, { - complete: (results: ParseResult) => { + complete: (results: Papa.ParseResult) => { if (!isCurrent()) return; if (results.data.length > 0) { this.loadTabularFile(results.data); diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset.component.html b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset.component.html index 69061cb5ecc..074a54c19fb 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset.component.html +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset.component.html @@ -67,7 +67,6 @@

Datasets