kunwp1 commented on code in PR #5035:
URL: https://github.com/apache/texera/pull/5035#discussion_r3231335376


##########
frontend/src/app/workspace/component/power-button/computing-unit-selection.component.ts:
##########
@@ -732,14 +734,32 @@ export class ComputingUnitSelectionComponent implements 
OnInit {
 
   addPackage(index: number): void {
     const env = this.pves[index];
-    env.newPackages.push({ name: "", version: "", versionOp: undefined });
+    env.newPackages.push({ name: "", version: "", versionOp: undefined, 
deleteToggle: false });
+  }
+
+  togglePackageDelete(index: number, pkg: PveUserPackageRow): void {
+    const env = this.pves[index];
+
+    pkg.deleteToggle = !pkg.deleteToggle;
+
+    const version = pkg.version ?? "";
+
+    if (pkg.deleteToggle) {
+      const exists = env.deletingPackages.some(p => p.name === pkg.name && 
(p.version ?? "") === version);
+      if (!exists) {
+        env.deletingPackages.push({ name: pkg.name, version });
+      }
+    } else {
+      env.deletingPackages = env.deletingPackages.filter(p => !(p.name === 
pkg.name && (p.version ?? "") === version));
+    }

Review Comment:
   I think this logic can be simplified by
   1. Drop the `?? ""` in the filter predicate because version is already 
normalized when pushed to `deletingPackages`
   2. Always filter first, then push if delete toggle is on (In this way you 
can remove redundant exists check)



-- 
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]

Reply via email to