kunwp1 commented on code in PR #8005: URL: https://github.com/apache/texera/pull/8005#discussion_r4020427202
########## 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: Can you move the request and its notifications into WarehouseActionsService? Consider a user who clicks Create and then clicks another tab (e.g., 'Workflow' tab). The dialog has already closed at line 87, and the backend is still creating the warehouse in Lakekeeper, which takes a network round trip. The page is destroyed, the subscription is torn down, and the browser aborts the request. The server completes the operation regardless: it creates the Lakekeeper warehouse and inserts the user_warehouse row. As a result, the warehouse exists but warehouseCreated is never emitted. When the user later creates a warehouse with the same name, the request fails. ########## 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: Add `.list-item-card:focus-within .button-group {` as what `list-item.component.scss` is doing. ########## frontend/src/app/dashboard/component/user/user-warehouse/user-warehouse-list-item/user-warehouse-list-item.component.html: ########## @@ -0,0 +1,86 @@ +<!-- + 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-card + [nzBodyStyle]="{padding: '3px'}" + class="warehouse-list-item-card"> + <div + nz-row + nzAlign="middle" + class="warehouse-item-row"> + <div + nz-col + nzFlex="20px"></div> + + <div + nz-col + nzFlex="0" + class="type-icon"> + <i + nz-icon + nzType="cloud-server"></i> + </div> + + <div + nz-col + nzFlex="0" + class="warehouse-id"> + <i>#{{ warehouse.whid }}</i> + </div> + + <div + nz-col + nzFlex="1" + class="resource-name-group"> + <div + class="resource-name truncate-single-line" + (click)="openWarehouseMetadataModal()"> + {{ warehouse.name }} + </div> + </div> + + <div class="button-group"> + <button + nz-button + nzType="text" + title="Delete" + (click)="deleted.emit()"> + <i + nz-icon + nzType="delete"></i> + </button> + </div> + + <div + nz-col + nzFlex="100px" + class="resource-info"> + Created:<br /> + {{ formatRelativeTime(warehouse.createdAtMillis) }} Review Comment: I think it's too inefficient to call `formatRelativeTime` all the time for every rendered row. Can you think of a better way? ########## frontend/src/app/dashboard/component/user/user-warehouse/user-warehouse.component.scss: ########## @@ -0,0 +1,30 @@ +/** + * 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 "../../dashboard.component.scss" as *; Review Comment: I think you don't need this line. ########## 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: Can you add a guard in the front to handle a case where a user clicks the "Create" button twice quickly? ########## 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: I think it would be nice to apply the pattern of `VFSURIFactory.isValidWarehouseName` in the [disabled] binding so that we don't send a request to the backend with invalid names. ########## frontend/src/app/dashboard/component/user/user-warehouse/user-warehouse-list-item/user-warehouse-list-item.component.scss: ########## Review Comment: Can we do a refactoring to move `.type-icon, .resource-name-group, .resource-name, .resource-name:hover, .resource-info, .truncate-single-line` to maybe `section-style.scss` because they are exact duplicate of `user-computing-unit-list-item.component.scss`? I also see some of them are duplicates of `list-item.component.scss` as well. ########## 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: I think it's more efficient to just append `this.warehouses` with the newly created warehouse. The backend orders rows by "created_at asc" so I think this way we don't need to call the backend API. -- 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]
