gracecluvohio commented on code in PR #4331: URL: https://github.com/apache/texera/pull/4331#discussion_r3036126770
########## frontend/src/app/dashboard/component/user/user-computing-unit/user-computing-unit-list-item/user-computing-unit-list-item.component.ts: ########## @@ -0,0 +1,319 @@ +/** + * 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 { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from "@angular/core"; +import { ComputingUnitStatusService } from "../../../../../workspace/service/computing-unit-status/computing-unit-status.service"; +import { extractErrorMessage } from "../../../../../common/util/error"; +import { NotificationService } from "../../../../../common/service/notification/notification.service"; +import { NzModalService } from "ng-zorro-antd/modal"; +import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy"; +import { + DashboardWorkflowComputingUnit, + WorkflowComputingUnit, +} from "../../../../../workspace/types/workflow-computing-unit"; +import { WorkflowComputingUnitManagingService } from "../../../../../workspace/service/workflow-computing-unit/workflow-computing-unit-managing.service"; +import { + buildComputingUnitMetadataTable, + parseResourceUnit, + parseResourceNumber, + cpuResourceConversion, + memoryResourceConversion, + cpuPercentage, + memoryPercentage, +} from "../../../../../common/util/computing-unit.util"; + +@UntilDestroy() +@Component({ + selector: "texera-user-computing-unit-list-item", + templateUrl: "./user-computing-unit-list-item.component.html", + styleUrls: ["./user-computing-unit-list-item.component.scss"], +}) +export class UserComputingUnitListItemComponent implements OnInit { + private _entry?: DashboardWorkflowComputingUnit; + editingNameOfUnit: number | null = null; + editingUnitName: string = ""; + gpuOptions: string[] = []; + @Input() editable = false; + @Output() deleted = new EventEmitter<void>(); + + @Input() + get entry(): DashboardWorkflowComputingUnit { + if (!this._entry) { + throw new Error("entry property must be provided to UserComputingUnitListItemComponent."); + } + return this._entry; + } + + set entry(value: DashboardWorkflowComputingUnit) { + this._entry = value; + } + + get unit(): WorkflowComputingUnit { + if (!this.entry.computingUnit) { + throw new Error( + "Incorrect type of DashboardEntry provided to UserComputingUnitListItemComponent. Entry must be computing unit." + ); + } + return this.entry.computingUnit; + } + + constructor( + private cdr: ChangeDetectorRef, + private modalService: NzModalService, + private notificationService: NotificationService, + private computingUnitService: WorkflowComputingUnitManagingService, + private computingUnitStatusService: ComputingUnitStatusService + ) {} + + ngOnInit(): void { + this.computingUnitService + .getComputingUnitLimitOptions() + .pipe(untilDestroyed(this)) + .subscribe({ + next: ({ gpuLimitOptions }) => { + this.gpuOptions = gpuLimitOptions ?? []; + }, + error: (err: unknown) => + this.notificationService.error(`Failed to fetch resource options: ${extractErrorMessage(err)}`), + }); + } + + startEditingUnitName(entry: DashboardWorkflowComputingUnit): void { + if (!entry.isOwner) { + this.notificationService.error("Only owners can rename computing units"); + return; + } + + this.editingNameOfUnit = entry.computingUnit.cuid; + this.editingUnitName = entry.computingUnit.name; + + // Force change detection and focus the input + this.cdr.detectChanges(); + setTimeout(() => { + const input = document.querySelector(".unit-name-edit-input") as HTMLInputElement; + if (input) { + input.focus(); + input.select(); + } + }, 0); + } Review Comment: Sounds good -- 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]
