kunwp1 commented on code in PR #8005: URL: https://github.com/apache/texera/pull/8005#discussion_r4022204395
########## frontend/src/app/dashboard/component/user/user-warehouse/user-warehouse-list-item/user-warehouse-list-item.component.scss: ########## @@ -0,0 +1,78 @@ +/** + * 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. + */ + +@use "../../../section-style" as *; +@use "../../../dashboard.component.scss" as *; Review Comment: Maybe it's deletable? ########## frontend/src/app/common/service/warehouse/warehouse-actions.service.ts: ########## @@ -41,9 +42,23 @@ export class WarehouseActionsService { private notificationService: NotificationService ) {} - /** Creates a warehouse. Needs no confirmation, unlike the delete below. */ + /** + * Creates a warehouse and reports the outcome itself: the service owns the + * subscription, so the request and its toasts survive the dialog — and the + * whole page — being destroyed. Without this, navigating away mid-create + * aborts the browser request while the server finishes anyway: the warehouse + * exists, nothing was reported, and the next same-name attempt fails + * confusingly. The returned observable replays the created warehouse for + * callers that want it (the dialog relays it to its host). + */ create(name: string): Observable<DashboardWarehouse> { - return this.warehouseService.createWarehouse(name); + const request$ = this.warehouseService.createWarehouse(name).pipe(shareReplay({ bufferSize: 1, refCount: false })); Review Comment: `shareReplay` replay contract doesn't hold when the request fails. ########## frontend/src/app/common/component/warehouse-create-modal/warehouse-create-modal.component.ts: ########## @@ -0,0 +1,107 @@ +/** + * 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, EventEmitter, Input, OnChanges, Output, SimpleChanges } from "@angular/core"; +import { FormsModule } from "@angular/forms"; +import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy"; +import { NzButtonComponent } from "ng-zorro-antd/button"; +import { ɵNzTransitionPatchDirective } from "ng-zorro-antd/core/transition-patch"; +import { NzWaveDirective } from "ng-zorro-antd/core/wave"; +import { NzInputDirective } from "ng-zorro-antd/input"; +import { NzModalComponent } from "ng-zorro-antd/modal"; +import { WarehouseActionsService } from "../../service/warehouse/warehouse-actions.service"; +import { DashboardWarehouse } from "../../type/warehouse"; + +/** + * Shared create-warehouse modal (#6933), embedded the same way + * ComputingUnitCreateModalComponent is — two-way `[(visible)]` controls the + * dialog and `(warehouseCreated)` returns the created warehouse — by the + * dashboard tab today and by the workspace picker once it lands (#7817). + */ +@UntilDestroy() +@Component({ + selector: "texera-warehouse-create-modal", + templateUrl: "./warehouse-create-modal.component.html", + styleUrls: ["./warehouse-create-modal.component.scss"], + imports: [ + FormsModule, + NzModalComponent, + NzButtonComponent, + NzWaveDirective, + ɵNzTransitionPatchDirective, + NzInputDirective, + ], +}) +export class WarehouseCreateModalComponent implements OnChanges { + // Must be bound two-way ([(visible)]): the modal closes itself. + @Input() visible = false; + @Output() visibleChange = new EventEmitter<boolean>(); + @Output() warehouseCreated = new EventEmitter<DashboardWarehouse>(); + + newWarehouseName = ""; + + constructor(private warehouseActionsService: WarehouseActionsService) {} + + ngOnChanges(changes: SimpleChanges): void { + if (changes["visible"]?.currentValue === true) { + this.newWarehouseName = ""; + } + } + + // Mirrors the backend's VFSURIFactory.warehouseNamePattern (≤64 comes from + // the input's maxlength), so an invalid name never leaves the dialog: the + // Create button stays disabled and the Enter path returns early. + private static readonly VALID_WAREHOUSE_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/; + + isValidWarehouseName(): boolean { + return WarehouseCreateModalComponent.VALID_WAREHOUSE_NAME.test(this.newWarehouseName.trim()); + } + + /** + * Mirrors ComputingUnitCreateModalComponent's submit flow: Create fires the + * request and closes the dialog at once. The actions service owns the request + * and its toasts, so the outcome arrives even if the user has navigated away; + * this dialog only relays the created warehouse to its host while it is + * still alive. + */ + handleCreateWarehouseModalOk(): void { + if (!this.isValidWarehouseName()) { + return; + } + const name = this.newWarehouseName.trim(); + // The dialog stays clickable through its close animation; clearing the + // name drops a second rapid click into the guard above instead of firing + // a duplicate create. + this.newWarehouseName = ""; + this.warehouseActionsService + .create(name) + .pipe(untilDestroyed(this)) + .subscribe(created => this.warehouseCreated.emit(created)); Review Comment: Please add unhandled RxJS error on every failed create. ########## frontend/src/app/dashboard/component/user/user-warehouse/user-warehouse.component.ts: ########## @@ -0,0 +1,147 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Component, OnInit } from "@angular/core"; +import { NgIf } from "@angular/common"; +import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy"; +import { EMPTY, Subject, catchError, switchMap } from "rxjs"; + +import { ɵɵCdkVirtualScrollViewport, ɵɵCdkFixedSizeVirtualScroll, ɵɵCdkVirtualForOf } from "@angular/cdk/overlay"; +import { NzButtonComponent } from "ng-zorro-antd/button"; +import { NzCardComponent } from "ng-zorro-antd/card"; +import { ɵNzTransitionPatchDirective } from "ng-zorro-antd/core/transition-patch"; +import { NzWaveDirective } from "ng-zorro-antd/core/wave"; +import { NzIconDirective } from "ng-zorro-antd/icon"; +import { NzListComponent } from "ng-zorro-antd/list"; + +import { WarehouseCreateModalComponent } from "../../../../common/component/warehouse-create-modal/warehouse-create-modal.component"; +import { NotificationService } from "../../../../common/service/notification/notification.service"; +import { WarehouseActionsService } from "../../../../common/service/warehouse/warehouse-actions.service"; +import { WarehouseService } from "../../../../common/service/warehouse/warehouse.service"; +import { DashboardWarehouse } from "../../../../common/type/warehouse"; +import { extractErrorMessage } from "../../../../common/util/error"; +import { UserWarehouseListItemComponent } from "./user-warehouse-list-item/user-warehouse-list-item.component"; + +/** + * Dashboard page for per-user warehouses (#6933), mirroring + * UserComputingUnitComponent: list the caller's warehouses, create one (Local + * flavor), delete one. Reachable only while the deployment reports the feature + * enabled; the page re-checks and says so otherwise. + */ +@UntilDestroy() +@Component({ + selector: "texera-user-warehouse", + templateUrl: "./user-warehouse.component.html", + styleUrls: ["./user-warehouse.component.scss"], + imports: [ + NgIf, + NzCardComponent, + NzButtonComponent, + NzWaveDirective, + ɵNzTransitionPatchDirective, + NzIconDirective, + ɵɵCdkVirtualScrollViewport, + ɵɵCdkFixedSizeVirtualScroll, + NzListComponent, + ɵɵCdkVirtualForOf, + UserWarehouseListItemComponent, + WarehouseCreateModalComponent, + ], +}) +export class UserWarehouseComponent implements OnInit { + // Undefined until the status request settles: with a plain false, a pending or + // failed request renders the "disabled in this deployment" notice, which names + // the wrong cause. + warehouseEnabled?: boolean; + warehouses: DashboardWarehouse[] = []; + // The status request failed: without this the page renders neither the + // disabled notice nor the list, leaving a blank card and no way back. + loadFailed = false; + + // visibility of the shared create-warehouse modal + addWarehouseModalVisible = false; + + constructor( + private warehouseService: WarehouseService, + private notificationService: NotificationService, + private warehouseActionsService: WarehouseActionsService + ) {} + + // All refreshes flow through one switchMap'd stream: a new request cancels + // the in-flight one, so a response arriving late can never overwrite newer + // state (say, resurrecting a warehouse a later refresh saw deleted). + private readonly refreshRequested$ = new Subject<void>(); + + ngOnInit(): void { + this.refreshRequested$ + .pipe( + switchMap(() => + this.warehouseService.getStatus().pipe( + // Caught inside the switchMap so a failure ends only this request, + // not the stream — Retry must still work afterwards. + catchError((err: unknown) => { + this.loadFailed = true; + // A failed refresh must not leave the previous answer behind: + // stale rows (possibly including a just-deleted warehouse) and an + // enabled Create button would render alongside the failure + // notice, mixing the states this page promises to keep distinct. + this.warehouseEnabled = undefined; + this.warehouses = []; + console.error("Failed to fetch warehouses", err); + this.notificationService.error(`Failed to fetch warehouses: ${extractErrorMessage(err)}`); + return EMPTY; + }) + ) + ), + untilDestroyed(this) + ) + .subscribe(status => { + this.loadFailed = false; + this.warehouseEnabled = status.enabled; + this.warehouses = [...status.warehouses]; + }); + this.refresh(); + } + + retry(): void { + this.refresh(); + } + + // Identity for *cdkVirtualFor, so a refresh reuses the rendered rows instead + // of rebuilding every one. + trackByWarehouse = (_: number, warehouse: DashboardWarehouse): number => warehouse.whid; + + private refresh(): void { + this.refreshRequested$.next(); + } + + deleteWarehouse(warehouse: DashboardWarehouse): void { + this.warehouseActionsService.confirmAndDelete(warehouse, () => this.refresh()); Review Comment: I think this can also be optimized by not sending a round trip. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
