mengw15 commented on code in PR #8005: URL: https://github.com/apache/texera/pull/8005#discussion_r4019052155
########## frontend/src/app/common/component/warehouse-create-modal/warehouse-create-modal.component.ts: ########## @@ -0,0 +1,117 @@ +/** + * 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 { Subject, takeUntil } from "rxjs"; +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 = ""; + creating = false; + + // Closing the dialog ends the attempt it was showing. Without this the request + // outlives the dialog (the component itself is never torn down), so Cancel + // would still create the warehouse and a late response would close — and + // discard — whatever the user had typed after reopening. + private readonly closed$ = new Subject<void>(); + + constructor( + private warehouseActionsService: WarehouseActionsService, + private notificationService: NotificationService + ) {} + + ngOnChanges(changes: SimpleChanges): void { + if (changes["visible"]?.currentValue === true) { + this.newWarehouseName = ""; + // Cancelling mid-flight leaves creating set; without this the Create button + // reopens stuck in its loading state. + this.creating = false; + } + } + + createWarehouse(): void { + const name = this.newWarehouseName.trim(); + if (!name || this.creating) { + return; + } + this.creating = true; + this.warehouseActionsService + .create(name) + .pipe(takeUntil(this.closed$), untilDestroyed(this)) Review Comment: Reworked to mirror the computing-unit dialog: Create fires the request and closes at once, and the outcome arrives as a toast plus the list refresh. There is no in-flight state left to cancel, so a create that lands anyway shows up visibly in the list instead of surprising a retry with "already exists". ########## frontend/src/app/dashboard/component/dashboard.component.ts: ########## @@ -170,6 +179,26 @@ export class DashboardComponent implements OnInit { this.loadTabs(); } + // The status endpoint needs an authenticated user; logged out (or on any + // fetch failure) the tab simply stays hidden. + loadWarehouseEnabled(): void { Review Comment: Done — `ConfigResource` now serves `storage.warehouse.enabled` as `warehouseEnabled`, the sidebar reads `config.env`, and the `WarehouseService` injection is gone. ########## frontend/src/app/dashboard/component/user/user-warehouse/user-warehouse.component.html: ########## @@ -0,0 +1,84 @@ +<!-- + 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. +--> + +<div class="section-container subsection-grid-container"> + <nz-card class="section-title"> + <h2 class="page-title">Warehouses</h2> + <div class="button-group"> + <button + nz-button + class="create-btn" + (click)="showAddWarehouseModalVisible()" + [disabled]="!warehouseEnabled" + title="Create Warehouse"> + <i + nz-icon + nzType="file-add" + nzTheme="outline"></i> + <span>Create Warehouse</span> + </button> + </div> + </nz-card> + + <nz-card + class="section-list-container" + [nzBodyStyle]="{ height: '100%'}"> + <div + *ngIf="loadFailed" + class="warehouse-page-empty"> + Could not load your warehouses. + <button + nz-button + nzType="link" + (click)="retry()"> + Retry + </button> + </div> + + <div + *ngIf="warehouseEnabled === false" + class="warehouse-page-empty"> + Per-user warehouses are disabled in this deployment. + </div> + + <div + *ngIf="warehouseEnabled && warehouses.length === 0" + class="warehouse-page-empty"> + No warehouses yet. Click <strong>Create Warehouse</strong> to create one. + </div> + + <cdk-virtual-scroll-viewport + *ngIf="warehouseEnabled && warehouses.length > 0" + itemSize="70" Review Comment: Good catch — measured in the browser: the real row pitch is 78px (1px border + 3px card padding + 3px body padding + 64px row, mirrored below), so at 70 a thirty-row list lost 240px and the last three rows never scrolled into view. Set to the measured 78 and re-verified with 30 rows that the last one reaches the viewport. -- 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]
