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-9522-f030df12b73c2c6a8f2e8b325c6e762d54fead7f in repository https://gitbox.apache.org/repos/asf/texera.git
commit 941051bf2a94237bc312e7ebe63f747a0c5f0403 Author: Xinyuan Lin <[email protected]> AuthorDate: Sun Nov 22 04:05:33 2026 +0000 refactor(frontend): share dataset and model resource UI (#9522) ### What changes were proposed in this PR? Extracts shared stylesheets, Settings-tab cards, overview statistics projection, Formly field builders, upload-tuning loaders, and test fixtures across dataset and model management UI components with no user-facing behavior change: | Area | Shared abstraction | Consumers | | --- | --- | --- | | Detail layout & cards | `_resource-detail-shared.scss`, `overviewStatistics` (`@for`), single-icon binding & `createFiletreeFixture` | Dataset detail, model detail, versions browser, filetree | | Settings tab | `ResourceDetailSettingsComponent` (`div[texeraResourceDetailSettings]`) | Dataset detail Settings, model detail Settings | | Creator & contributor forms | `resourceNameAndDescriptionFields`, `contributorInput`, `createFormlyModalFixture` | Dataset creator, model creator, contributor editor | | Version uploader | Table-driven `loadUploadSettings`, shared `stageFile`/`mount`/`expectAbortRequest` test helpers | Version uploader & spec | ### Any related issues, documentation, discussions? Closes #9520. ### How was this PR tested? Ran in `frontend/` on `63e9447924`: - `yarn format:ci` — passed - `yarn tsc --noEmit -p src/tsconfig.app.json` — passed - `yarn tsc --noEmit -p src/tsconfig.spec.json` — passed - `yarn test:ci` — `254 passed (254)` files, `7290 passed | 1 skipped (7291)` tests - `yarn ng run gui:test-browser --watch=false --progress=false` — `3 passed (3)` files, `23 passed (23)` tests in Chromium - `yarn build:ci --skip-nx-cache` — production build succeeded - Review-round follow-up (`8bfb77b1e6`): `prettier-eslint`, `eslint`, `tsc` (app + spec), and `ng test` across `dataset-detail`, `model-detail`, and `versions-files-browser` (`231/231` passed) - **Playwright Chromium (`1280x980`) against `ng serve` with stubbed `/api/**`**: navigated to `/user/dataset/1` (`Data Card`, `Versions & Files`, `Settings`) and `/user/model/1` (`Model Card`, `Settings`) before and after refactoring to verify identical layout and controls. #### Visual comparison (`1280x980` desktop) | View | Before (`main`) | After (this PR) | | --- | --- | --- | | Dataset Data Card |  |  | | Dataset Versions & Files |  |  | | Dataset Settings |  |  | | Model Card |  |  | | Model Settings |  |  | ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Antigravity IDE (Gemini 3.8 Flash) --- .../component/user/_resource-detail-shared.scss | 208 ++++++++++++ .../component/user/formly-modal-test-fixture.ts | 51 +++ .../resource-creator-form.component.ts | 8 + .../user/resource-detail-settings.component.ts | 209 ++++++++++++ .../user-dataset-creator.component.spec.ts | 82 ++--- .../user-dataset-creator.component.ts | 22 +- .../dataset-detail.component.html | 122 ++----- .../dataset-detail.component.scss | 350 +-------------------- .../dataset-detail.component.ts | 21 +- .../contributor-form-fields.ts | 42 +-- ...er-dataset-contributor-editor.component.spec.ts | 69 ++-- ...aset-version-filetree.component.browser.spec.ts | 9 +- .../user-dataset-version-filetree.component.html | 8 +- ...user-dataset-version-filetree.component.spec.ts | 60 ++-- .../user-dataset-version-filetree.test-utils.ts | 8 + .../user-model-creator.component.spec.ts | 84 ++--- .../user-model-creator.component.ts | 49 +-- .../model-detail.component.html | 133 ++------ .../model-detail.component.scss | 332 +------------------ .../user-model-explorer/model-detail.component.ts | 22 +- .../version-uploader.component.spec.ts | 241 +++++--------- .../version-uploader/version-uploader.component.ts | 35 +-- .../versions-files-browser.component.scss | 6 +- 23 files changed, 801 insertions(+), 1370 deletions(-) diff --git a/frontend/src/app/dashboard/component/user/_resource-detail-shared.scss b/frontend/src/app/dashboard/component/user/_resource-detail-shared.scss new file mode 100644 index 0000000000..92157e7f2f --- /dev/null +++ b/frontend/src/app/dashboard/component/user/_resource-detail-shared.scss @@ -0,0 +1,208 @@ +// 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. + +@mixin status-tags { + .status-tag-row { + margin-top: 16px; + display: flex; + align-items: center; + gap: 5px; + } + + .status-tag { + padding: 3px 10px 3px 3px; + font-size: 13px; + display: inline-flex; + align-items: center; + gap: 5px; + background: #fff; + border-radius: 5px; + + i { + width: 22px; + height: 22px; + display: inline-flex; + align-items: center; + justify-content: center; + border-radius: 4px; + background: #f0f0f0; + } + } + + .tag-public i { + color: #3b82f6; + background: #eff6ff; + } + + .tag-downloadable i { + color: #22c55e; + background: #f0fdf4; + } +} + +@mixin like-states { + .like-tag { + cursor: pointer; + } + + .like-tag.liked { + i { + color: #ef4444; + background: #fef2f2; + } + } + + .like-tag.disabled { + cursor: not-allowed; + opacity: 0.55; + } +} + +@mixin tab-bar { + nz-tabs { + margin-top: 6px; + } + + ::ng-deep .ant-tabs-nav { + padding-left: 16px; + } +} + +@mixin data-card { + // Two side-by-side cards filling the full tab width: a wide description card + // and a narrower stats card. The flex grow ratio is the single source of + // truth for their proportions (basis 0), so no width/max-width competes. + .data-card-columns { + display: flex; + align-items: flex-start; + gap: 20px; + margin-top: 24px; + width: 100%; + // Match the tab bar's left inset (.ant-tabs-nav padding-left) so the cards + // line up with the tab labels above, not the page's outer edge. + padding-left: 16px; + } + + .data-card { + border-radius: 8px; + border: 1px solid #d9d9d9; + // Let each card shrink to its flex share regardless of content width; without + // this the default min-width:auto keeps them from shrinking, skewing the + // ratio and leaving odd empty gaps. + min-width: 0; + } + + // Left card takes ~3/4 of the row, stats card ~1/4 — grow ratio with basis 0 + // so the split is exact and content-independent. + .data-card-main { + flex: 3 1 0; + } + + .data-card-details { + flex: 1 1 0; + } + + // Stack the two cards full-width on narrow viewports. + @media (max-width: 768px) { + .data-card-columns { + flex-direction: column; + align-items: stretch; + } + } + + // Matches the app's standard card-section heading convention (e.g. the + // Settings tab's "General" card title): bold, dark, slightly larger than + // body text, with a clear gap before the content below. + .data-card-heading { + font-size: 18px; + font-weight: 600; + color: rgba(0, 0, 0, 0.85); + margin: 0 0 20px; + } + + // Plain text, no box/border styling — larger size keeps it readable as prose. + .data-card-description { + font-size: 16px; + line-height: 1.6; + margin-bottom: 32px; + } + + // Empty state: muted grey italic so it reads as "nothing here yet", not broken. + .empty-description { + color: rgba(0, 0, 0, 0.4); + font-style: italic; + } + + // Stats as a full-width vertical list, one fact per row, avoiding the awkward + // wrapping of the previous cramped horizontal layout. + .data-card-stats { + display: flex; + flex-direction: column; + } + + .stat-row { + display: flex; + justify-content: space-between; + align-items: baseline; + gap: 16px; + padding: 12px 0; + border-bottom: 1px solid #f0f0f0; + + &:last-child { + border-bottom: none; + } + } + + .stat-label { + font-size: 13px; + font-weight: 600; + color: rgba(0, 0, 0, 0.85); + flex-shrink: 0; + } + + .stat-value { + font-weight: 400; + color: rgba(0, 0, 0, 0.45); + text-align: right; + word-break: break-word; + } +} + +@mixin header($kind) { + .#{$kind}-header { + display: flex; + gap: 24px; + } + + .#{$kind}-header-meta { + flex: 1; + } + + .#{$kind}-cover-image { + width: 280px; + height: 120px; + object-fit: cover; + border-radius: 8px; + margin-right: 80px; + } +} + +@mixin scrollable-tab { + height: 100%; + overflow-y: auto; + padding-bottom: 24px; +} diff --git a/frontend/src/app/dashboard/component/user/formly-modal-test-fixture.ts b/frontend/src/app/dashboard/component/user/formly-modal-test-fixture.ts new file mode 100644 index 0000000000..5f79c18056 --- /dev/null +++ b/frontend/src/app/dashboard/component/user/formly-modal-test-fixture.ts @@ -0,0 +1,51 @@ +/** + * 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, Type } from "@angular/core"; +import { ComponentFixture, TestBed, TestModuleMetadata } from "@angular/core/testing"; +import { ReactiveFormsModule } from "@angular/forms"; +import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; +import { FieldType, FieldTypeConfig, FormlyModule } from "@ngx-formly/core"; +import { NzModalRef } from "ng-zorro-antd/modal"; +import { commonTestProviders } from "../../../common/testing/test-utils"; + +// Formly still creates real controls and attaches the declared validators. +@Component({ template: "", standalone: true }) +class StubFormlyFieldComponent extends FieldType<FieldTypeConfig> {} + +/** Creates a TestBed component fixture with stubbed Formly field types and an NzModalRef close spy. */ +export async function createFormlyModalFixture<T>( + component: Type<T>, + fieldNames: readonly string[], + close: ReturnType<typeof vi.fn>, + { imports = [], providers = [] }: Pick<TestModuleMetadata, "imports" | "providers"> = {} +): Promise<ComponentFixture<T>> { + await TestBed.configureTestingModule({ + imports: [ + component, + BrowserAnimationsModule, + ReactiveFormsModule, + FormlyModule.forRoot({ types: fieldNames.map(name => ({ name, component: StubFormlyFieldComponent })) }), + ...imports, + ], + providers: [{ provide: NzModalRef, useValue: { close } }, ...providers, ...commonTestProviders], + }).compileComponents(); + + return TestBed.createComponent(component); +} 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 ad14b21d9b..8b6d4487fc 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 @@ -26,6 +26,14 @@ import { NzButtonComponent } from "ng-zorro-antd/button"; import { NzWaveDirective } from "ng-zorro-antd/core/wave"; import { ɵNzTransitionPatchDirective } from "ng-zorro-antd/core/transition-patch"; +/** Builds fresh required `name` and optional `description` Formly configs for resource creator modals. */ +export function resourceNameAndDescriptionFields(): FormlyFieldConfig[] { + return [ + { key: "name", type: "input", templateOptions: { label: "Name", required: true } }, + { key: "description", type: "input", defaultValue: "", templateOptions: { label: "Description" } }, + ]; +} + /** * The creation form shared by the dataset and model creators: the Formly fields, the visibility * and downloadability switches, and the Create and Cancel buttons. The parent keeps the state and diff --git a/frontend/src/app/dashboard/component/user/resource-detail-settings.component.ts b/frontend/src/app/dashboard/component/user/resource-detail-settings.component.ts new file mode 100644 index 0000000000..ba7f19bac3 --- /dev/null +++ b/frontend/src/app/dashboard/component/user/resource-detail-settings.component.ts @@ -0,0 +1,209 @@ +/** + * 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 { NgIf, TitleCasePipe } from "@angular/common"; +import { Component, EventEmitter, Input, Output } from "@angular/core"; +import { FormsModule } from "@angular/forms"; +import { NzButtonComponent } from "ng-zorro-antd/button"; +import { NzCardComponent } from "ng-zorro-antd/card"; +import { NzDividerComponent } from "ng-zorro-antd/divider"; +import { NzInputDirective } from "ng-zorro-antd/input"; +import { NzSwitchComponent } from "ng-zorro-antd/switch"; +import { MarkdownDescriptionComponent } from "./markdown-description/markdown-description.component"; + +/** + * Shared Settings-tab cards (General and Access & visibility) for dataset and model detail pages, + * with a projection slot for resource-specific middle cards and trailing sections. + */ +@Component({ + // eslint-disable-next-line @angular-eslint/component-selector -- Keep the existing settings scroll container as the host. + selector: "div[texeraResourceDetailSettings]", + imports: [ + FormsModule, + MarkdownDescriptionComponent, + NgIf, + NzButtonComponent, + NzCardComponent, + NzDividerComponent, + NzInputDirective, + NzSwitchComponent, + TitleCasePipe, + ], + template: ` + <nz-card class="settings-general-card"> + <h3 class="settings-card-title">General</h3> + + <div class="settings-name-row"> + <div class="settings-name-label"> + <label>{{ resourceType | titlecase }} name</label> + <p class="settings-hint">{{ nameHints[resourceType] }}</p> + <p + *ngIf="uploadsInFlight" + class="settings-hint"> + An upload is in progress — finish or cancel it in Versions & Files first, or it will be left incomplete. + </p> + </div> + <div class="settings-name-controls"> + <input + nz-input + [disabled]="uploadsInFlight" + [ngModel]="editedName" + (ngModelChange)="editedNameChange.emit($event)" /> + <button + nz-button + nzType="primary" + [disabled]="uploadsInFlight" + (click)="saveName.emit()"> + Save + </button> + </div> + </div> + + <nz-divider></nz-divider> + + <div class="settings-field"> + <label class="settings-field-label">Description</label> + <div class="settings-field-hint">Shown on cards.</div> + <texera-markdown-description + [description]="description" + [editable]="true" + [enableViewMore]="true" + (descriptionChange)="descriptionChange.emit($event)"> + </texera-markdown-description> + </div> + </nz-card> + + <ng-content select="[resourceSettingsBetweenCards]"></ng-content> + + <nz-card class="settings-general-card"> + <h3 class="settings-card-title">Access & visibility</h3> + + <div class="settings-name-row"> + <div class="settings-name-label"> + <label>Visibility</label> + <p class="settings-hint"> + {{ + isPublic + ? "Public — anyone can view this " + resourceType + "." + : "Private — only you and invited collaborators can see this " + resourceType + "." + }} + </p> + </div> + <div class="settings-name-controls"> + <nz-switch + [ngModel]="isPublic" + (ngModelChange)="publicChange.emit($event)" + nzCheckedChildren="public" + nzUnCheckedChildren="private"></nz-switch> + </div> + </div> + + <nz-divider></nz-divider> + + <div class="settings-name-row"> + <div class="settings-name-label"> + <label>Downloadable</label> + <p class="settings-hint"> + {{ + isDownloadable + ? "Viewers can download this " + resourceType + "." + : "Viewers can browse files but cannot download them." + }} + </p> + </div> + <div class="settings-name-controls"> + <nz-switch + [ngModel]="isDownloadable" + (ngModelChange)="downloadableChange.emit($event)" + [nzDisabled]="!isOwner" + nzCheckedChildren="allowed" + nzUnCheckedChildren="blocked"></nz-switch> + </div> + </div> + </nz-card> + + <ng-content></ng-content> + `, + styles: [ + ` + :host ::ng-deep .settings-general-card { + max-width: 700px; + margin: 24px auto 0; + border-radius: 16px; + border: 1px solid #d9d9d9; + } + :host ::ng-deep .settings-general-card .settings-card-title { + font-weight: 600; + margin-bottom: 20px; + } + :host ::ng-deep .settings-general-card .settings-field-label { + display: block; + font-weight: 600; + } + :host ::ng-deep .settings-general-card .settings-field-hint { + color: rgba(0, 0, 0, 0.45); + font-size: 12px; + margin-bottom: 8px; + } + :host ::ng-deep .settings-general-card .settings-name-row { + display: flex; + justify-content: space-between; + align-items: center; + gap: 16px; + } + :host ::ng-deep .settings-general-card .settings-name-row .settings-name-label label { + font-weight: 600; + } + :host ::ng-deep .settings-general-card .settings-name-row .settings-hint { + color: rgba(0, 0, 0, 0.45); + font-size: 12px; + margin: 4px 0 0; + } + :host ::ng-deep .settings-general-card .settings-name-row .settings-name-controls { + display: flex; + gap: 8px; + flex-shrink: 0; + } + :host ::ng-deep .settings-general-card .settings-name-row .settings-name-controls > input, + :host ::ng-deep .settings-general-card .settings-name-row .settings-name-controls > button { + border-radius: 8px; + } + `, + ], +}) +export class ResourceDetailSettingsComponent { + protected readonly nameHints = { + dataset: "Lowercase letters, numbers and hyphens.", + model: "Letters, numbers, underscores and hyphens.", + }; + + @Input({ required: true }) resourceType!: "dataset" | "model"; + @Input() editedName = ""; + @Input() uploadsInFlight = false; + @Input() description = ""; + @Input() isPublic = false; + @Input() isDownloadable = true; + @Input() isOwner = false; + + @Output() editedNameChange = new EventEmitter<string>(); + @Output() saveName = new EventEmitter<void>(); + @Output() descriptionChange = new EventEmitter<string>(); + @Output() publicChange = new EventEmitter<boolean>(); + @Output() downloadableChange = new EventEmitter<boolean>(); +} diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component.spec.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component.spec.ts index 14f70d2e5b..bd9ce5dc97 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component.spec.ts +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-creator/user-dataset-creator.component.spec.ts @@ -17,25 +17,15 @@ * under the License. */ -import { Component } from "@angular/core"; -import { ComponentFixture, TestBed } from "@angular/core/testing"; +import { ComponentFixture } from "@angular/core/testing"; import { By } from "@angular/platform-browser"; -import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; -import { FormsModule, ReactiveFormsModule } from "@angular/forms"; -import { FieldType, FieldTypeConfig, FormlyModule } from "@ngx-formly/core"; +import { FormsModule } from "@angular/forms"; import { HttpClientTestingModule } from "@angular/common/http/testing"; -import { NzModalRef } from "ng-zorro-antd/modal"; import { of, Subject, throwError } from "rxjs"; 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 -// into real form controls — with their validators — on render. -@Component({ template: "", standalone: true }) -class StubFormlyInputComponent extends FieldType<FieldTypeConfig> {} +import { createFormlyModalFixture } from "../../formly-modal-test-fixture"; describe("UserDatasetCreatorComponent", () => { let modalClose: ReturnType<typeof vi.fn>; @@ -49,34 +39,28 @@ describe("UserDatasetCreatorComponent", () => { notifySuccess = vi.fn(); notifyError = vi.fn(); - await TestBed.configureTestingModule({ - imports: [ - UserDatasetCreatorComponent, - BrowserAnimationsModule, - FormsModule, - ReactiveFormsModule, - FormlyModule.forRoot({ - types: ["input", "checkbox", "textarea", "array"].map(name => ({ - name, - component: StubFormlyInputComponent, - })), - }), - HttpClientTestingModule, - ], - providers: [ - { provide: NzModalRef, useValue: { close: modalClose } }, - { provide: DatasetService, useValue: { createDataset } }, - { provide: NotificationService, useValue: { success: notifySuccess, error: notifyError } }, - ...commonTestProviders, - ], - }).compileComponents(); - - return TestBed.createComponent(UserDatasetCreatorComponent); + return createFormlyModalFixture( + UserDatasetCreatorComponent, + ["input", "checkbox", "textarea", "array"], + modalClose, + { + imports: [FormsModule, HttpClientTestingModule], + providers: [ + { provide: DatasetService, useValue: { createDataset } }, + { provide: NotificationService, useValue: { success: notifySuccess, error: notifyError } }, + ], + } + ); } - it("should create and render the formly form", async () => { + async function render() { const fixture = await createFixture(); fixture.detectChanges(); + return fixture; + } + + it("should create and render the formly form", async () => { + const fixture = await render(); expect(fixture.componentInstance).toBeTruthy(); // Formly materializes the declared fields into real form controls on render. @@ -84,15 +68,13 @@ describe("UserDatasetCreatorComponent", () => { }); it("ngOnInit builds the name, description and contributors fields", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); + const fixture = await render(); 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(); - fixture.detectChanges(); + const fixture = await render(); const component = fixture.componentInstance; expect(component.form.valid).toBe(false); // name is required and empty @@ -103,8 +85,7 @@ describe("UserDatasetCreatorComponent", () => { }); it("onClickCreate creates a dataset with a sanitized name and closes the modal on success", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); + const fixture = await render(); const component = fixture.componentInstance; component.form.get("name")?.setValue("My Dataset"); component.form.get("description")?.setValue("desc"); @@ -126,8 +107,7 @@ describe("UserDatasetCreatorComponent", () => { }); it("onClickCreate reports both the typed and the sanitized name when the name had to be rewritten", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); + const fixture = await render(); const component = fixture.componentInstance; // Padded on both sides, and the only junk at the end is the whitespace itself. // That is what separates the four candidate trims: only stripping the leading @@ -151,8 +131,7 @@ describe("UserDatasetCreatorComponent", () => { }); it("onClickCreate reports a name that needed no rewriting just once", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); + const fixture = await render(); const component = fixture.componentInstance; // Already lower-case, alphanumeric and hyphenated: sanitization is a no-op. component.form.get("name")?.setValue("already-clean-1"); @@ -165,8 +144,7 @@ describe("UserDatasetCreatorComponent", () => { }); it("onClickCreate notifies with the stored name and closes with null when dataset creation fails", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); + const fixture = await render(); const component = fixture.componentInstance; component.form.get("name")?.setValue("My Dataset"); createDataset.mockReturnValue(throwError(() => ({ error: { message: "duplicate name" } }))); @@ -182,8 +160,7 @@ describe("UserDatasetCreatorComponent", () => { }); it("onClickCreate locks the form while the creation request is still outstanding", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); + const fixture = await render(); const component = fixture.componentInstance; component.form.get("name")?.setValue("My Dataset"); // Never emits: the request is still in flight when we look at the flag. @@ -198,8 +175,7 @@ describe("UserDatasetCreatorComponent", () => { }); it("onClickCancel closes the modal with null", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); + const fixture = await render(); fixture.componentInstance.onClickCancel(); 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 index 763065dd97..0164d24fd4 100644 --- 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 @@ -27,7 +27,10 @@ import { NotificationService } from "../../../../../common/service/notification/ 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"; +import { + ResourceCreatorFormComponent, + resourceNameAndDescriptionFields, +} from "../../resource-creator-form/resource-creator-form.component"; @UntilDestroy() @Component({ @@ -61,22 +64,7 @@ export class UserDatasetCreatorComponent implements OnInit { private setFormFields() { this.fields = [ - { - key: "name", - type: "input", - templateOptions: { - label: "Name", - required: true, - }, - }, - { - key: "description", - type: "input", - defaultValue: "", - templateOptions: { - label: "Description", - }, - }, + ...resourceNameAndDescriptionFields(), { key: "contributors", type: "array", diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/dataset-detail.component.html b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/dataset-detail.component.html index 7ef75951fa..8733919003 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/dataset-detail.component.html +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/dataset-detail.component.html @@ -105,26 +105,12 @@ <nz-card class="data-card data-card-details"> <div class="data-card-stats"> + @for (stat of overviewStatistics; track stat.label) { <div class="stat-row"> - <span class="stat-label">Created</span> - <span class="stat-value">{{ datasetCreationTime }}</span> - </div> - <div class="stat-row"> - <span class="stat-label">Last updated</span> - <span class="stat-value">{{ latestVersionCreationTime || "—" }}</span> - </div> - <div class="stat-row"> - <span class="stat-label">Versions</span> - <span class="stat-value">{{ versions.length }}</span> - </div> - <div class="stat-row"> - <span class="stat-label">Latest version file</span> - <span class="stat-value">{{ latestVersionFileName || "—" }}</span> - </div> - <div class="stat-row"> - <span class="stat-label">Latest version size</span> - <span class="stat-value">{{ formatSize(latestVersionSize) }}</span> + <span class="stat-label">{{ stat.label }}</span> + <span class="stat-value">{{ stat.value }}</span> </div> + } </div> </nz-card> </div> @@ -285,92 +271,20 @@ <nz-tab nzTitle="Settings" *ngIf="userHasWriteAccess()"> - <div class="settings-tab-content"> - <nz-card class="settings-general-card"> - <h3 class="settings-card-title">General</h3> - - <div class="settings-name-row"> - <div class="settings-name-label"> - <label>Dataset name</label> - <p class="settings-hint">Lowercase letters, numbers and hyphens.</p> - <p - *ngIf="uploadsInFlight" - class="settings-hint"> - An upload is in progress — finish or cancel it in Versions & Files first, or it will be left - incomplete. - </p> - </div> - <div class="settings-name-controls"> - <input - nz-input - [disabled]="uploadsInFlight" - [(ngModel)]="editedDatasetName" /> - <button - nz-button - nzType="primary" - [disabled]="uploadsInFlight" - (click)="onSaveDatasetName()"> - Save - </button> - </div> - </div> - - <nz-divider></nz-divider> - - <div class="settings-field"> - <label class="settings-field-label">Description</label> - <div class="settings-field-hint">Shown on cards.</div> - <texera-markdown-description - [description]="datasetDescription" - [editable]="userDatasetAccessLevel === 'WRITE'" - [enableViewMore]="true" - (descriptionChange)="onDatasetDescriptionChange($event)"> - </texera-markdown-description> - </div> - </nz-card> - - <nz-card class="settings-general-card"> - <h3 class="settings-card-title">Access & visibility</h3> - - <div class="settings-name-row"> - <div class="settings-name-label"> - <label>Visibility</label> - <p class="settings-hint"> - {{ datasetIsPublic ? "Public — anyone can view this dataset." : "Private — only you and invited - collaborators can see this dataset." }} - </p> - </div> - <div class="settings-name-controls"> - <nz-switch - [ngModel]="datasetIsPublic" - (ngModelChange)="onPublicStatusChange($event)" - [nzDisabled]="userDatasetAccessLevel !== 'WRITE'" - nzCheckedChildren="public" - nzUnCheckedChildren="private"></nz-switch> - </div> - </div> - - <nz-divider></nz-divider> - - <div class="settings-name-row"> - <div class="settings-name-label"> - <label>Downloadable</label> - <p class="settings-hint"> - {{ datasetIsDownloadable ? "Viewers can download this dataset." : "Viewers can browse files but cannot - download them." }} - </p> - </div> - <div class="settings-name-controls"> - <nz-switch - [ngModel]="datasetIsDownloadable" - (ngModelChange)="onDownloadableStatusChange($event)" - [nzDisabled]="!isOwner" - nzCheckedChildren="allowed" - nzUnCheckedChildren="blocked"></nz-switch> - </div> - </div> - </nz-card> - + <div + class="settings-tab-content" + texeraResourceDetailSettings + resourceType="dataset" + [(editedName)]="editedDatasetName" + [uploadsInFlight]="uploadsInFlight" + (saveName)="onSaveDatasetName()" + [description]="datasetDescription" + (descriptionChange)="onDatasetDescriptionChange($event)" + [isPublic]="datasetIsPublic" + (publicChange)="onPublicStatusChange($event)" + [isDownloadable]="datasetIsDownloadable" + (downloadableChange)="onDownloadableStatusChange($event)" + [isOwner]="isOwner"> <nz-card class="settings-general-card"> <h3 class="settings-card-title">Delete</h3> diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/dataset-detail.component.scss b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/dataset-detail.component.scss index 093ee1801e..f6b29cad5b 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/dataset-detail.component.scss +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/dataset-detail.component.scss @@ -17,15 +17,7 @@ * under the License. */ -.version-storage { - padding: 0 15px; - margin-bottom: 25px; -} - -.version-storage nz-select { - width: 100%; - margin: 0; -} +@use "../../resource-detail-shared" as detail; nz-layout { height: 100%; @@ -38,37 +30,6 @@ body { padding: 0; } -.right-sider { - height: 100%; - overflow-y: auto; - position: relative; - z-index: 0; -} - -.sider-resize-line { - display: flex; - align-items: center; - justify-content: center; - height: 100%; - width: 5px; - border-right: 1px solid #e8e8e8; -} - -.sider-resize-handle { - background: #fff; - border: 1px solid #ddd; - text-align: center; - font-size: 12px; - height: 20px; - line-height: 20px; -} - -.file-renderer { - width: 95%; - height: 80%; - margin: auto; -} - .grayed-out { filter: grayscale(1) opacity(0.7); background-color: #f0f0f0; /* Adjust the color as needed */ @@ -78,131 +39,15 @@ body { pointer-events: none; } -.select-and-button-container { - display: flex; - align-items: stretch; - gap: 10px; -} - -.spaced-button { - flex-shrink: 0; - width: 30px; - height: 24px; -} - -nz-select { - flex-grow: 1; -} - .file-title { display: flex; align-items: center; gap: 10px; } -.file-size, -.version-size, -.version-date { - font-size: 12px; - color: #8c8c8c; - display: inline-flex; - align-items: center; - gap: 4px; -} - -.version-date { - display: flex; -} +@include detail.status-tags; -.version-size { - margin-top: 8px; -} - -.icon-database, -.icon-file { - font-size: 14px; -} - -.empty-version-indicator { - margin-top: 15%; -} - -.status-tag-row { - margin-top: 16px; - display: flex; - align-items: center; - gap: 5px; -} - -.status-tag { - padding: 3px 10px 3px 3px; - font-size: 13px; - display: inline-flex; - align-items: center; - gap: 5px; - background: #fff; - border-radius: 5px; - - i { - width: 22px; - height: 22px; - display: inline-flex; - align-items: center; - justify-content: center; - border-radius: 4px; - background: #f0f0f0; - } -} - -.tag-public i { - color: #3b82f6; - background: #eff6ff; -} - -.tag-downloadable i { - color: #22c55e; - background: #f0fdf4; -} - -.like-tag { - cursor: pointer; -} - -.like-tag.liked { - i { - color: #ef4444; - background: #fef2f2; - } -} - -.like-tag.disabled { - cursor: not-allowed; - opacity: 0.55; -} - -.file-title { - display: flex; - align-items: center; - flex-wrap: wrap; - gap: 8px; - margin-bottom: 0; -} - -.file-title-main { - display: inline-flex; - align-items: center; - gap: 6px; - min-width: 0; -} - -.copy-path-btn { - padding: 0 4px; - height: auto; - line-height: 1; - display: inline-flex; - align-items: center; - justify-content: center; -} +@include detail.like-states; .file-size { display: inline-flex; @@ -210,41 +55,16 @@ nz-select { gap: 4px; } -.dataset-header { - display: flex; - gap: 24px; -} - -.dataset-header-meta { - flex: 1; -} - -.dataset-cover-image { - width: 280px; - height: 120px; - object-fit: cover; - border-radius: 8px; - margin-right: 80px; -} +@include detail.header("dataset"); -nz-tabs { - margin-top: 6px; -} - -::ng-deep .ant-tabs-nav { - padding-left: 16px; -} +@include detail.tab-bar; .versions-tab-content { - height: 100%; - overflow-y: auto; - padding-bottom: 24px; + @include detail.scrollable-tab; } .data-card-tab-content { - height: 100%; - overflow-y: auto; - padding-bottom: 24px; + @include detail.scrollable-tab; } // The Settings tab shares the tab area's bounded height with the Data Card @@ -253,162 +73,10 @@ nz-tabs { // be scrolled fully into view, with bottom padding for breathing room below // the last card. .settings-tab-content { - height: 100%; - overflow-y: auto; - padding-bottom: 24px; -} - -// Two side-by-side cards filling the full tab width: a wide description card -// and a narrower stats card. The flex grow ratio is the single source of -// truth for their proportions (basis 0), so no width/max-width competes. -.data-card-columns { - display: flex; - align-items: flex-start; - gap: 20px; - margin-top: 24px; - width: 100%; - // Match the tab bar's left inset (.ant-tabs-nav padding-left) so the cards - // line up with the tab labels above, not the page's outer edge. - padding-left: 16px; -} - -.data-card { - border-radius: 8px; - border: 1px solid #d9d9d9; - // Let each card shrink to its flex share regardless of content width; without - // this the default min-width:auto keeps them from shrinking, skewing the - // ratio and leaving odd empty gaps. - min-width: 0; -} - -// Left card takes ~3/4 of the row, stats card ~1/4 — grow ratio with basis 0 -// so the split is exact and content-independent. -.data-card-main { - flex: 3 1 0; -} - -.data-card-details { - flex: 1 1 0; -} - -// Stack the two cards full-width on narrow viewports. -@media (max-width: 768px) { - .data-card-columns { - flex-direction: column; - align-items: stretch; - } -} - -// Matches the app's standard card-section heading convention (e.g. the -// Settings tab's "General" card title): bold, dark, slightly larger than -// body text, with a clear gap before the content below. -.data-card-heading { - font-size: 18px; - font-weight: 600; - color: rgba(0, 0, 0, 0.85); - margin: 0 0 20px; -} - -// Plain text, no box/border styling — larger size keeps it readable as prose. -.data-card-description { - font-size: 16px; - line-height: 1.6; - margin-bottom: 32px; -} - -// Empty state: muted grey italic so it reads as "nothing here yet", not broken. -.empty-description { - color: rgba(0, 0, 0, 0.4); - font-style: italic; + @include detail.scrollable-tab; } -// Stats as a full-width vertical list, one fact per row, avoiding the awkward -// wrapping of the previous cramped horizontal layout. -.data-card-stats { - display: flex; - flex-direction: column; -} - -.stat-row { - display: flex; - justify-content: space-between; - align-items: baseline; - gap: 16px; - padding: 12px 0; - border-bottom: 1px solid #f0f0f0; - - &:last-child { - border-bottom: none; - } -} - -.stat-label { - font-size: 13px; - font-weight: 600; - color: rgba(0, 0, 0, 0.85); - flex-shrink: 0; -} - -.stat-value { - font-weight: 400; - color: rgba(0, 0, 0, 0.45); - text-align: right; - word-break: break-word; -} - -.settings-general-card { - max-width: 700px; - margin: 24px auto 0; - border-radius: 16px; - border: 1px solid #d9d9d9; - - .settings-card-title { - font-weight: 600; - margin-bottom: 20px; - } - - .settings-field-label { - display: block; - font-weight: 600; - } - - .settings-field-hint { - color: rgba(0, 0, 0, 0.45); - font-size: 12px; - margin-bottom: 8px; - } - - .settings-name-row { - display: flex; - justify-content: space-between; - align-items: center; - gap: 16px; - - .settings-name-label label { - font-weight: 600; - } - - .settings-hint { - color: rgba(0, 0, 0, 0.45); - font-size: 12px; - margin: 4px 0 0; - } - - .settings-name-controls { - display: flex; - gap: 8px; - flex-shrink: 0; - - input { - border-radius: 8px; - } - - button { - border-radius: 8px; - } - } - } -} +@include detail.data-card; ::ng-deep .settings-general-card button { border-radius: 8px; diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/dataset-detail.component.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/dataset-detail.component.ts index f9d8f70c16..7ffdbe0f6a 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/dataset-detail.component.ts +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/dataset-detail.component.ts @@ -54,16 +54,13 @@ import { NzIconDirective } from "ng-zorro-antd/icon"; import { NzSpaceCompactItemDirective } from "ng-zorro-antd/space"; import { NzButtonComponent } from "ng-zorro-antd/button"; import { NzPopconfirmDirective } from "ng-zorro-antd/popconfirm"; -import { NzSwitchComponent } from "ng-zorro-antd/switch"; -import { FormsModule } from "@angular/forms"; import { MarkdownDescriptionComponent } from "../../markdown-description/markdown-description.component"; -import { NzWaveDirective } from "ng-zorro-antd/core/wave"; import { NzTabsComponent, NzTabComponent } from "ng-zorro-antd/tabs"; import { NzCollapseComponent, NzCollapsePanelComponent } from "ng-zorro-antd/collapse"; import { NzDividerComponent } from "ng-zorro-antd/divider"; import { DATASET_FILE_RESOURCE_ENDPOINT } from "../../../../service/user/file-resource/file-resource-endpoint"; -import { NzInputDirective } from "ng-zorro-antd/input"; import { VersionsFilesBrowserComponent } from "../../versions-files-browser/versions-files-browser.component"; +import { ResourceDetailSettingsComponent } from "../../resource-detail-settings.component"; export const THROTTLE_TIME_MS = 1000; @@ -83,22 +80,19 @@ export const THROTTLE_TIME_MS = 1000; NzSpaceCompactItemDirective, NzButtonComponent, NzPopconfirmDirective, - NzSwitchComponent, - FormsModule, MarkdownDescriptionComponent, - NzWaveDirective, NzTabsComponent, NzTabComponent, NzCollapseComponent, NzCollapsePanelComponent, NzDividerComponent, NgFor, - NzInputDirective, NzDropdownDirective, NzDropdownMenuComponent, NzMenuDirective, NzMenuItemComponent, VersionsFilesBrowserComponent, + ResourceDetailSettingsComponent, ], }) export class DatasetDetailComponent implements OnInit { @@ -459,8 +453,15 @@ export class DatasetDetailComponent implements OnInit { } } - // alias for formatSize - formatSize = formatSize; + protected get overviewStatistics() { + return [ + { label: "Created", value: this.datasetCreationTime }, + { label: "Last updated", value: this.latestVersionCreationTime || "—" }, + { label: "Versions", value: this.versions.length }, + { label: "Latest version file", value: this.latestVersionFileName || "—" }, + { label: "Latest version size", value: formatSize(this.latestVersionSize) }, + ]; + } formatCount = formatCount; diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-contributor-editor/contributor-form-fields.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-contributor-editor/contributor-form-fields.ts index 106236daa9..c3c5d9f11d 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-contributor-editor/contributor-form-fields.ts +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-contributor-editor/contributor-form-fields.ts @@ -20,21 +20,20 @@ import { Validators } from "@angular/forms"; import { FormlyFieldConfig } from "@ngx-formly/core"; +function contributorInput(key: string, options: FormlyFieldConfig["templateOptions"]): FormlyFieldConfig { + return { + key, + type: "input", + defaultValue: "", + templateOptions: { ...options, maxLength: 256 }, + }; +} + // Formly attaches per-form runtime state to field-config objects, so every // consumer must get a fresh copy instead of sharing one array. export function contributorFieldGroup(): FormlyFieldConfig[] { return [ - { - key: "name", - type: "input", - defaultValue: "", - templateOptions: { - label: "Name", - required: true, - placeholder: "Enter name", - maxLength: 256, - }, - }, + contributorInput("name", { label: "Name", required: true, placeholder: "Enter name" }), { key: "creator", type: "checkbox", @@ -44,15 +43,7 @@ export function contributorFieldGroup(): FormlyFieldConfig[] { }, }, { - key: "email", - type: "input", - defaultValue: "", - templateOptions: { - label: "Email", - type: "email", - placeholder: "Enter email", - maxLength: 256, - }, + ...contributorInput("email", { label: "Email", type: "email", placeholder: "Enter email" }), validators: { validation: [Validators.email], }, @@ -62,16 +53,7 @@ export function contributorFieldGroup(): FormlyFieldConfig[] { }, }, }, - { - key: "affiliation", - type: "input", - defaultValue: "", - templateOptions: { - label: "Affiliation", - placeholder: "Enter affiliation", - maxLength: 256, - }, - }, + contributorInput("affiliation", { label: "Affiliation", placeholder: "Enter affiliation" }), { key: "comments", type: "textarea", diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-contributor-editor/user-dataset-contributor-editor.component.spec.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-contributor-editor/user-dataset-contributor-editor.component.spec.ts index d66712cdf0..e58fdd7011 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-contributor-editor/user-dataset-contributor-editor.component.spec.ts +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-contributor-editor/user-dataset-contributor-editor.component.spec.ts @@ -17,51 +17,31 @@ * under the License. */ -import { Component } from "@angular/core"; -import { ComponentFixture, TestBed } from "@angular/core/testing"; -import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; -import { ReactiveFormsModule } from "@angular/forms"; -import { FieldType, FieldTypeConfig, FormlyModule } from "@ngx-formly/core"; -import { NZ_MODAL_DATA, NzModalRef } from "ng-zorro-antd/modal"; +import { NZ_MODAL_DATA } from "ng-zorro-antd/modal"; import { UserDatasetContributorEditorComponent } from "./user-dataset-contributor-editor.component"; import { Contributor } from "../../../../../../common/type/dataset"; -import { commonTestProviders } from "../../../../../../common/testing/test-utils"; - -@Component({ template: "", standalone: true }) -class StubFormlyFieldComponent extends FieldType<FieldTypeConfig> {} +import { createFormlyModalFixture } from "../../../formly-modal-test-fixture"; describe("UserDatasetContributorEditorComponent", () => { let modalClose: ReturnType<typeof vi.fn>; - async function createFixture( - modalData: Contributor | null - ): Promise<ComponentFixture<UserDatasetContributorEditorComponent>> { + async function render(modalData: Contributor | null): Promise<UserDatasetContributorEditorComponent> { modalClose = vi.fn(); - await TestBed.configureTestingModule({ - imports: [ - UserDatasetContributorEditorComponent, - BrowserAnimationsModule, - ReactiveFormsModule, - FormlyModule.forRoot({ - types: ["input", "checkbox", "textarea"].map(name => ({ name, component: StubFormlyFieldComponent })), - }), - ], - providers: [ - { provide: NZ_MODAL_DATA, useValue: modalData }, - { provide: NzModalRef, useValue: { close: modalClose } }, - ...commonTestProviders, - ], - }).compileComponents(); - - return TestBed.createComponent(UserDatasetContributorEditorComponent); + const fixture = await createFormlyModalFixture( + UserDatasetContributorEditorComponent, + ["input", "checkbox", "textarea"], + modalClose, + { providers: [{ provide: NZ_MODAL_DATA, useValue: modalData }] } + ); + fixture.detectChanges(); + return fixture.componentInstance; } it("starts with an empty model when adding a new contributor", async () => { - const fixture = await createFixture(null); - fixture.detectChanges(); + const component = await render(null); - expect(fixture.componentInstance.model).toEqual({ + expect(component.model).toEqual({ name: "", creator: false, email: "", @@ -78,16 +58,13 @@ describe("UserDatasetContributorEditorComponent", () => { email: "[email protected]", comments: "collected the data", }; - const fixture = await createFixture(contributor); - fixture.detectChanges(); + const component = await render(contributor); - expect(fixture.componentInstance.model).toEqual(contributor); + expect(component.model).toEqual(contributor); }); it("submit closes the modal with a copy of the model when the form is valid", async () => { - const fixture = await createFixture(null); - fixture.detectChanges(); - const component = fixture.componentInstance; + const component = await render(null); component.contributorForm.get("name")?.setValue("Bob"); component.submit(); @@ -97,9 +74,7 @@ describe("UserDatasetContributorEditorComponent", () => { }); it("submit does nothing when the email is invalid", async () => { - const fixture = await createFixture(null); - fixture.detectChanges(); - const component = fixture.componentInstance; + const component = await render(null); component.contributorForm.get("name")?.setValue("Contributor A"); component.contributorForm.get("email")?.setValue("not-an-email"); @@ -114,19 +89,17 @@ describe("UserDatasetContributorEditorComponent", () => { }); it("submit does nothing when the required name is empty (invalid form)", async () => { - const fixture = await createFixture(null); - fixture.detectChanges(); + const component = await render(null); - fixture.componentInstance.submit(); + component.submit(); expect(modalClose).not.toHaveBeenCalled(); }); it("cancel closes the modal without a value", async () => { - const fixture = await createFixture(null); - fixture.detectChanges(); + const component = await render(null); - fixture.componentInstance.cancel(); + component.cancel(); expect(modalClose).toHaveBeenCalledWith(); }); 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 ae5429b244..bdb87cd8f3 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 @@ -23,20 +23,17 @@ // These tests run in vitest's Playwright/Chromium browser mode to pin the // behaviors that need real geometry. -import { ComponentFixture, TestBed } from "@angular/core/testing"; +import { ComponentFixture } from "@angular/core/testing"; import { UserDatasetVersionFiletreeComponent } from "./user-dataset-version-filetree.component"; import { DatasetFileNode } from "../../../../../../common/type/datasetVersionFileTree"; -import { FILE_COUNT, makeFlatFileNodes } from "./user-dataset-version-filetree.test-utils"; +import { createFiletreeFixture, FILE_COUNT, makeFlatFileNodes } from "./user-dataset-version-filetree.test-utils"; describe("UserDatasetVersionFiletreeComponent (browser)", () => { let fixture: ComponentFixture<UserDatasetVersionFiletreeComponent>; let component: UserDatasetVersionFiletreeComponent; beforeEach(() => { - TestBed.configureTestingModule({ - imports: [UserDatasetVersionFiletreeComponent], - }); - fixture = TestBed.createComponent(UserDatasetVersionFiletreeComponent); + fixture = createFiletreeFixture(); component = fixture.componentInstance; }); diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.html b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.html index d564c5edbd..1dca4f311d 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.html +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.component.html @@ -31,14 +31,8 @@ let-node> <span title="{{ node.data.name }}"> <i - *ngIf="node.data.children" nz-icon - nzType="folder" - nzTheme="outline"></i> - <i - *ngIf="!node.data.children" - nz-icon - nzType="file" + [nzType]="node.data.children ? 'folder' : 'file'" nzTheme="outline"></i> {{ node.data.name }} <button 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 38c2397353..ce9fe30cf5 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 @@ -17,29 +17,29 @@ * under the License. */ -import { ComponentFixture, TestBed } from "@angular/core/testing"; +import { ComponentFixture } from "@angular/core/testing"; import { UserDatasetVersionFiletreeComponent } from "./user-dataset-version-filetree.component"; import { DatasetFileNode } from "../../../../../../common/type/datasetVersionFileTree"; -import { FILE_COUNT, makeFlatFileNodes } from "./user-dataset-version-filetree.test-utils"; +import { createFiletreeFixture, FILE_COUNT, makeFlatFileNodes } from "./user-dataset-version-filetree.test-utils"; describe("UserDatasetVersionFiletreeComponent", () => { let fixture: ComponentFixture<UserDatasetVersionFiletreeComponent>; let component: UserDatasetVersionFiletreeComponent; - function makeFolderNode(fileCount: number): DatasetFileNode { - return { - name: "dir", - type: "directory", - parentDir: "/owner/dataset/v1", - children: makeFlatFileNodes(fileCount), - }; + const folderWith = (children: DatasetFileNode[]): DatasetFileNode => ({ + name: "dir", + type: "directory", + parentDir: "/owner/dataset/v1", + children, + }); + + function expectContainerHeight(height: string): void { + const container = fixture.nativeElement.querySelector(".file-tree-container") as HTMLElement; + expect(container.style.height).toBe(height); } beforeEach(() => { - TestBed.configureTestingModule({ - imports: [UserDatasetVersionFiletreeComponent], - }); - fixture = TestBed.createComponent(UserDatasetVersionFiletreeComponent); + fixture = createFiletreeFixture(); component = fixture.componentInstance; }); @@ -69,32 +69,28 @@ describe("UserDatasetVersionFiletreeComponent", () => { component.fileTreeNodes = []; fixture.detectChanges(); - const container = fixture.nativeElement.querySelector(".file-tree-container") as HTMLElement; - expect(container.style.height).toBe("0px"); + expectContainerHeight("0px"); }); it("sizes the container to its content for small trees", () => { component.fileTreeNodes = makeFlatFileNodes(3); fixture.detectChanges(); - const container = fixture.nativeElement.querySelector(".file-tree-container") as HTMLElement; - expect(container.style.height).toBe("80px"); // 3 rows x 26px pitch + 2px leading drop slot + expectContainerHeight("80px"); // 3 rows x 26px pitch + 2px leading drop slot }); it("caps the container height at 200px for large trees", () => { component.fileTreeNodes = makeFlatFileNodes(FILE_COUNT); fixture.detectChanges(); - const container = fixture.nativeElement.querySelector(".file-tree-container") as HTMLElement; - expect(container.style.height).toBe("200px"); + expectContainerHeight("200px"); }); it("counts nested folder contents when sizing the container", () => { - component.fileTreeNodes = [makeFolderNode(2)]; // 1 folder + 2 files = 3 rows when expanded + component.fileTreeNodes = [folderWith(makeFlatFileNodes(2))]; // 1 folder + 2 files = 3 rows when expanded fixture.detectChanges(); - const container = fixture.nativeElement.querySelector(".file-tree-container") as HTMLElement; - expect(container.style.height).toBe("80px"); + expectContainerHeight("80px"); }); it("treats a missing files input as an empty tree", () => { @@ -102,13 +98,12 @@ describe("UserDatasetVersionFiletreeComponent", () => { fixture.detectChanges(); expect(component.fileTreeNodes).toEqual([]); - const container = fixture.nativeElement.querySelector(".file-tree-container") as HTMLElement; - expect(container.style.height).toBe("0px"); + expectContainerHeight("0px"); }); it("expands all folders after view init when isExpandAllAfterViewInit is set", () => { component.isExpandAllAfterViewInit = true; - component.fileTreeNodes = [makeFolderNode(2)]; + component.fileTreeNodes = [folderWith(makeFlatFileNodes(2))]; fixture.detectChanges(); expect(component.tree.treeModel.roots[0].isExpanded).toBe(true); @@ -173,13 +168,6 @@ describe("UserDatasetVersionFiletreeComponent", () => { * changes how many rows the tree draws but not what a row contains. */ describe("node template", () => { - const folderWith = (children: DatasetFileNode[]): DatasetFileNode => ({ - name: "dir", - type: "directory", - parentDir: "/owner/dataset/v1", - children, - }); - const file = (name: string): DatasetFileNode => ({ name, type: "file", @@ -211,10 +199,10 @@ describe("UserDatasetVersionFiletreeComponent", () => { expect(rowTitles()).toEqual(["dir", "a.csv"]); expect(rowFor("dir").textContent?.trim()).toBe("dir"); - expect(rowFor("dir").querySelector("i[nztype='folder']")).not.toBeNull(); - expect(rowFor("dir").querySelector("i[nztype='file']")).toBeNull(); - expect(rowFor("a.csv").querySelector("i[nztype='file']")).not.toBeNull(); - expect(rowFor("a.csv").querySelector("i[nztype='folder']")).toBeNull(); + expect(rowFor("dir").querySelector("i[aria-label='folder']")).not.toBeNull(); + expect(rowFor("dir").querySelector("i[aria-label='file']")).toBeNull(); + expect(rowFor("a.csv").querySelector("i[aria-label='file']")).not.toBeNull(); + expect(rowFor("a.csv").querySelector("i[aria-label='folder']")).toBeNull(); }); it("offers deletion on files only, and never on the folders holding them", () => { diff --git a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.test-utils.ts b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.test-utils.ts index 97e8b2bd17..56c68966af 100644 --- a/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.test-utils.ts +++ b/frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-version-filetree/user-dataset-version-filetree.test-utils.ts @@ -22,6 +22,8 @@ * two cannot drift. */ +import { ComponentFixture, TestBed } from "@angular/core/testing"; +import { UserDatasetVersionFiletreeComponent } from "./user-dataset-version-filetree.component"; import { DatasetFileNode } from "../../../../../../common/type/datasetVersionFileTree"; export const FILE_COUNT = 1000; @@ -34,3 +36,9 @@ export function makeFlatFileNodes(count: number): DatasetFileNode[] { size: 1, })); } + +/** Configures TestBed for `UserDatasetVersionFiletreeComponent` and returns a fresh fixture. */ +export function createFiletreeFixture(): ComponentFixture<UserDatasetVersionFiletreeComponent> { + TestBed.configureTestingModule({ imports: [UserDatasetVersionFiletreeComponent] }); + return TestBed.createComponent(UserDatasetVersionFiletreeComponent); +} 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 9b795940f3..b2708efd9b 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 @@ -17,22 +17,14 @@ * under the License. */ -import { Component } from "@angular/core"; -import { ComponentFixture, TestBed } from "@angular/core/testing"; -import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; -import { FormsModule, ReactiveFormsModule } from "@angular/forms"; -import { FieldType, FieldTypeConfig, FormlyModule } from "@ngx-formly/core"; +import { FormsModule } from "@angular/forms"; import { HttpClientTestingModule } from "@angular/common/http/testing"; -import { NzModalRef } from "ng-zorro-antd/modal"; import { of, throwError } from "rxjs"; import { sanitizeModelName, UserModelCreatorComponent } from "./user-model-creator.component"; import { MODEL_FORMATS, MODEL_FRAMEWORKS, ModelService } from "../../../../service/user/model/model.service"; import { NotificationService } from "../../../../../common/service/notification/notification.service"; -import { commonTestProviders } from "../../../../../common/testing/test-utils"; - -@Component({ template: "", standalone: true }) -class StubFormlyFieldComponent extends FieldType<FieldTypeConfig> {} +import { createFormlyModalFixture } from "../../formly-modal-test-fixture"; describe("sanitizeModelName", () => { it("keeps underscores and hyphens, unlike the dataset sanitizer", () => { @@ -55,52 +47,36 @@ describe("UserModelCreatorComponent", () => { let notifySuccess: ReturnType<typeof vi.fn>; let notifyError: ReturnType<typeof vi.fn>; - async function createFixture(): Promise<ComponentFixture<UserModelCreatorComponent>> { + async function render(): Promise<UserModelCreatorComponent> { modalClose = vi.fn(); createModel = vi.fn(); notifySuccess = vi.fn(); notifyError = vi.fn(); - await TestBed.configureTestingModule({ - imports: [ - UserModelCreatorComponent, - BrowserAnimationsModule, - FormsModule, - ReactiveFormsModule, - FormlyModule.forRoot({ - types: [ - { name: "input", component: StubFormlyFieldComponent }, - { name: "select", component: StubFormlyFieldComponent }, - ], - }), - HttpClientTestingModule, - ], + const fixture = await createFormlyModalFixture(UserModelCreatorComponent, ["input", "select"], modalClose, { + imports: [FormsModule, HttpClientTestingModule], providers: [ - { provide: NzModalRef, useValue: { close: modalClose } }, { provide: ModelService, useValue: { createModel } }, { provide: NotificationService, useValue: { success: notifySuccess, error: notifyError } }, - ...commonTestProviders, ], - }).compileComponents(); - - return TestBed.createComponent(UserModelCreatorComponent); + }); + fixture.detectChanges(); + return fixture.componentInstance; } it("renders the four create fields", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); + const component = await render(); - expect(fixture.componentInstance.fields.map(f => f.key)).toEqual(["name", "description", "framework", "format"]); - expect(fixture.componentInstance.form.contains("name")).toBe(true); + expect(component.fields.map(f => f.key)).toEqual(["name", "description", "framework", "format"]); + expect(component.form.contains("name")).toBe(true); }); it("offers exactly the framework and format values the backend accepts", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); + const component = await render(); const optionsFor = (key: string) => - ( - fixture.componentInstance.fields.find(f => f.key === key)?.templateOptions?.options as Array<{ value: string }> - ).map(o => o.value); + (component.fields.find(f => f.key === key)?.templateOptions?.options as Array<{ value: string }>).map( + o => o.value + ); // A drift here becomes a 400 from ModelResource's whitelist at create time. expect(optionsFor("framework")).toEqual([...MODEL_FRAMEWORKS]); @@ -108,19 +84,16 @@ describe("UserModelCreatorComponent", () => { }); it("does nothing when the required name is empty", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); + const component = await render(); - fixture.componentInstance.onClickCreate(); + component.onClickCreate(); expect(createModel).not.toHaveBeenCalled(); expect(modalClose).not.toHaveBeenCalled(); }); it("creates the model with the sanitized name and the toggle values", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); - const component = fixture.componentInstance; + const component = await render(); createModel.mockReturnValue(of({ model: { mid: 9 } })); component.form.get("name")?.setValue("churn_predictor"); @@ -147,9 +120,7 @@ describe("UserModelCreatorComponent", () => { }); it("reports the rename when the entered name had to be sanitized", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); - const component = fixture.componentInstance; + const component = await render(); createModel.mockReturnValue(of({ model: { mid: 3 } })); component.form.get("name")?.setValue("My Model"); @@ -164,9 +135,7 @@ describe("UserModelCreatorComponent", () => { it("refuses a name that sanitizes to nothing, without calling the backend", async () => { // Whitespace survives `required` but sanitizes to "", which the backend answers with a 400. // Punctuation does not belong here: "!!" sanitizes to "-", which is a legal name. - const fixture = await createFixture(); - fixture.detectChanges(); - const component = fixture.componentInstance; + const component = await render(); for (const typed of [" ", "\t\n "]) { notifyError.mockClear(); @@ -180,9 +149,7 @@ describe("UserModelCreatorComponent", () => { }); it("refuses a name past the length limit, without calling the backend", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); - const component = fixture.componentInstance; + const component = await render(); component.form.get("name")?.setValue("a".repeat(129)); component.onClickCreate(); @@ -192,9 +159,7 @@ describe("UserModelCreatorComponent", () => { }); it("surfaces the server message and keeps the modal open when creation fails", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); - const component = fixture.componentInstance; + const component = await render(); createModel.mockReturnValue(throwError(() => ({ error: { message: "name already taken" } }))); component.form.get("name")?.setValue("dupe"); @@ -207,10 +172,9 @@ describe("UserModelCreatorComponent", () => { }); it("closes with null on cancel without calling the backend", async () => { - const fixture = await createFixture(); - fixture.detectChanges(); + const component = await render(); - fixture.componentInstance.onClickCancel(); + component.onClickCancel(); expect(modalClose).toHaveBeenCalledWith(null); expect(createModel).not.toHaveBeenCalled(); diff --git a/frontend/src/app/dashboard/component/user/user-model/user-model-creator/user-model-creator.component.ts b/frontend/src/app/dashboard/component/user/user-model/user-model-creator/user-model-creator.component.ts index 06e76c109c..e25501acc4 100644 --- a/frontend/src/app/dashboard/component/user/user-model/user-model-creator/user-model-creator.component.ts +++ b/frontend/src/app/dashboard/component/user/user-model/user-model-creator/user-model-creator.component.ts @@ -32,7 +32,10 @@ import { } from "../../../../service/user/model/model.service"; import { Model } from "../../../../../common/type/model"; import { NotificationService } from "../../../../../common/service/notification/notification.service"; -import { ResourceCreatorFormComponent } from "../../resource-creator-form/resource-creator-form.component"; +import { + ResourceCreatorFormComponent, + resourceNameAndDescriptionFields, +} from "../../resource-creator-form/resource-creator-form.component"; export function sanitizeModelName(name: string): string { return name @@ -70,43 +73,17 @@ export class UserModelCreatorComponent implements OnInit { private setFormFields() { this.fields = [ - { - key: "name", - type: "input", - templateOptions: { - label: "Name", - required: true, - }, - }, - { - key: "description", - type: "input", - defaultValue: "", - templateOptions: { - label: "Description", - }, - }, + ...resourceNameAndDescriptionFields(), // Options mirror ModelResource's whitelists, which reject anything else with a 400. - { - key: "framework", + ...[ + { key: "framework", label: "Framework", values: MODEL_FRAMEWORKS }, + { key: "format", label: "Format", values: MODEL_FORMATS }, + ].map(({ key, label, values }) => ({ + key, type: "select", - defaultValue: MODEL_FRAMEWORKS[0], - templateOptions: { - label: "Framework", - required: true, - options: MODEL_FRAMEWORKS.map(value => ({ label: value, value })), - }, - }, - { - key: "format", - type: "select", - defaultValue: MODEL_FORMATS[0], - templateOptions: { - label: "Format", - required: true, - options: MODEL_FORMATS.map(value => ({ label: value, value })), - }, - }, + defaultValue: values[0], + templateOptions: { label, required: true, options: values.map(value => ({ label: value, value })) }, + })), ]; } diff --git a/frontend/src/app/dashboard/component/user/user-model/user-model-explorer/model-detail.component.html b/frontend/src/app/dashboard/component/user/user-model/user-model-explorer/model-detail.component.html index cd40389898..c30e34eb5f 100644 --- a/frontend/src/app/dashboard/component/user/user-model/user-model-explorer/model-detail.component.html +++ b/frontend/src/app/dashboard/component/user/user-model/user-model-explorer/model-detail.component.html @@ -125,34 +125,12 @@ <nz-card class="data-card data-card-details"> <div class="data-card-stats"> + @for (stat of overviewStatistics; track stat.label) { <div class="stat-row"> - <span class="stat-label">Created</span> - <span class="stat-value">{{ modelCreationTime }}</span> - </div> - <div class="stat-row"> - <span class="stat-label">Last updated</span> - <span class="stat-value">{{ latestVersionCreationTime || "—" }}</span> - </div> - <div class="stat-row"> - <span class="stat-label">Versions</span> - <span class="stat-value">{{ versions.length }}</span> - </div> - <div class="stat-row"> - <span class="stat-label">Framework</span> - <span class="stat-value">{{ modelFramework || "—" }}</span> - </div> - <div class="stat-row"> - <span class="stat-label">Format</span> - <span class="stat-value">{{ modelFormat || "—" }}</span> - </div> - <div class="stat-row"> - <span class="stat-label">Latest version file</span> - <span class="stat-value">{{ latestVersionFileName || "—" }}</span> - </div> - <div class="stat-row"> - <span class="stat-label">Latest version size</span> - <span class="stat-value">{{ formatSize(latestVersionSize) }}</span> + <span class="stat-label">{{ stat.label }}</span> + <span class="stat-value">{{ stat.value }}</span> </div> + } </div> </nz-card> </div> @@ -194,51 +172,23 @@ <nz-tab nzTitle="Settings" *ngIf="userHasWriteAccess()"> - <div class="settings-tab-content"> - <nz-card class="settings-general-card"> - <h3 class="settings-card-title">General</h3> - - <div class="settings-name-row"> - <div class="settings-name-label"> - <label>Model name</label> - <p class="settings-hint">Letters, numbers, underscores and hyphens.</p> - <p - *ngIf="uploadsInFlight" - class="settings-hint"> - An upload is in progress — finish or cancel it in Versions & Files first, or it will be left - incomplete. - </p> - </div> - <div class="settings-name-controls"> - <input - nz-input - [disabled]="uploadsInFlight" - [(ngModel)]="editedModelName" /> - <button - nz-button - nzType="primary" - [disabled]="uploadsInFlight" - (click)="onSaveModelName()"> - Save - </button> - </div> - </div> - - <nz-divider></nz-divider> - - <div class="settings-field"> - <label class="settings-field-label">Description</label> - <div class="settings-field-hint">Shown on cards.</div> - <texera-markdown-description - [description]="modelDescription" - [editable]="true" - [enableViewMore]="true" - (descriptionChange)="onModelDescriptionChange($event)"> - </texera-markdown-description> - </div> - </nz-card> - - <nz-card class="settings-general-card"> + <div + class="settings-tab-content" + texeraResourceDetailSettings + resourceType="model" + [(editedName)]="editedModelName" + [uploadsInFlight]="uploadsInFlight" + (saveName)="onSaveModelName()" + [description]="modelDescription" + (descriptionChange)="onModelDescriptionChange($event)" + [isPublic]="modelIsPublic" + (publicChange)="onPublicStatusChange($event)" + [isDownloadable]="modelIsDownloadable" + (downloadableChange)="onDownloadableStatusChange($event)" + [isOwner]="isOwner"> + <nz-card + class="settings-general-card" + ngProjectAs="[resourceSettingsBetweenCards]"> <h3 class="settings-card-title">Model type</h3> <div class="settings-name-row"> @@ -281,47 +231,6 @@ </div> </div> </nz-card> - - <nz-card class="settings-general-card"> - <h3 class="settings-card-title">Access & visibility</h3> - - <div class="settings-name-row"> - <div class="settings-name-label"> - <label>Visibility</label> - <p class="settings-hint"> - {{ modelIsPublic ? "Public — anyone can view this model." : "Private — only you and invited collaborators - can see this model." }} - </p> - </div> - <div class="settings-name-controls"> - <nz-switch - [ngModel]="modelIsPublic" - (ngModelChange)="onPublicStatusChange($event)" - nzCheckedChildren="public" - nzUnCheckedChildren="private"></nz-switch> - </div> - </div> - - <nz-divider></nz-divider> - - <div class="settings-name-row"> - <div class="settings-name-label"> - <label>Downloadable</label> - <p class="settings-hint"> - {{ modelIsDownloadable ? "Viewers can download this model." : "Viewers can browse files but cannot - download them." }} - </p> - </div> - <div class="settings-name-controls"> - <nz-switch - [ngModel]="modelIsDownloadable" - (ngModelChange)="onDownloadableStatusChange($event)" - [nzDisabled]="!isOwner" - nzCheckedChildren="allowed" - nzUnCheckedChildren="blocked"></nz-switch> - </div> - </div> - </nz-card> </div> </nz-tab> </nz-tabs> diff --git a/frontend/src/app/dashboard/component/user/user-model/user-model-explorer/model-detail.component.scss b/frontend/src/app/dashboard/component/user/user-model/user-model-explorer/model-detail.component.scss index 8adfac83c3..26cd9c88f4 100644 --- a/frontend/src/app/dashboard/component/user/user-model/user-model-explorer/model-detail.component.scss +++ b/frontend/src/app/dashboard/component/user/user-model/user-model-explorer/model-detail.component.scss @@ -17,148 +17,21 @@ * under the License. */ -// Mirrors dataset-detail.component.scss; the two detail pages are the same layout. - -.version-storage { - padding: 0 15px; - margin-bottom: 25px; -} +@use "../../resource-detail-shared" as detail; -.version-storage nz-select { - width: 100%; - margin: 0; -} +// Mirrors dataset-detail.component.scss; the two detail pages are the same layout. nz-layout { height: 100%; } -.right-sider { - height: 100%; - overflow-y: auto; - position: relative; - z-index: 0; -} - -.sider-resize-line { - display: flex; - align-items: center; - justify-content: center; - height: 100%; - width: 5px; - border-right: 1px solid #e8e8e8; -} - -.sider-resize-handle { - background: #fff; - border: 1px solid #ddd; - text-align: center; - font-size: 12px; - height: 20px; - line-height: 20px; -} - -.file-renderer { - width: 95%; - height: 80%; - margin: auto; -} - -.select-and-button-container { - display: flex; - align-items: stretch; - gap: 10px; -} - -.spaced-button { - flex-shrink: 0; - width: 30px; - height: 24px; -} - nz-select { flex-grow: 1; } -.file-size, -.version-size, -.version-date { - font-size: 12px; - color: #8c8c8c; - display: inline-flex; - align-items: center; - gap: 4px; -} - -.version-date { - display: flex; -} - -.version-size { - margin-top: 8px; -} - -.icon-database, -.icon-file { - font-size: 14px; -} - -.empty-version-indicator { - margin-top: 15%; -} - -.status-tag-row { - margin-top: 16px; - display: flex; - align-items: center; - gap: 5px; -} - -.like-tag { - cursor: pointer; -} +@include detail.like-states; -.like-tag.liked { - i { - color: #ef4444; - background: #fef2f2; - } -} - -.like-tag.disabled { - cursor: not-allowed; - opacity: 0.55; -} - -.status-tag { - padding: 3px 10px 3px 3px; - font-size: 13px; - display: inline-flex; - align-items: center; - gap: 5px; - background: #fff; - border-radius: 5px; - - i { - width: 22px; - height: 22px; - display: inline-flex; - align-items: center; - justify-content: center; - border-radius: 4px; - background: #f0f0f0; - } -} - -.tag-public i { - color: #3b82f6; - background: #eff6ff; -} - -.tag-downloadable i { - color: #22c55e; - background: #f0fdf4; -} +@include detail.status-tags; .tag-framework i { color: #a855f7; @@ -170,204 +43,21 @@ nz-select { background: #fffbeb; } -.file-title { - display: flex; - align-items: center; - flex-wrap: wrap; - gap: 8px; - margin-bottom: 0; -} +@include detail.header("model"); -.file-title-main { - display: inline-flex; - align-items: center; - gap: 6px; - min-width: 0; -} - -.copy-path-btn { - padding: 0 4px; - height: auto; - line-height: 1; - display: inline-flex; - align-items: center; - justify-content: center; -} - -.model-header { - display: flex; - gap: 24px; -} - -.model-header-meta { - flex: 1; -} - -.model-cover-image { - width: 280px; - height: 120px; - object-fit: cover; - border-radius: 8px; - margin-right: 80px; -} - -nz-tabs { - margin-top: 6px; -} - -::ng-deep .ant-tabs-nav { - padding-left: 16px; -} +@include detail.tab-bar; .data-card-tab-content, .versions-tab-content { - height: 100%; - overflow-y: auto; - padding-bottom: 24px; + @include detail.scrollable-tab; } -// A wide description card beside a narrower stats card. The grow ratio with -// basis 0 is the only thing setting their proportions. -.data-card-columns { - display: flex; - align-items: flex-start; - gap: 20px; - margin-top: 24px; - width: 100%; - // Match the tab bar's left inset so the cards line up with the tab labels. - padding-left: 16px; -} - -.data-card { - border-radius: 8px; - border: 1px solid #d9d9d9; - // Without this the default min-width:auto keeps the cards from shrinking to - // their flex share, skewing the ratio. - min-width: 0; -} - -.data-card-main { - flex: 3 1 0; -} - -.data-card-details { - flex: 1 1 0; -} - -@media (max-width: 768px) { - .data-card-columns { - flex-direction: column; - align-items: stretch; - } -} - -.data-card-heading { - font-size: 18px; - font-weight: 600; - color: rgba(0, 0, 0, 0.85); - margin: 0 0 20px; -} - -.data-card-description { - font-size: 16px; - line-height: 1.6; - margin-bottom: 32px; -} - -.empty-description { - color: rgba(0, 0, 0, 0.4); - font-style: italic; -} - -.data-card-stats { - display: flex; - flex-direction: column; -} - -.stat-row { - display: flex; - justify-content: space-between; - align-items: baseline; - gap: 16px; - padding: 12px 0; - border-bottom: 1px solid #f0f0f0; - - &:last-child { - border-bottom: none; - } -} - -.stat-label { - font-size: 13px; - font-weight: 600; - color: rgba(0, 0, 0, 0.85); - flex-shrink: 0; -} - -.stat-value { - font-weight: 400; - color: rgba(0, 0, 0, 0.45); - text-align: right; - word-break: break-word; -} +@include detail.data-card; .settings-tab-content { - height: 100%; - overflow-y: auto; - padding-bottom: 24px; + @include detail.scrollable-tab; } -.settings-general-card { - max-width: 700px; - margin: 24px auto 0; - border-radius: 16px; - border: 1px solid #d9d9d9; - - .settings-card-title { - font-weight: 600; - margin-bottom: 20px; - } - - .settings-field-label { - display: block; - font-weight: 600; - } - - .settings-field-hint { - color: rgba(0, 0, 0, 0.45); - font-size: 12px; - margin-bottom: 8px; - } - - .settings-name-row { - display: flex; - justify-content: space-between; - align-items: center; - gap: 16px; - - .settings-name-label label { - font-weight: 600; - } - - .settings-hint { - color: rgba(0, 0, 0, 0.45); - font-size: 12px; - margin: 4px 0 0; - } - - .settings-name-controls { - display: flex; - gap: 8px; - flex-shrink: 0; - - input, - button { - border-radius: 8px; - } - } - } - - .settings-select { - min-width: 200px; - } +.settings-general-card .settings-select { + min-width: 200px; } diff --git a/frontend/src/app/dashboard/component/user/user-model/user-model-explorer/model-detail.component.ts b/frontend/src/app/dashboard/component/user/user-model/user-model-explorer/model-detail.component.ts index 2b11761d93..510e6b7682 100644 --- a/frontend/src/app/dashboard/component/user/user-model/user-model-explorer/model-detail.component.ts +++ b/frontend/src/app/dashboard/component/user/user-model/user-model-explorer/model-detail.component.ts @@ -30,13 +30,9 @@ import { NzTooltipDirective } from "ng-zorro-antd/tooltip"; import { NzTagComponent } from "ng-zorro-antd/tag"; import { ɵNzTransitionPatchDirective } from "ng-zorro-antd/core/transition-patch"; import { NzIconDirective } from "ng-zorro-antd/icon"; -import { NzButtonComponent } from "ng-zorro-antd/button"; -import { NzWaveDirective } from "ng-zorro-antd/core/wave"; import { NzSelectComponent, NzOptionComponent } from "ng-zorro-antd/select"; import { NzTabsComponent, NzTabComponent } from "ng-zorro-antd/tabs"; import { NzDividerComponent } from "ng-zorro-antd/divider"; -import { NzInputDirective } from "ng-zorro-antd/input"; -import { NzSwitchComponent } from "ng-zorro-antd/switch"; import { MODEL_FORMATS, @@ -61,6 +57,7 @@ import { } from "../../../../../common/type/datasetVersionFileTree"; import { MarkdownDescriptionComponent } from "../../markdown-description/markdown-description.component"; import { VersionsFilesBrowserComponent } from "../../versions-files-browser/versions-files-browser.component"; +import { ResourceDetailSettingsComponent } from "../../resource-detail-settings.component"; @UntilDestroy() @Component({ @@ -77,17 +74,14 @@ import { VersionsFilesBrowserComponent } from "../../versions-files-browser/vers NzTagComponent, ɵNzTransitionPatchDirective, NzIconDirective, - NzButtonComponent, - NzWaveDirective, NzSelectComponent, NzOptionComponent, NzTabsComponent, NzTabComponent, NzDividerComponent, - NzInputDirective, - NzSwitchComponent, MarkdownDescriptionComponent, VersionsFilesBrowserComponent, + ResourceDetailSettingsComponent, ], }) export class ModelDetailComponent implements OnInit { @@ -145,7 +139,17 @@ export class ModelDetailComponent implements OnInit { // blocks it until the panel is idle. public uploadsInFlight = false; - formatSize = formatSize; + protected get overviewStatistics() { + return [ + { label: "Created", value: this.modelCreationTime }, + { label: "Last updated", value: this.latestVersionCreationTime || "—" }, + { label: "Versions", value: this.versions.length }, + { label: "Framework", value: this.modelFramework || "—" }, + { label: "Format", value: this.modelFormat || "—" }, + { label: "Latest version file", value: this.latestVersionFileName || "—" }, + { label: "Latest version size", value: formatSize(this.latestVersionSize) }, + ]; + } formatCount = formatCount; constructor( diff --git a/frontend/src/app/dashboard/component/user/version-uploader/version-uploader.component.spec.ts b/frontend/src/app/dashboard/component/user/version-uploader/version-uploader.component.spec.ts index 499a84034e..87b25c85de 100644 --- a/frontend/src/app/dashboard/component/user/version-uploader/version-uploader.component.spec.ts +++ b/frontend/src/app/dashboard/component/user/version-uploader/version-uploader.component.spec.ts @@ -50,6 +50,7 @@ describe("VersionUploaderComponent", () => { let uploadedPaths: string[]; let multipartUploadSpy: ReturnType<typeof vi.fn>; let createVersionSpy: ReturnType<typeof vi.fn>; + let finalize: ReturnType<typeof vi.fn>; const asCreateVersion = (spy: ReturnType<typeof vi.fn>) => spy as unknown as (name: string) => Observable<unknown>; const makeFileItem = (name: string): FileUploadItem => ({ @@ -66,6 +67,34 @@ describe("VersionUploaderComponent", () => { const finishUpload = (index: number, filePath: string, totalTime = 1) => uploadSubjects[index].next({ filePath, percentage: 100, status: "finished", totalTime }); + function stageFile(filePath: string): void { + const index = uploadSubjects.length; + dropFiles(filePath); + finishUpload(index, filePath); + } + + function mount(seed?: (c: VersionUploaderComponent) => void): void { + fixture = TestBed.createComponent(VersionUploaderComponent); + component = fixture.componentInstance; + component.resourceId = 1; + component.ownerEmail = "[email protected]"; + component.resourceName = "test-dataset"; + component.endpoint = DATASET_FILE_RESOURCE_ENDPOINT; + component.createVersion = asCreateVersion(createVersionSpy); + seed?.(component); + fixture.detectChanges(); + } + + function expectAbortRequest(path: string) { + expect(finalize).toHaveBeenCalledWith( + DATASET_FILE_RESOURCE_ENDPOINT, + "[email protected]", + "test-dataset", + path, + true + ); + } + beforeEach(() => { uploadSubjects = []; uploadedPaths = []; @@ -76,6 +105,7 @@ describe("VersionUploaderComponent", () => { return progress.asObservable(); }); createVersionSpy = vi.fn(() => of({})); + finalize = vi.fn(() => of({})); TestBed.configureTestingModule({ imports: [VersionUploaderComponent, ...commonTestImports], @@ -85,7 +115,7 @@ describe("VersionUploaderComponent", () => { provide: MultipartUploadService, useValue: { multipartUpload: multipartUploadSpy, - finalizeMultipartUpload: vi.fn(() => of({})), + finalizeMultipartUpload: finalize, listMultipartUploads: vi.fn(() => of([])), findExistingUploadFiles: vi.fn(() => of([])), }, @@ -98,14 +128,7 @@ describe("VersionUploaderComponent", () => { ], }); - fixture = TestBed.createComponent(VersionUploaderComponent); - component = fixture.componentInstance; - component.resourceId = 1; - component.ownerEmail = "[email protected]"; - component.resourceName = "test-dataset"; - component.endpoint = DATASET_FILE_RESOURCE_ENDPOINT; - component.createVersion = asCreateVersion(createVersionSpy); - fixture.detectChanges(); + mount(); }); describe("a failed upload", () => { @@ -234,11 +257,8 @@ describe("VersionUploaderComponent", () => { * and the caller's callback must fire exactly once down every one of those paths. */ describe("aborting an upload", () => { - let finalize: ReturnType<typeof vi.fn>; - beforeEach(() => { vi.useFakeTimers(); - finalize = TestBed.inject(MultipartUploadService).finalizeMultipartUpload as unknown as ReturnType<typeof vi.fn>; }); afterEach(() => { @@ -252,22 +272,20 @@ describe("VersionUploaderComponent", () => { return component.uploadTasks.find(t => t.filePath === name)!; } + function abortInFlight() { + const task = inFlight(); + const onAborted = vi.fn(); + component.onClickAbortUploadProgress(task as any, onAborted); + return onAborted; + } + const conflict = () => throwError(() => ({ status: 409 }) as any); const gone = () => throwError(() => ({ status: 404 }) as any); it("marks the task aborted and tells the caller once", () => { - const task = inFlight(); - const onAborted = vi.fn(); - - component.onClickAbortUploadProgress(task as any, onAborted); + const onAborted = abortInFlight(); - expect(finalize).toHaveBeenCalledWith( - DATASET_FILE_RESOURCE_ENDPOINT, - "[email protected]", - "test-dataset", - "a.txt", - true - ); + expectAbortRequest("a.txt"); expect(component.uploadTasks.find(t => t.filePath === "a.txt")!.status).toBe("aborted"); expect(onAborted).toHaveBeenCalledTimes(1); @@ -290,10 +308,7 @@ describe("VersionUploaderComponent", () => { it("treats a 404 as already aborted rather than an error", () => { finalize.mockReturnValueOnce(gone()); - const task = inFlight(); - const onAborted = vi.fn(); - - component.onClickAbortUploadProgress(task as any, onAborted); + const onAborted = abortInFlight(); expect(onAborted).toHaveBeenCalledTimes(1); expect(finalize).toHaveBeenCalledTimes(1); @@ -302,10 +317,7 @@ describe("VersionUploaderComponent", () => { it("retries a 409 after a backoff and finishes once the server catches up", () => { // The server is still finalizing the previous attempt; the abort has to wait it out. finalize.mockReturnValueOnce(conflict()); - const task = inFlight(); - const onAborted = vi.fn(); - - component.onClickAbortUploadProgress(task as any, onAborted); + const onAborted = abortInFlight(); expect(onAborted).not.toHaveBeenCalled(); vi.advanceTimersByTime(ABORT_RETRY_BACKOFF_BASE_MS); @@ -335,10 +347,7 @@ describe("VersionUploaderComponent", () => { it("gives up after the attempt limit but still reports the abort", () => { // Without the bound this would retry forever against a permanently conflicted server. finalize.mockReturnValue(conflict()); - const task = inFlight(); - const onAborted = vi.fn(); - - component.onClickAbortUploadProgress(task as any, onAborted); + const onAborted = abortInFlight(); vi.advanceTimersByTime(ABORT_RETRY_BACKOFF_BASE_MS * ABORT_RETRY_MAX_ATTEMPTS * (ABORT_RETRY_MAX_ATTEMPTS + 1)); expect(finalize).toHaveBeenCalledTimes(ABORT_RETRY_MAX_ATTEMPTS + 1); @@ -347,10 +356,7 @@ describe("VersionUploaderComponent", () => { it("reports the abort once even on an error the retry does not cover", () => { finalize.mockReturnValueOnce(throwError(() => ({ status: 500 }) as any)); - const task = inFlight(); - const onAborted = vi.fn(); - - component.onClickAbortUploadProgress(task as any, onAborted); + const onAborted = abortInFlight(); expect(onAborted).toHaveBeenCalledTimes(1); expect(finalize).toHaveBeenCalledTimes(1); @@ -375,13 +381,7 @@ describe("VersionUploaderComponent", () => { component.cancelExistingUpload("b.txt", onCanceled); - expect(finalize).toHaveBeenCalledWith( - DATASET_FILE_RESOURCE_ENDPOINT, - "[email protected]", - "test-dataset", - "b.txt", - true - ); + expectAbortRequest("b.txt"); expect(onCanceled).toHaveBeenCalledTimes(1); }); @@ -450,13 +450,7 @@ describe("VersionUploaderComponent", () => { component.cancelExistingUpload("b.txt", onCanceled); - expect(finalize).toHaveBeenCalledWith( - DATASET_FILE_RESOURCE_ENDPOINT, - "[email protected]", - "test-dataset", - "b.txt", - true - ); + expectAbortRequest("b.txt"); expect(component.uploadTasks.find(t => t.filePath === "b.txt")!.status).toBe("aborted"); // The slot goes back to the queue instead of being held by an attempt that // is no longer running. @@ -475,10 +469,7 @@ describe("VersionUploaderComponent", () => { throwError(() => ({ status: 500 }) as any) ) ); - const task = inFlight(); - const onAborted = vi.fn(); - - component.onClickAbortUploadProgress(task as any, onAborted); + const onAborted = abortInFlight(); expect(onAborted).toHaveBeenCalledTimes(1); }); @@ -489,13 +480,7 @@ describe("VersionUploaderComponent", () => { component.onClickAbortUploadProgress(task as any); - expect(finalize).toHaveBeenCalledWith( - DATASET_FILE_RESOURCE_ENDPOINT, - "[email protected]", - "test-dataset", - "a.txt", - true - ); + expectAbortRequest("a.txt"); // Writing "aborted" back at a missing index would leave a phantom "-1" property on // the array, which neither a throw nor `.length` would reveal. expect(component.uploadTasks).toEqual([]); @@ -509,15 +494,7 @@ describe("VersionUploaderComponent", () => { /** Rebuilds the fixture so a per-test settings stub is in place before ngOnInit runs. */ const rebuild = (seed?: (c: VersionUploaderComponent) => void): void => { fixture.destroy(); - fixture = TestBed.createComponent(VersionUploaderComponent); - component = fixture.componentInstance; - component.resourceId = 1; - component.ownerEmail = "[email protected]"; - component.resourceName = "test-dataset"; - component.endpoint = DATASET_FILE_RESOURCE_ENDPOINT; - component.createVersion = asCreateVersion(createVersionSpy); - seed?.(component); - fixture.detectChanges(); + mount(seed); }; /** The panel is the only thing that knows which resource family it is addressing. */ @@ -533,12 +510,8 @@ describe("VersionUploaderComponent", () => { }); it("reads its upload tuning from its own family's settings keys", () => { - const settings = TestBed.inject(AdminSettingsService) as unknown as { - getPublicSetting: ReturnType<typeof vi.fn>; - }; - // The last is the file picker's own per-file ceiling, which it reads off the same endpoint. - expect(settings.getPublicSetting.mock.calls.map(call => call[0])).toEqual([ + expect(settingsStub().getPublicSetting.mock.calls.map(call => call[0])).toEqual([ DATASET_FILE_RESOURCE_ENDPOINT.chunkSizeSettingKey, DATASET_FILE_RESOURCE_ENDPOINT.maxConcurrentChunksSettingKey, DATASET_FILE_RESOURCE_ENDPOINT.maxConcurrentFilesSettingKey, @@ -659,8 +632,7 @@ describe("VersionUploaderComponent", () => { it("clears the staged state, tells the host to reload, and re-enables the button", () => { const versionCreated = vi.fn(); component.versionCreated.subscribe(versionCreated); - dropFiles("a.csv"); - finishUpload(0, "a.csv"); + stageFile("a.csv"); expect(component.pendingChangesCount).toBe(1); component.onClickCreateVersion(); @@ -675,8 +647,7 @@ describe("VersionUploaderComponent", () => { createVersionSpy.mockReturnValue(throwError(() => new HttpErrorResponse({ status: 400 }))); const versionCreated = vi.fn(); component.versionCreated.subscribe(versionCreated); - dropFiles("a.csv"); - finishUpload(0, "a.csv"); + stageFile("a.csv"); component.onClickCreateVersion(); @@ -859,8 +830,7 @@ describe("VersionUploaderComponent", () => { }); it("does not double-count a finished upload already confirmed by a diff response", () => { - dropFiles("f1.txt"); - finishUpload(0, "f1.txt"); + stageFile("f1.txt"); component.onStagedObjectsUpdated([{ path: "f1.txt", pathType: "file", diffType: "added", sizeBytes: 1 }]); expect(component.pendingChangesCount).toBe(1); @@ -882,8 +852,7 @@ describe("VersionUploaderComponent", () => { }); it("clears the Finished count when a version is created", () => { - dropFiles("f1.txt"); - finishUpload(0, "f1.txt"); + stageFile("f1.txt"); expect(component.pendingChangesCount).toBe(1); component.versionName = "v1"; @@ -945,44 +914,41 @@ describe("VersionUploaderComponent", () => { expect(component.queuedFileNames).toEqual(["f5.txt"]); }); - describe("rendered progress", () => { - /** - * Puts one task on the panel in the given state and opens it. The panel is gated on the - * separate activeUploads counter rather than on uploadTasks, and ng-zorro collapses it by - * default, so both have to be arranged before its body exists. - */ - function withTask(over: Record<string, unknown>): HTMLElement { - (component as any).activeUploads = 1; - component.uploadTasks = [ - { - filePath: "big.csv", - percentage: 40, - status: "uploading", - uploadSpeed: 1024, - totalTime: 12, - estimatedTimeRemaining: 30, - ...over, - } as any, - ]; - fixture.detectChanges(); - const el = fixture.nativeElement as HTMLElement; - const header = Array.from(el.querySelectorAll<HTMLElement>(".ant-collapse-header")).find(h => - (h.textContent || "").includes("Uploading:") - ); - header!.click(); - fixture.detectChanges(); - return el; - } + const host = (): HTMLElement => fixture.nativeElement as HTMLElement; + + /** Render the tasks after supplying the active count and opening the collapsed panel. */ + function withTasks(...tasks: Array<Partial<VersionUploaderComponent["uploadTasks"][number]>>): HTMLElement { + component.uploadTasks = tasks.map(task => ({ + filePath: "big.csv", + percentage: 40, + status: "uploading", + uploadSpeed: 1024, + totalTime: 12, + estimatedTimeRemaining: 30, + ...task, + })); + (component as unknown as { activeUploads: number }).activeUploads = tasks.length; + fixture.detectChanges(); + const el = host(); + const header = Array.from(el.querySelectorAll<HTMLElement>(".ant-collapse-header")).find(h => + (h.textContent || "").includes("Uploading:") + ); + expect(header, 'expected a collapse panel headed "Uploading:"').toBeDefined(); + header!.click(); + fixture.detectChanges(); + return el; + } + describe("rendered progress", () => { it("shows no statistics while an upload is still initializing", () => { // There is nothing to report yet; showing a 0 B/s row reads as a stalled upload. - const el = withTask({ status: "initializing" }); + const el = withTasks({ status: "initializing" }); expect(el.querySelector(".upload-stats")).toBeNull(); }); it("reports speed and both timings while an upload runs", () => { - const el = withTask({ status: "uploading" }); + const el = withTasks({ status: "uploading" }); const stats = el.querySelector(".upload-stats")!; expect(stats.textContent).toContain("elapsed"); @@ -991,7 +957,7 @@ describe("VersionUploaderComponent", () => { }); it("replaces the live figures with a total once the upload finishes", () => { - const el = withTask({ status: "finished" }); + const el = withTasks({ status: "finished" }); const stats = el.querySelector(".upload-stats")!; expect(stats.textContent).toContain("Upload time:"); @@ -999,15 +965,13 @@ describe("VersionUploaderComponent", () => { }); it("reports a total for an aborted upload too", () => { - const el = withTask({ status: "aborted" }); + const el = withTasks({ status: "aborted" }); expect(el.querySelector(".upload-stats")!.textContent).toContain("Upload time:"); }); }); describe("rendered panel", () => { - const host = (): HTMLElement => fixture.nativeElement as HTMLElement; - const q = <E extends Element>(root: ParentNode, selector: string): E => { const el = root.querySelector(selector); expect(el, `expected to find "${selector}"`).not.toBeNull(); @@ -1016,16 +980,6 @@ describe("VersionUploaderComponent", () => { const text = (el: Element | null | undefined): string => (el?.textContent ?? "").replace(/\s+/g, " ").trim(); - /** ng-zorro collapses every status panel by default, so its body has to be opened first. */ - const openPanel = (header: string): void => { - const found = Array.from(host().querySelectorAll<HTMLElement>(".ant-collapse-header")).find(h => - (h.textContent || "").includes(header) - ); - expect(found, `expected a collapse panel headed "${header}"`).toBeDefined(); - found!.click(); - fixture.detectChanges(); - }; - describe("upload panel", () => { it("starts an upload for a file the uploader hands over", () => { const el = host(); @@ -1053,22 +1007,6 @@ describe("VersionUploaderComponent", () => { expect(text(el)).toContain("Uploading: 1 file(s)"); }); - /** Renders the given in-flight tasks and expands the "Uploading" panel. */ - const withTasks = (...tasks: Array<Record<string, unknown>>): HTMLElement => { - component.uploadTasks = tasks.map(t => ({ - percentage: 40, - status: "uploading", - uploadSpeed: 1024, - totalTime: 12, - estimatedTimeRemaining: 30, - ...t, - })) as never; - (component as unknown as { activeUploads: number }).activeUploads = tasks.length; - fixture.detectChanges(); - openPanel("Uploading:"); - return host(); - }; - it("aborts the upload whose own row button was clicked", () => { withTasks({ filePath: "first.csv" }, { filePath: "second.csv" }); @@ -1088,17 +1026,8 @@ describe("VersionUploaderComponent", () => { abort.nativeElement.click(); fixture.detectChanges(); - const finalize = TestBed.inject(MultipartUploadService).finalizeMultipartUpload as unknown as ReturnType< - typeof vi.fn - >; expect(finalize).toHaveBeenCalledTimes(1); - expect(finalize).toHaveBeenCalledWith( - DATASET_FILE_RESOURCE_ENDPOINT, - "[email protected]", - "test-dataset", - "second.csv", - true - ); + expectAbortRequest("second.csv"); }); it("reports the elapsed time, the time remaining and the speed in their own slots", () => { diff --git a/frontend/src/app/dashboard/component/user/version-uploader/version-uploader.component.ts b/frontend/src/app/dashboard/component/user/version-uploader/version-uploader.component.ts index 860d3226a3..d6b4e2482e 100644 --- a/frontend/src/app/dashboard/component/user/version-uploader/version-uploader.component.ts +++ b/frontend/src/app/dashboard/component/user/version-uploader/version-uploader.component.ts @@ -156,27 +156,20 @@ export class VersionUploaderComponent implements OnInit { // A missing key or failed fetch keeps the field defaults; NaN here would silently stall the // upload queue (`activeUploads < NaN` is always false). private loadUploadSettings(): void { - this.adminSettingsService - .getPublicSetting(this.endpoint.chunkSizeSettingKey) - .pipe(untilDestroyed(this)) - .subscribe({ - next: value => (this.chunkSizeMiB = parseIntOrDefault(value, this.chunkSizeMiB)), - error: () => {}, - }); - this.adminSettingsService - .getPublicSetting(this.endpoint.maxConcurrentChunksSettingKey) - .pipe(untilDestroyed(this)) - .subscribe({ - next: value => (this.maxConcurrentChunks = parseIntOrDefault(value, this.maxConcurrentChunks)), - error: () => {}, - }); - this.adminSettingsService - .getPublicSetting(this.endpoint.maxConcurrentFilesSettingKey) - .pipe(untilDestroyed(this)) - .subscribe({ - next: value => (this.maxConcurrentFiles = parseIntOrDefault(value, this.maxConcurrentFiles)), - error: () => {}, - }); + const settings = [ + ["chunkSizeSettingKey", "chunkSizeMiB"], + ["maxConcurrentChunksSettingKey", "maxConcurrentChunks"], + ["maxConcurrentFilesSettingKey", "maxConcurrentFiles"], + ] as const; + for (const [key, field] of settings) { + this.adminSettingsService + .getPublicSetting(this.endpoint[key]) + .pipe(untilDestroyed(this)) + .subscribe({ + next: value => (this[field] = parseIntOrDefault(value, this[field])), + error: () => {}, + }); + } } onNewUploadFilesChanged(files: FileUploadItem[]): void { diff --git a/frontend/src/app/dashboard/component/user/versions-files-browser/versions-files-browser.component.scss b/frontend/src/app/dashboard/component/user/versions-files-browser/versions-files-browser.component.scss index b1e2c96b26..3c794bbe12 100644 --- a/frontend/src/app/dashboard/component/user/versions-files-browser/versions-files-browser.component.scss +++ b/frontend/src/app/dashboard/component/user/versions-files-browser/versions-files-browser.component.scss @@ -17,10 +17,10 @@ * under the License. */ +@use "../resource-detail-shared" as detail; + .versions-tab-content { - height: 100%; - overflow-y: auto; - padding-bottom: 24px; + @include detail.scrollable-tab; } nz-layout {
