mengw15 commented on code in PR #8005: URL: https://github.com/apache/texera/pull/8005#discussion_r4021175076
########## frontend/src/app/common/component/warehouse-create-modal/warehouse-create-modal.component.ts: ########## @@ -0,0 +1,113 @@ +/** + * 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 { NotificationService } from "../../service/notification/notification.service"; +import { WarehouseActionsService } from "../../service/warehouse/warehouse-actions.service"; +import { DashboardWarehouse } from "../../type/warehouse"; +import { extractErrorMessage } from "../../util/error"; + +/** + * 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, + private notificationService: NotificationService + ) {} + + ngOnChanges(changes: SimpleChanges): void { + if (changes["visible"]?.currentValue === true) { + this.newWarehouseName = ""; + } + } + + /** + * Mirrors ComputingUnitCreateModalComponent's submit flow: Create fires the + * request and closes the dialog at once; the outcome arrives later as a toast + * plus (warehouseCreated). There is no in-flight dialog state left to cancel, + * so a create that lands after the close shows up visibly in the list instead + * of surprising a retry with "already exists". Unlike the computing-unit + * dialog, an empty name never reaches the request: the Create button is + * disabled and the Enter path returns early, keeping the dialog open. + */ + handleCreateWarehouseModalOk(): void { + const name = this.newWarehouseName.trim(); + if (!name) { + return; + } + this.createWarehouse(name); + this.closeModal(); + } + + handleCreateWarehouseModalCancel(): void { + this.closeModal(); + } + + private createWarehouse(name: string): void { + this.warehouseActionsService + .create(name) + .pipe(untilDestroyed(this)) Review Comment: Done — the service owns the request and both toasts now (shareReplay plus its own subscription), so navigating away mid-create neither aborts the request nor swallows the outcome; the dialog only relays the created warehouse to its host. ########## frontend/src/app/common/component/warehouse-create-modal/warehouse-create-modal.component.ts: ########## @@ -0,0 +1,113 @@ +/** + * 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 { NotificationService } from "../../service/notification/notification.service"; +import { WarehouseActionsService } from "../../service/warehouse/warehouse-actions.service"; +import { DashboardWarehouse } from "../../type/warehouse"; +import { extractErrorMessage } from "../../util/error"; + +/** + * 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, + private notificationService: NotificationService + ) {} + + ngOnChanges(changes: SimpleChanges): void { + if (changes["visible"]?.currentValue === true) { + this.newWarehouseName = ""; + } + } + + /** + * Mirrors ComputingUnitCreateModalComponent's submit flow: Create fires the + * request and closes the dialog at once; the outcome arrives later as a toast + * plus (warehouseCreated). There is no in-flight dialog state left to cancel, + * so a create that lands after the close shows up visibly in the list instead + * of surprising a retry with "already exists". Unlike the computing-unit + * dialog, an empty name never reaches the request: the Create button is + * disabled and the Enter path returns early, keeping the dialog open. + */ + handleCreateWarehouseModalOk(): void { Review Comment: Done — submitting clears the name, so a second click during the close animation falls into the validity guard. Covered by a regression test. ########## frontend/src/app/common/component/warehouse-create-modal/warehouse-create-modal.component.html: ########## @@ -0,0 +1,57 @@ +<!-- + 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. +--> + +<nz-modal + [nzVisible]="visible" + nzTitle="Create Warehouse" + [nzContent]="createWarehouseModalContent" + [nzFooter]="createWarehouseModalFooter" + (nzOnCancel)="handleCreateWarehouseModalCancel()"> + <ng-template #createWarehouseModalContent> + <div class="create-warehouse-container"> + <div class="select-unit name-field"> + <span>Warehouse Name</span> + <input + nz-input + placeholder="Enter the name of your warehouse (required)" + maxlength="64" + [(ngModel)]="newWarehouseName" + class="warehouse-name-input" + (keyup.enter)="handleCreateWarehouseModalOk()" /> + <p class="warehouse-name-hint">Letters, digits, '-' and '_' only; must start with a letter or digit.</p> Review Comment: Done — the Create button and the Enter path now enforce VFSURIFactory's pattern, so an invalid name never leaves the dialog. ########## frontend/src/app/dashboard/component/user/user-warehouse/user-warehouse-list-item/user-warehouse-list-item.component.scss: ########## @@ -0,0 +1,105 @@ +/** + * 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 *; + +.warehouse-list-item-card { + padding: 3px; + width: 100%; + background-color: white; + position: relative; + min-height: 65px; + height: auto; + + &:hover { + background-color: #f0f0f0; + } +} + +// The computing-unit row is 64px of content: its two 32px metric bars drive +// the height. A warehouse row has no metrics, so pin the same content height +// here — card paddings and borders already match, so the rows line up exactly. +.warehouse-item-row { + min-height: 64px; +} + +.warehouse-list-item-card:hover .button-group { + display: flex; + background-color: transparent; +} + Review Comment: Done. ########## frontend/src/app/dashboard/component/user/user-warehouse/user-warehouse-list-item/user-warehouse-list-item.component.scss: ########## Review Comment: Done — the six shared rules live in `section-style.scss` now and both list items dropped their copies; of the files importing it, only these two templates use the classes. ########## frontend/src/app/dashboard/component/user/user-warehouse/user-warehouse.component.ts: ########## @@ -0,0 +1,145 @@ +/** + * 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()); + } + + showAddWarehouseModalVisible(): void { + this.addWarehouseModalVisible = true; + } + + onWarehouseCreated(): void { Review Comment: Done — appended; verified the backend orders by `created_at` ascending. -- 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]
