This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-9463-0796c47de4c14287b147eaa2b8d416f3e1371086 in repository https://gitbox.apache.org/repos/asf/texera.git
commit 48fef8fe80df611cf4810e3865e5f0c2a9b904a9 Author: Xinyuan Lin <[email protected]> AuthorDate: Mon Nov 16 23:51:31 2026 +0000 refactor(frontend): remove unused dataset dashboard code (#9463) ### What changes were proposed in this PR? Remove unreachable code from dataset creation, dashboard search, and file previews, and rename the dataset creator to match the model creator. **+245/−388 lines across fourteen files.** - The dashboard and result export both open the modal to create a dataset. Versions are created on the dataset detail page, so the shared creator form always shows its visibility and downloadability switches. - With only dataset creation left, `UserDatasetVersionCreatorComponent` becomes `UserDatasetCreatorComponent` and moves from `user-dataset-explorer/` to `user-dataset/user-dataset-creator/`, matching `UserModelCreatorComponent` in `user-model/user-model-creator/`. GitHub shows its `.ts` as a new file because the move and the version-mode removal together change most of it. - Dashboard search has no callers for the public or all scopes. - HTML, PDF, MS Word, and MS PowerPoint suffixes already fall through to the unsupported-preview notice. The preview guard rejects binary files before the size lookup, and every type it accepts has its own size limit, so the default limit is never used. | Code | Introduced by | Usage removed by | | --- | --- | --- | | Modal version mode | #3296 | #3659 | | Creator form switch toggle | #2413 | #3659 | | Dashboard search scopes | #2987 | #3129 | | Binary preview size limit | #2413 | #3149 | | Default preview size limit | #2413, #3427 | Never reached | | Unsupported MIME aliases | #2413 | Never selected a viewer | The modal mode and its switch toggle have been unreachable since August 2025, the search scopes since January 2025, and the binary size limit since December 2024. ### Any related issues, documentation, discussions? Closes #9462. ### How was this PR tested? From `frontend/` on Node 24 ```sh NODE_OPTIONS=--max-old-space-size=8192 yarn test --progress=false \ --include='**/{user-dataset-file-renderer,user-dataset-creator,user-model-creator,user-dataset,result-exportation,result-table-frame,context-menu,dataset-detail,version-uploader}.component.spec.ts' yarn exec tsc --noEmit -p src/tsconfig.app.json yarn exec tsc --noEmit -p src/tsconfig.spec.json yarn format:ci yarn build ``` 509 tests passed across nine suites. The preview test now checks that the four affected suffixes still show the unsupported-preview state without a request to the backend. Both creation entry points, the model creator that shares the creator form, and the dataset version uploader are covered by the targeted run. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Codex (GPT-6) and Claude Code (Claude Opus 5.5) --------- Co-authored-by: Claude Opus 5.5 <[email protected]> --- frontend/src/app/app.module.ts | 4 +- .../resource-creator-form.component.html | 4 +- .../resource-creator-form.component.ts | 3 - .../user-dataset-creator.component.html} | 1 - .../user-dataset-creator.component.spec.ts} | 106 +++------- .../user-dataset-creator.component.ts | 179 +++++++++++++++++ .../user-dataset-file-renderer.component.spec.ts | 27 +-- .../user-dataset-file-renderer.component.ts | 13 +- .../user-dataset-version-creator.component.ts | 219 --------------------- .../user-dataset/user-dataset.component.spec.ts | 35 +--- .../user/user-dataset/user-dataset.component.ts | 28 +-- .../user-model-creator.component.spec.ts | 3 +- .../result-exportation.component.spec.ts | 4 +- .../result-exportation.component.ts | 7 +- 14 files changed, 245 insertions(+), 388 deletions(-) diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 10e7652efc..917317210c 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -143,7 +143,7 @@ import { en_US, provideNzI18n } from "ng-zorro-antd/i18n"; import { FilesUploaderComponent } from "./dashboard/component/user/files-uploader/files-uploader.component"; import { ConflictingFileModalContentComponent } from "./dashboard/component/user/files-uploader/conflicting-file-modal-content/conflicting-file-modal-content.component"; import { UserDatasetComponent } from "./dashboard/component/user/user-dataset/user-dataset.component"; -import { UserDatasetVersionCreatorComponent } from "./dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-creator/user-dataset-version-creator.component"; +import { UserDatasetCreatorComponent } from "./dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component"; import { DatasetDetailComponent } from "./dashboard/component/user/user-dataset/user-dataset-explorer/dataset-detail.component"; import { UserDatasetVersionFiletreeComponent } from "./dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component"; import { UserDatasetFileRendererComponent } from "./dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-file-renderer/user-dataset-file-renderer.component"; @@ -307,7 +307,7 @@ registerLocaleData(en); FilesUploaderComponent, ConflictingFileModalContentComponent, UserDatasetComponent, - UserDatasetVersionCreatorComponent, + UserDatasetCreatorComponent, DatasetDetailComponent, UserDatasetVersionFiletreeComponent, UserDatasetFileRendererComponent, diff --git a/frontend/src/app/dashboard/component/user/resource-creator-form/resource-creator-form.component.html b/frontend/src/app/dashboard/component/user/resource-creator-form/resource-creator-form.component.html index a52b890603..985478f508 100644 --- a/frontend/src/app/dashboard/component/user/resource-creator-form/resource-creator-form.component.html +++ b/frontend/src/app/dashboard/component/user/resource-creator-form/resource-creator-form.component.html @@ -27,9 +27,7 @@ [form]="form" [fields]="fields" [model]="model"></formly-form> - <div - *ngIf="showToggles" - class="creator-toggles"> + <div class="creator-toggles"> <div class="toggle-item"> <label>Visibility:</label> <nz-switch diff --git a/frontend/src/app/dashboard/component/user/resource-creator-form/resource-creator-form.component.ts b/frontend/src/app/dashboard/component/user/resource-creator-form/resource-creator-form.component.ts index fc557c6d59..ad14b21d9b 100644 --- a/frontend/src/app/dashboard/component/user/resource-creator-form/resource-creator-form.component.ts +++ b/frontend/src/app/dashboard/component/user/resource-creator-form/resource-creator-form.component.ts @@ -20,7 +20,6 @@ import { Component, EventEmitter, Input, Output } from "@angular/core"; import { FormGroup, FormsModule } from "@angular/forms"; import { FormlyFieldConfig, FormlyModule } from "@ngx-formly/core"; -import { NgIf } from "@angular/common"; import { NzSpinComponent } from "ng-zorro-antd/spin"; import { NzSwitchComponent } from "ng-zorro-antd/switch"; import { NzButtonComponent } from "ng-zorro-antd/button"; @@ -39,7 +38,6 @@ import { ɵNzTransitionPatchDirective } from "ng-zorro-antd/core/transition-patc imports: [ NzSpinComponent, FormlyModule, - NgIf, NzSwitchComponent, FormsModule, NzButtonComponent, @@ -52,7 +50,6 @@ export class ResourceCreatorFormComponent { @Input({ required: true }) fields!: FormlyFieldConfig[]; @Input({ required: true }) model!: Record<string, unknown>; @Input() isCreating = false; - @Input() showToggles = true; @Input() isPublic = false; @Input() isDownloadable = false; @Output() isPublicChange = new EventEmitter<boolean>(); diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-creator/user-dataset-version-creator.component.html b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component.html similarity index 96% rename from frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-creator/user-dataset-version-creator.component.html rename to frontend/src/app/dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component.html index 65504590cf..4bf740e766 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-creator/user-dataset-version-creator.component.html +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component.html @@ -22,7 +22,6 @@ [fields]="fields" [model]="model" [isCreating]="isCreating" - [showToggles]="!isCreatingVersion" [isPublic]="isDatasetPublic" [isDownloadable]="isDatasetDownloadable" (isPublicChange)="onPublicStatusChange($event)" diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-creator/user-dataset-version-creator.component.spec.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component.spec.ts similarity index 70% rename from frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-creator/user-dataset-version-creator.component.spec.ts rename to frontend/src/app/dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component.spec.ts index a9d94d1486..14f70d2e5b 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-creator/user-dataset-version-creator.component.spec.ts +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component.spec.ts @@ -24,12 +24,12 @@ import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; import { FormsModule, ReactiveFormsModule } from "@angular/forms"; import { FieldType, FieldTypeConfig, FormlyModule } from "@ngx-formly/core"; import { HttpClientTestingModule } from "@angular/common/http/testing"; -import { NZ_MODAL_DATA, NzModalRef } from "ng-zorro-antd/modal"; +import { NzModalRef } from "ng-zorro-antd/modal"; import { of, Subject, throwError } from "rxjs"; -import { UserDatasetVersionCreatorComponent } from "./user-dataset-version-creator.component"; -import { DatasetService } from "../../../../../service/user/dataset/dataset.service"; -import { NotificationService } from "../../../../../../common/service/notification/notification.service"; -import { commonTestProviders } from "../../../../../../common/testing/test-utils"; +import { UserDatasetCreatorComponent } from "./user-dataset-creator.component"; +import { DatasetService } from "../../../../service/user/dataset/dataset.service"; +import { NotificationService } from "../../../../../common/service/notification/notification.service"; +import { commonTestProviders } from "../../../../../common/testing/test-utils"; // Minimal stand-in for the "input" formly type (the real one comes from the app's // UI formly module). Registering it lets formly materialize the declared fields @@ -37,26 +37,21 @@ import { commonTestProviders } from "../../../../../../common/testing/test-utils @Component({ template: "", standalone: true }) class StubFormlyInputComponent extends FieldType<FieldTypeConfig> {} -describe("UserDatasetVersionCreatorComponent", () => { +describe("UserDatasetCreatorComponent", () => { let modalClose: ReturnType<typeof vi.fn>; let createDataset: ReturnType<typeof vi.fn>; - let createDatasetVersion: ReturnType<typeof vi.fn>; let notifySuccess: ReturnType<typeof vi.fn>; let notifyError: ReturnType<typeof vi.fn>; - async function createFixture(modalData: { - isCreatingVersion: boolean; - did?: number; - }): Promise<ComponentFixture<UserDatasetVersionCreatorComponent>> { + async function createFixture(): Promise<ComponentFixture<UserDatasetCreatorComponent>> { modalClose = vi.fn(); createDataset = vi.fn(); - createDatasetVersion = vi.fn(); notifySuccess = vi.fn(); notifyError = vi.fn(); await TestBed.configureTestingModule({ imports: [ - UserDatasetVersionCreatorComponent, + UserDatasetCreatorComponent, BrowserAnimationsModule, FormsModule, ReactiveFormsModule, @@ -69,19 +64,18 @@ describe("UserDatasetVersionCreatorComponent", () => { HttpClientTestingModule, ], providers: [ - { provide: NZ_MODAL_DATA, useValue: modalData }, { provide: NzModalRef, useValue: { close: modalClose } }, - { provide: DatasetService, useValue: { createDataset, createDatasetVersion } }, + { provide: DatasetService, useValue: { createDataset } }, { provide: NotificationService, useValue: { success: notifySuccess, error: notifyError } }, ...commonTestProviders, ], }).compileComponents(); - return TestBed.createComponent(UserDatasetVersionCreatorComponent); + return TestBed.createComponent(UserDatasetCreatorComponent); } - it("should create and render the formly form (dataset-creation mode)", async () => { - const fixture = await createFixture({ isCreatingVersion: false }); + it("should create and render the formly form", async () => { + const fixture = await createFixture(); fixture.detectChanges(); expect(fixture.componentInstance).toBeTruthy(); @@ -89,22 +83,15 @@ describe("UserDatasetVersionCreatorComponent", () => { expect(fixture.componentInstance.form.contains("name")).toBe(true); }); - it("ngOnInit builds the version-description field when creating a version", async () => { - const fixture = await createFixture({ isCreatingVersion: true, did: 5 }); - fixture.detectChanges(); - - expect(fixture.componentInstance.fields.map(f => f.key)).toEqual(["versionDescription"]); - }); - - it("ngOnInit builds the name + description fields when creating a dataset", async () => { - const fixture = await createFixture({ isCreatingVersion: false }); + it("ngOnInit builds the name, description and contributors fields", async () => { + const fixture = await createFixture(); fixture.detectChanges(); expect(fixture.componentInstance.fields.map(f => f.key)).toEqual(["name", "description", "contributors"]); }); it("onClickCreate does nothing when the required name is empty (invalid form)", async () => { - const fixture = await createFixture({ isCreatingVersion: false }); + const fixture = await createFixture(); fixture.detectChanges(); const component = fixture.componentInstance; @@ -116,7 +103,7 @@ describe("UserDatasetVersionCreatorComponent", () => { }); it("onClickCreate creates a dataset with a sanitized name and closes the modal on success", async () => { - const fixture = await createFixture({ isCreatingVersion: false }); + const fixture = await createFixture(); fixture.detectChanges(); const component = fixture.componentInstance; component.form.get("name")?.setValue("My Dataset"); @@ -139,7 +126,7 @@ describe("UserDatasetVersionCreatorComponent", () => { }); it("onClickCreate reports both the typed and the sanitized name when the name had to be rewritten", async () => { - const fixture = await createFixture({ isCreatingVersion: false }); + const fixture = await createFixture(); fixture.detectChanges(); const component = fixture.componentInstance; // Padded on both sides, and the only junk at the end is the whitespace itself. @@ -164,7 +151,7 @@ describe("UserDatasetVersionCreatorComponent", () => { }); it("onClickCreate reports a name that needed no rewriting just once", async () => { - const fixture = await createFixture({ isCreatingVersion: false }); + const fixture = await createFixture(); fixture.detectChanges(); const component = fixture.componentInstance; // Already lower-case, alphanumeric and hyphenated: sanitization is a no-op. @@ -178,7 +165,7 @@ describe("UserDatasetVersionCreatorComponent", () => { }); it("onClickCreate notifies with the stored name and closes with null when dataset creation fails", async () => { - const fixture = await createFixture({ isCreatingVersion: false }); + const fixture = await createFixture(); fixture.detectChanges(); const component = fixture.componentInstance; component.form.get("name")?.setValue("My Dataset"); @@ -195,7 +182,7 @@ describe("UserDatasetVersionCreatorComponent", () => { }); it("onClickCreate locks the form while the creation request is still outstanding", async () => { - const fixture = await createFixture({ isCreatingVersion: false }); + const fixture = await createFixture(); fixture.detectChanges(); const component = fixture.componentInstance; component.form.get("name")?.setValue("My Dataset"); @@ -210,37 +197,8 @@ describe("UserDatasetVersionCreatorComponent", () => { expect(modalClose).not.toHaveBeenCalled(); }); - it("onClickCreate creates a dataset version and closes the modal on success", async () => { - const fixture = await createFixture({ isCreatingVersion: true, did: 42 }); - fixture.detectChanges(); - const component = fixture.componentInstance; - component.form.get("versionDescription")?.setValue("v2 notes"); - createDatasetVersion.mockReturnValue(of({ dvid: 1 })); - - component.onClickCreate(); - - expect(createDatasetVersion).toHaveBeenCalledWith(42, "v2 notes"); - expect(notifySuccess).toHaveBeenCalledWith("Version Created"); - expect(modalClose).toHaveBeenCalledWith({ dvid: 1 }); - expect(component.isCreating).toBe(false); - }); - - it("onClickCreate notifies and closes with null when version creation fails", async () => { - const fixture = await createFixture({ isCreatingVersion: true, did: 42 }); - fixture.detectChanges(); - const component = fixture.componentInstance; - component.form.get("versionDescription")?.setValue("v2"); - createDatasetVersion.mockReturnValue(throwError(() => ({ error: { message: "boom" } }))); - - component.onClickCreate(); - - expect(notifyError).toHaveBeenCalled(); - expect(modalClose).toHaveBeenCalledWith(null); - expect(component.isCreating).toBe(false); - }); - it("onClickCancel closes the modal with null", async () => { - const fixture = await createFixture({ isCreatingVersion: false }); + const fixture = await createFixture(); fixture.detectChanges(); fixture.componentInstance.onClickCancel(); @@ -249,7 +207,7 @@ describe("UserDatasetVersionCreatorComponent", () => { }); it("datasetNameSanitization lowercases, dashes non-alphanumerics, and flags the change", async () => { - const fixture = await createFixture({ isCreatingVersion: false }); + const fixture = await createFixture(); const component = fixture.componentInstance; expect(component.datasetNameSanitization(" My Data Set!! ")).toBe("my-data-set-"); @@ -257,7 +215,7 @@ describe("UserDatasetVersionCreatorComponent", () => { }); it("switch handlers toggle the public and downloadable flags", async () => { - const fixture = await createFixture({ isCreatingVersion: false }); + const fixture = await createFixture(); const component = fixture.componentInstance; component.onPublicStatusChange(true); @@ -274,19 +232,18 @@ describe("UserDatasetVersionCreatorComponent", () => { * swapping the two switches or the two buttons fails here. */ describe("rendered controls", () => { - /** Renders in dataset-creation mode (the only mode that shows the switches). */ - async function renderCreator(): Promise<ComponentFixture<UserDatasetVersionCreatorComponent>> { - const fixture = await createFixture({ isCreatingVersion: false }); + async function renderCreator(): Promise<ComponentFixture<UserDatasetCreatorComponent>> { + const fixture = await createFixture(); fixture.detectChanges(); fixture.componentInstance.form.get("name")?.setValue("My Dataset"); fixture.detectChanges(); return fixture; } - const switches = (fixture: ComponentFixture<UserDatasetVersionCreatorComponent>) => + const switches = (fixture: ComponentFixture<UserDatasetCreatorComponent>) => fixture.debugElement.queryAll(By.css("nz-switch")); - const click = (fixture: ComponentFixture<UserDatasetVersionCreatorComponent>, selector: string) => + const click = (fixture: ComponentFixture<UserDatasetCreatorComponent>, selector: string) => (fixture.nativeElement.querySelector(selector) as HTMLButtonElement).click(); it("submits the dataset from the create button", async () => { @@ -327,14 +284,5 @@ describe("UserDatasetVersionCreatorComponent", () => { expect(createDataset.mock.calls[0][0]).toMatchObject({ isPublic: false, isDownloadable: true }); }); - - it("offers no visibility or downloadability switch when adding a version", async () => { - const fixture = await createFixture({ isCreatingVersion: true, did: 5 }); - fixture.detectChanges(); - - // A version inherits both flags from its dataset, so the toggles are hidden. - expect(switches(fixture)).toHaveLength(0); - expect(fixture.nativeElement.querySelector("button.create-btn")).not.toBeNull(); - }); }); }); diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component.ts new file mode 100644 index 0000000000..763065dd97 --- /dev/null +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component.ts @@ -0,0 +1,179 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Component, OnInit } from "@angular/core"; +import { FormGroup } from "@angular/forms"; +import { FormlyFieldConfig } from "@ngx-formly/core"; +import { DatasetService } from "../../../../service/user/dataset/dataset.service"; +import { Dataset } from "../../../../../common/type/dataset"; +import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy"; +import { NotificationService } from "../../../../../common/service/notification/notification.service"; +import { HttpErrorResponse } from "@angular/common/http"; +import { NzModalRef } from "ng-zorro-antd/modal"; +import { contributorFieldGroup } from "../user-dataset-explorer/user-dataset-contributor-editor/contributor-form-fields"; +import { ResourceCreatorFormComponent } from "../../resource-creator-form/resource-creator-form.component"; + +@UntilDestroy() +@Component({ + selector: "texera-user-dataset-creator", + templateUrl: "./user-dataset-creator.component.html", + imports: [ResourceCreatorFormComponent], +}) +export class UserDatasetCreatorComponent implements OnInit { + public form: FormGroup = new FormGroup({}); + model: any = {}; + fields: FormlyFieldConfig[] = []; + isDatasetPublic: boolean = false; + isDatasetDownloadable: boolean = false; + + // used when creating the dataset + isDatasetNameSanitized: boolean = false; + + // boolean to control if is uploading + isCreating: boolean = false; + + constructor( + private modalRef: NzModalRef, + private datasetService: DatasetService, + private notificationService: NotificationService + ) {} + + ngOnInit() { + this.setFormFields(); + this.isDatasetNameSanitized = false; + } + + private setFormFields() { + this.fields = [ + { + key: "name", + type: "input", + templateOptions: { + label: "Name", + required: true, + }, + }, + { + key: "description", + type: "input", + defaultValue: "", + templateOptions: { + label: "Description", + }, + }, + { + key: "contributors", + type: "array", + templateOptions: { + label: "Add a New Contributor", + }, + fieldArray: { + fieldGroup: contributorFieldGroup(), + }, + }, + ]; + } + + datasetNameSanitization(datasetName: string): string { + // Remove leading spaces + let sanitizedDatasetName = datasetName.trimStart(); + + // Replace all characters that are not letters (a-z, A-Z), numbers (0-9) with a short dash "-" + sanitizedDatasetName = sanitizedDatasetName.replace(/[^a-zA-Z0-9]+/g, "-"); + + // Lower-case everything + sanitizedDatasetName = sanitizedDatasetName.toLowerCase(); + + // Track whether user’s input be changed + if (sanitizedDatasetName !== datasetName) { + this.isDatasetNameSanitized = true; + } + + return sanitizedDatasetName; + } + + private triggerValidation() { + Object.keys(this.form.controls).forEach(field => { + const control = this.form.get(field); + control?.markAsTouched({ onlySelf: true }); + }); + } + + onClickCancel() { + this.modalRef.close(null); + } + + onClickCreate() { + // check if the form is valid + this.triggerValidation(); + + if (!this.form.valid) { + return; // Stop further execution if the form is not valid + } + + this.isCreating = true; + // capture original and sanitized names + const originalName = this.form.get("name")?.value as string; + const sanitizedName = this.datasetNameSanitization(originalName); + + const ds: Dataset = { + name: sanitizedName, + description: this.form.get("description")?.value, + isPublic: this.isDatasetPublic, + isDownloadable: this.isDatasetDownloadable, + did: undefined, + ownerUid: undefined, + storagePath: undefined, + creationTime: undefined, + coverImage: undefined, + }; + this.datasetService + .createDataset(ds, this.form.get("contributors")?.value) + .pipe(untilDestroyed(this)) + .subscribe({ + next: res => { + const msg = this.isDatasetNameSanitized + ? `Dataset '${originalName}' was sanitized to '${sanitizedName}' and created successfully.` + : `Dataset '${sanitizedName}' created successfully.`; + + this.notificationService.success(msg); + this.isCreating = false; + // if creation succeed, emit the created dashboard dataset + this.modalRef.close(res); + }, + error: (res: unknown) => { + const err = res as HttpErrorResponse; + this.notificationService.error(`Dataset ${ds.name} creation failed: ${err.error.message}`); + this.isCreating = false; + // if creation failed, emit null value + this.modalRef.close(null); + }, + }); + } + + onPublicStatusChange(newValue: boolean): void { + // Handle the change in dataset public status + this.isDatasetPublic = newValue; + } + + onDownloadableStatusChange(newValue: boolean): void { + // Handle the change in dataset downloadable status + this.isDatasetDownloadable = newValue; + } +} diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-file-renderer/user-dataset-file-renderer.component.spec.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-file-renderer/user-dataset-file-renderer.component.spec.ts index c335bfe3c2..bb75909eaa 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-file-renderer/user-dataset-file-renderer.component.spec.ts +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-file-renderer/user-dataset-file-renderer.component.spec.ts @@ -65,18 +65,21 @@ describe("UserDatasetFileRendererComponent", () => { }); describe("reloadFileContent", () => { - it("flags an unsupported file type and does not hit the backend", () => { - const spy = vi.spyOn(TestBed.inject(DatasetService), "retrieveDatasetVersionSingleFile"); - // The ids are set so the early-return is what stops the request, not the missing ids. - component.resourceId = 1; - component.versionId = 2; - component.filePath = "archive.bin"; // -> OCTET_STREAM -> unsupported - - component.reloadFileContent(); - - expect(component.isFileTypePreviewUnsupported).toBe(true); - expect(spy).not.toHaveBeenCalled(); - }); + it.each(["archive.bin", "page.html", "report.pdf", "letter.msword", "slides.mspowerpoint"])( + "flags %s as unsupported and does not hit the backend", + filePath => { + const spy = vi.spyOn(TestBed.inject(DatasetService), "retrieveDatasetVersionSingleFile"); + // The ids are set so the early-return is what stops the request, not the missing ids. + component.resourceId = 1; + component.versionId = 2; + component.filePath = filePath; + + component.reloadFileContent(); + + expect(component.isFileTypePreviewUnsupported).toBe(true); + expect(spy).not.toHaveBeenCalled(); + } + ); it("flags an oversized file and does not hit the backend", () => { const spy = vi.spyOn(TestBed.inject(DatasetService), "retrieveDatasetVersionSingleFile"); 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 d744f6dd76..871ac4cf0d 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 @@ -50,13 +50,9 @@ export const MIME_TYPES = { CSV: "text/csv", TXT: "text/plain", MD: "text/markdown", - HTML: "text/html", JSON: "application/json", - PDF: "application/pdf", - MSWORD: "application/msword", MSEXCEL: "application/vnd.ms-excel", XLSX: "application/vnd.ms-excel", - MSPOWERPOINT: "application/vnd.ms-powerpoint", MP4: "video/mp4", MP3: "audio/mpeg", OCTET_STREAM: "application/octet-stream", // Default binary format @@ -82,7 +78,6 @@ export const MIME_TYPE_SIZE_LIMITS_MB = { [MIME_TYPES.MSEXCEL]: 10 * 1024 * 1024, // 10 MB for Excel spreadsheets [MIME_TYPES.MP4]: 50 * 1024 * 1024, // 50 MB for MP4 videos [MIME_TYPES.MP3]: 10 * 1024 * 1024, // 10 MB for MP3 audio files - [MIME_TYPES.OCTET_STREAM]: 5 * 1024 * 1024, // Default size for other binary formats }; @UntilDestroy() @@ -107,8 +102,6 @@ export const MIME_TYPE_SIZE_LIMITS_MB = { ], }) export class UserDatasetFileRendererComponent implements OnInit, OnChanges, OnDestroy { - private DEFAULT_MAX_SIZE = 5 * 1024 * 1024; // 5 MB - public fileURL: string | undefined; // safe url is used to display some formats including image public safeFileURL: SafeUrl | undefined; @@ -210,7 +203,7 @@ export class UserDatasetFileRendererComponent implements OnInit, OnChanges, OnDe this.onFileTypePreviewUnsupported(); return; } - const limit = MIME_TYPE_SIZE_LIMITS_MB[mimeType] ?? this.DEFAULT_MAX_SIZE; + const limit = MIME_TYPE_SIZE_LIMITS_MB[mimeType]; if (this.fileSize != null && this.fileSize > limit) { this.onFileSizeNotLoadable(); return; @@ -230,7 +223,7 @@ export class UserDatasetFileRendererComponent implements OnInit, OnChanges, OnDe this.onFileTypePreviewUnsupported(); return; } - const MaxSize = MIME_TYPE_SIZE_LIMITS_MB[blobMimeType] || this.DEFAULT_MAX_SIZE; + const MaxSize = MIME_TYPE_SIZE_LIMITS_MB[blobMimeType]; const fileSize = blob.size; if (fileSize > MaxSize) { this.onFileSizeNotLoadable(); @@ -348,7 +341,7 @@ export class UserDatasetFileRendererComponent implements OnInit, OnChanges, OnDe } isPreviewSupported(mimeType: string) { - return mimeType !== MIME_TYPES.OCTET_STREAM && Object.hasOwnProperty.call(MIME_TYPE_SIZE_LIMITS_MB, mimeType); + return Object.hasOwnProperty.call(MIME_TYPE_SIZE_LIMITS_MB, mimeType); } private readFileAsText(blob: Blob, isCurrent: () => boolean = () => true) { diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-creator/user-dataset-version-creator.component.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-creator/user-dataset-version-creator.component.ts deleted file mode 100644 index d5c2bd870d..0000000000 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-creator/user-dataset-version-creator.component.ts +++ /dev/null @@ -1,219 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { Component, inject, OnInit } from "@angular/core"; -import { FormGroup } from "@angular/forms"; -import { FormlyFieldConfig } from "@ngx-formly/core"; -import { DatasetService } from "../../../../../service/user/dataset/dataset.service"; -import { Dataset } from "../../../../../../common/type/dataset"; -import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy"; -import { NotificationService } from "../../../../../../common/service/notification/notification.service"; -import { HttpErrorResponse } from "@angular/common/http"; -import { NZ_MODAL_DATA, NzModalRef } from "ng-zorro-antd/modal"; -import { contributorFieldGroup } from "../user-dataset-contributor-editor/contributor-form-fields"; -import { ResourceCreatorFormComponent } from "../../../resource-creator-form/resource-creator-form.component"; - -@UntilDestroy() -@Component({ - selector: "texera-user-dataset-version-creator", - templateUrl: "./user-dataset-version-creator.component.html", - imports: [ResourceCreatorFormComponent], -}) -export class UserDatasetVersionCreatorComponent implements OnInit { - readonly isCreatingVersion: boolean = inject(NZ_MODAL_DATA).isCreatingVersion; - - readonly did: number = inject(NZ_MODAL_DATA)?.did ?? undefined; - - public form: FormGroup = new FormGroup({}); - model: any = {}; - fields: FormlyFieldConfig[] = []; - isDatasetPublic: boolean = false; - isDatasetDownloadable: boolean = false; - - // used when creating the dataset - isDatasetNameSanitized: boolean = false; - - // boolean to control if is uploading - isCreating: boolean = false; - - constructor( - private modalRef: NzModalRef, - private datasetService: DatasetService, - private notificationService: NotificationService - ) {} - - ngOnInit() { - this.setFormFields(); - this.isDatasetNameSanitized = false; - } - - private setFormFields() { - this.fields = this.isCreatingVersion - ? [ - // Fields when isCreatingVersion is true - { - key: "versionDescription", - type: "input", - defaultValue: "", - templateOptions: { - label: "Describe the new version", - required: false, - }, - }, - ] - : [ - // Fields when isCreatingVersion is false - { - key: "name", - type: "input", - templateOptions: { - label: "Name", - required: true, - }, - }, - { - key: "description", - type: "input", - defaultValue: "", - templateOptions: { - label: "Description", - }, - }, - { - key: "contributors", - type: "array", - templateOptions: { - label: "Add a New Contributor", - }, - fieldArray: { - fieldGroup: contributorFieldGroup(), - }, - }, - ]; - } - - datasetNameSanitization(datasetName: string): string { - // Remove leading spaces - let sanitizedDatasetName = datasetName.trimStart(); - - // Replace all characters that are not letters (a-z, A-Z), numbers (0-9) with a short dash "-" - sanitizedDatasetName = sanitizedDatasetName.replace(/[^a-zA-Z0-9]+/g, "-"); - - // Lower-case everything - sanitizedDatasetName = sanitizedDatasetName.toLowerCase(); - - // Track whether user’s input be changed - if (sanitizedDatasetName !== datasetName) { - this.isDatasetNameSanitized = true; - } - - return sanitizedDatasetName; - } - - private triggerValidation() { - Object.keys(this.form.controls).forEach(field => { - const control = this.form.get(field); - control?.markAsTouched({ onlySelf: true }); - }); - } - - onClickCancel() { - this.modalRef.close(null); - } - - onClickCreate() { - // check if the form is valid - this.triggerValidation(); - - if (!this.form.valid) { - return; // Stop further execution if the form is not valid - } - - this.isCreating = true; - if (this.isCreatingVersion && this.did) { - const versionName = this.form.get("versionDescription")?.value; - this.datasetService - .createDatasetVersion(this.did, versionName) - .pipe(untilDestroyed(this)) - .subscribe({ - next: res => { - this.notificationService.success("Version Created"); - this.isCreating = false; - // creation succeed, emit created version - this.modalRef.close(res); - }, - error: (res: unknown) => { - const err = res as HttpErrorResponse; - this.notificationService.error(`Version creation failed: ${err.error.message}`); - this.isCreating = false; - // creation failed, emit null value - this.modalRef.close(null); - }, - }); - } else { - // capture original and sanitized names - const originalName = this.form.get("name")?.value as string; - const sanitizedName = this.datasetNameSanitization(originalName); - - const ds: Dataset = { - name: sanitizedName, - description: this.form.get("description")?.value, - isPublic: this.isDatasetPublic, - isDownloadable: this.isDatasetDownloadable, - did: undefined, - ownerUid: undefined, - storagePath: undefined, - creationTime: undefined, - coverImage: undefined, - }; - this.datasetService - .createDataset(ds, this.form.get("contributors")?.value) - .pipe(untilDestroyed(this)) - .subscribe({ - next: res => { - const msg = this.isDatasetNameSanitized - ? `Dataset '${originalName}' was sanitized to '${sanitizedName}' and created successfully.` - : `Dataset '${sanitizedName}' created successfully.`; - - this.notificationService.success(msg); - this.isCreating = false; - // if creation succeed, emit the created dashboard dataset - this.modalRef.close(res); - }, - error: (res: unknown) => { - const err = res as HttpErrorResponse; - this.notificationService.error(`Dataset ${ds.name} creation failed: ${err.error.message}`); - this.isCreating = false; - // if creation failed, emit null value - this.modalRef.close(null); - }, - }); - } - } - - onPublicStatusChange(newValue: boolean): void { - // Handle the change in dataset public status - this.isDatasetPublic = newValue; - } - - onDownloadableStatusChange(newValue: boolean): void { - // Handle the change in dataset downloadable status - this.isDatasetDownloadable = newValue; - } -} diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset.component.spec.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset.component.spec.ts index 12411ecbee..4137337c2c 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset.component.spec.ts +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset.component.spec.ts @@ -37,7 +37,7 @@ import { commonTestImports, commonTestProviders } from "../../../../common/testi import { UserDatasetComponent } from "./user-dataset.component"; import { USER_DATASET } from "../../../../app-routing.constant"; -import { UserDatasetVersionCreatorComponent } from "./user-dataset-explorer/user-dataset-version-creator/user-dataset-version-creator.component"; +import { UserDatasetCreatorComponent } from "./user-dataset-creator/user-dataset-creator.component"; import { SortMethod } from "../../../type/sort-method"; import { User } from "../../../../common/type/user"; @@ -168,8 +168,8 @@ describe("UserDatasetComponent", () => { }); }); - describe("search filterScope variants", () => { - it('defaults to "private": passes isLogin through, includePublic = false', async () => { + describe("search visibility", () => { + it("passes isLogin through and leaves public datasets out", async () => { component.isLogin = true; component.sortMethod = SortMethod.EditTimeDesc; await component.search(); @@ -191,29 +191,9 @@ describe("UserDatasetComponent", () => { ); }); - it('"public": forces isLogin = false, includePublic = true', async () => { - component.isLogin = true; - await component.search(false, "public"); - await capturedLoadMoreFn!(0, 20); - - const args = searchServiceMock.executeSearch.mock.calls[0]; - expect(args[6]).toBe(false); // isLogin - expect(args[7]).toBe(true); // includePublic - }); - - it('"all": passes isLogin through, includePublic = true', async () => { - component.isLogin = true; - await component.search(false, "all"); - await capturedLoadMoreFn!(0, 20); - - const args = searchServiceMock.executeSearch.mock.calls[0]; - expect(args[6]).toBe(true); - expect(args[7]).toBe(true); - }); - - it('"private" with isLogin = false: passes false through, includePublic = false', async () => { + it("passes a signed-out isLogin through and still leaves public datasets out", async () => { component.isLogin = false; - await component.search(false, "private"); + await component.search(); await capturedLoadMoreFn!(0, 20); const args = searchServiceMock.executeSearch.mock.calls[0]; @@ -278,15 +258,14 @@ describe("UserDatasetComponent", () => { }); describe("onClickOpenDatasetAddComponent", () => { - it("opens UserDatasetVersionCreatorComponent with isCreatingVersion: false", () => { + it("opens UserDatasetCreatorComponent", () => { modalServiceMock.create.mockReturnValue({ afterClose: of(null) }); component.onClickOpenDatasetAddComponent(); expect(modalServiceMock.create).toHaveBeenCalledTimes(1); const config = modalServiceMock.create.mock.calls[0][0]; - expect(config.nzContent).toBe(UserDatasetVersionCreatorComponent); - expect(config.nzData).toEqual({ isCreatingVersion: false }); + expect(config.nzContent).toBe(UserDatasetCreatorComponent); expect(config.nzFooter).toBeNull(); }); diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset.component.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset.component.ts index 409f55218f..40aa314c7e 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset.component.ts +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset.component.ts @@ -32,7 +32,7 @@ import { SortButtonComponent } from "../sort-button/sort-button.component"; import { firstValueFrom } from "rxjs"; import { USER_DATASET } from "../../../../app-routing.constant"; import { NzModalService } from "ng-zorro-antd/modal"; -import { UserDatasetVersionCreatorComponent } from "./user-dataset-explorer/user-dataset-version-creator/user-dataset-version-creator.component"; +import { UserDatasetCreatorComponent } from "./user-dataset-creator/user-dataset-creator.component"; import { DashboardDataset } from "../../../type/dashboard-dataset.interface"; import { NzMessageService } from "ng-zorro-antd/message"; import { map, tap } from "rxjs/operators"; @@ -140,16 +140,8 @@ export class UserDatasetComponent implements AfterViewInit { localStorage.setItem(UserDatasetComponent.VIEW_MODE_STORAGE_KEY, viewType); } - /* - * Executes a dataset search with filtering, sorting. - * - * Parameters: - * - filterScope = "all" | "public" | "private" - Determines visibility scope for search: - * - "all": includes all datasets, public and private - * - "public": limits the search to public datasets - * - "private": limits the search to dataset where the user has direct access rights. - */ - async search(forced: Boolean = false, filterScope: "all" | "public" | "private" = "private"): Promise<void> { + /* Executes a dataset search with filtering, sorting. */ + async search(forced: Boolean = false): Promise<void> { const sameList = this.masterFilterList !== null && this.filters.masterFilterList.length === this.masterFilterList.length && @@ -165,11 +157,6 @@ export class UserDatasetComponent implements AfterViewInit { } let filterParams = this.filters.getSearchFilterParameters(); - // if the filter requires only public datasets, the public search should be invoked, and the search method should - // set the isLogin parameter to false in this case - const isLogin = filterScope === "public" ? false : this.isLogin; - const includePublic = filterScope === "all" || filterScope === "public"; - this.searchResultsComponent.reset((start, count) => { return firstValueFrom( this.searchService @@ -180,8 +167,8 @@ export class UserDatasetComponent implements AfterViewInit { count, "dataset", this.sortMethod, - isLogin, - includePublic + this.isLogin, + false ) .pipe( tap(({ hasMismatch }) => { @@ -203,11 +190,8 @@ export class UserDatasetComponent implements AfterViewInit { public onClickOpenDatasetAddComponent(): void { const modal = this.modalService.create({ nzTitle: "Create New Dataset", - nzContent: UserDatasetVersionCreatorComponent, + nzContent: UserDatasetCreatorComponent, nzFooter: null, - nzData: { - isCreatingVersion: false, - }, nzBodyStyle: { resize: "both", overflow: "auto", diff --git a/frontend/src/app/dashboard/component/user/user-model/user-model-creator/user-model-creator.component.spec.ts b/frontend/src/app/dashboard/component/user/user-model/user-model-creator/user-model-creator.component.spec.ts index a2a1699dde..9b795940f3 100644 --- a/frontend/src/app/dashboard/component/user/user-model/user-model-creator/user-model-creator.component.spec.ts +++ b/frontend/src/app/dashboard/component/user/user-model/user-model-creator/user-model-creator.component.spec.ts @@ -86,11 +86,10 @@ describe("UserModelCreatorComponent", () => { return TestBed.createComponent(UserModelCreatorComponent); } - it("renders the four create fields, with no version-description field", async () => { + it("renders the four create fields", async () => { const fixture = await createFixture(); fixture.detectChanges(); - // Create-only: the dataset creator's dual-purpose version branch is deliberately not forked. expect(fixture.componentInstance.fields.map(f => f.key)).toEqual(["name", "description", "framework", "format"]); expect(fixture.componentInstance.form.contains("name")).toBe(true); }); diff --git a/frontend/src/app/workspace/component/result-exportation/result-exportation.component.spec.ts b/frontend/src/app/workspace/component/result-exportation/result-exportation.component.spec.ts index 9470b694dd..e849f7ffaf 100644 --- a/frontend/src/app/workspace/component/result-exportation/result-exportation.component.spec.ts +++ b/frontend/src/app/workspace/component/result-exportation/result-exportation.component.spec.ts @@ -32,7 +32,7 @@ import { DatasetService } from "../../../dashboard/service/user/dataset/dataset. import { WorkflowActionService } from "../../service/workflow-graph/model/workflow-action.service"; import { WorkflowResultService } from "../../service/workflow-result/workflow-result.service"; import { ComputingUnitStatusService } from "../../../common/service/computing-unit/computing-unit-status/computing-unit-status.service"; -import { UserDatasetVersionCreatorComponent } from "../../../dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-creator/user-dataset-version-creator.component"; +import { UserDatasetCreatorComponent } from "../../../dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component"; import { DashboardDataset } from "../../../dashboard/type/dashboard-dataset.interface"; import { NZ_MODAL_DATA, NzModalRef, NzModalService } from "ng-zorro-antd/modal"; @@ -205,7 +205,7 @@ describe("ResultExportationComponent", () => { expect(modalCreate).toHaveBeenCalledTimes(1); const config = modalCreate.mock.calls[0][0]; expect(config.nzTitle).toBe("Create New Dataset"); - expect(config.nzContent).toBe(UserDatasetVersionCreatorComponent); + expect(config.nzContent).toBe(UserDatasetCreatorComponent); // afterClose emitted a dataset, so the component adopts it into its lists. expect(component.userAccessibleDatasets[0]).toBe(created); expect(component.inputDatasetName).toBe("brand-new"); diff --git a/frontend/src/app/workspace/component/result-exportation/result-exportation.component.ts b/frontend/src/app/workspace/component/result-exportation/result-exportation.component.ts index 96fafe7ca7..a59304039d 100644 --- a/frontend/src/app/workspace/component/result-exportation/result-exportation.component.ts +++ b/frontend/src/app/workspace/component/result-exportation/result-exportation.component.ts @@ -30,7 +30,7 @@ import { WorkflowActionService } from "../../service/workflow-graph/model/workfl import { WorkflowResultService } from "../../service/workflow-result/workflow-result.service"; import { ComputingUnitStatusService } from "../../../common/service/computing-unit/computing-unit-status/computing-unit-status.service"; import { DashboardWorkflowComputingUnit } from "../../../common/type/workflow-computing-unit"; -import { UserDatasetVersionCreatorComponent } from "../../../dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-creator/user-dataset-version-creator.component"; +import { UserDatasetCreatorComponent } from "../../../dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component"; import { NgIf, NgFor } from "@angular/common"; import { NzAlertComponent } from "ng-zorro-antd/alert"; import { FormsModule } from "@angular/forms"; @@ -282,10 +282,7 @@ export class ResultExportationComponent implements OnInit { onClickCreateNewDataset(): void { const modal = this.modalService.create({ nzTitle: "Create New Dataset", - nzContent: UserDatasetVersionCreatorComponent, - nzData: { - isCreatingVersion: false, - }, + nzContent: UserDatasetCreatorComponent, nzFooter: null, nzWidth: 500, });
