bobbai00 commented on code in PR #9278:
URL: https://github.com/apache/texera/pull/9278#discussion_r4500466032


##########
frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.ts:
##########
@@ -173,6 +173,80 @@ export class ContextMenuComponent {
     });
   }
 
+  /** A comment box is added to exactly one selected operator, with nothing 
else selected. */
+  public canAddCommentBoxToOperator(): boolean {
+    return (
+      this.canModify &&
+      this.highlightedOperatorIds.length === 1 &&
+      this.highlightedCommentBoxIds.length === 0 &&
+      !this.hasHighlightedLinks()
+    );
+  }
+
+  /** Adds a comment box beside the selected operator, anchored to it. */
+  public onAddCommentBoxToOperator(): void {
+    if (!this.canAddCommentBoxToOperator()) {
+      return;
+    }
+    
this.workflowActionService.addCommentBoxToOperator(this.highlightedOperatorIds[0]);
+  }
+
+  /** Anchoring takes the selected comment boxes and exactly one selected 
operator to anchor them to. */
+  public canAnchorCommentBoxes(): boolean {
+    return (
+      this.canModify &&
+      this.highlightedOperatorIds.length === 1 &&
+      this.highlightedCommentBoxIds.length > 0 &&
+      !this.hasHighlightedLinks()
+    );
+  }
+
+  /** Anchors every selected comment box to the selected operator. */
+  public onAnchorCommentBoxes(): void {

Review Comment:
   **Advisory:**
   
   This anchors a box at any distance, but `anchorCommentBoxOnDrop` 
(`workflow-action.service.ts:510`) detaches any anchored box dropped more than 
160px from its operator. A box anchored here from 300px therefore loses its 
anchor on its next drag, even one toward the operator, despite the "small nudge 
changes nothing" doc at `:507`. Is that intended? I'd offer this item only for 
boxes within `COMMENT_BOX_DETACH_DISTANCE`.



##########
frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.html:
##########
@@ -155,6 +155,37 @@
     >delete
   </li>
 
+  <li
+    nz-menu-item
+    *ngIf="canAddCommentBoxToOperator()"
+    (click)="onAddCommentBoxToOperator()">
+    <span
+      nz-icon
+      nzType="message"
+      nzTheme="outline"></span
+    >add comment
+  </li>
+  <li
+    nz-menu-item
+    *ngIf="canAnchorCommentBoxes()"
+    (click)="onAnchorCommentBoxes()">
+    <span
+      nz-icon
+      nzType="pushpin"
+      nzTheme="outline"></span
+    >anchor to operator

Review Comment:
   **Advisory:**
   
   The description's "How" table and testing list mention only "add comment", 
but the menu also gets "anchor to operator" and "detach from operator" here. 
The `calculateTopLeftOperatorPosition` change 
(`workflow-action.service.ts:627`), which stops an empty workflow from leaving 
joint-command listening switched off, isn't mentioned either. A line for each 
would tell reviewers to check them.



##########
frontend/src/app/workspace/service/workflow-graph/model/joint-graph-wrapper.ts:
##########
@@ -586,9 +586,44 @@ export class JointGraphWrapper {
     return this.zoomRatio;
   }
 
-  public autoLayoutJoint(): void {
+  /**
+   * Lays out the graph left to right with dagre.
+   *
+   * Comment boxes anchored to an operator are not laid out on their own: the 
operator is laid out as
+   * the bounding box of itself and its anchored comment boxes, so that 
nothing is placed on top of
+   * them, and the comment boxes are then put back at their offsets from the 
operator.
+   *
+   * @param anchoredCommentBoxIDs the IDs of the comment boxes anchored to 
each operator, by operator ID
+   */
+  public autoLayoutJoint(anchoredCommentBoxIDs: ReadonlyMap<string, readonly 
string[]> = new Map()): void {
+    const getElement = (id: string) => this.jointGraph.getCell(id) as 
joint.dia.Element;
+    const anchored = new 
Set(Array.from(anchoredCommentBoxIDs.values()).flat());
+    // For each operator with anchored comment boxes: the bounding box of the 
group, and the
+    // operator's and each comment box's offset within it, so the group is 
laid out as one node.

Review Comment:
   **Polish:**
   
   `commentOffsets` are measured from the operator (line 615), not from the 
group's bounding box.
   ```suggestion
       // For each operator with anchored comment boxes: the bounding box of 
the group, the operator's
       // offset within it, and each comment box's offset from the operator, so 
the group is laid out as one node.
   ```



##########
frontend/src/app/workspace/service/workflow-graph/model/shared-model-change-handler.ts:
##########
@@ -232,12 +233,14 @@ export class SharedModelChangeHandler {
 
   /**
    * Syncs element positions. Will temporarily block local updates.
+   * An "add" counts too when the element is already on the canvas: a comment 
box enters the
+   * position map only when it first moves, so its first move arrives as an 
add.
    * @private
    */
   private handleElementPositionChange(): void {
     this.texeraGraph.sharedModel.elementPositionMap?.observe((event: 
Y.YMapEvent<Point>) => {
       event.changes.keys.forEach((change, key) => {
-        if (change.action === "update") {
+        if (change.action === "update" || (change.action === "add" && 
this.jointGraph.getCell(key) !== undefined)) {

Review Comment:
   **Must fix:**
   
   Undoing an operator drag leaves its anchored comment boxes where the drag 
put them. Comment boxes get no `elementPositionMap` key when added or loaded 
(`workflow-action.service.ts:442`), while `addOperator` adds one (`:329`). So 
the operator drag (`:1372`) is the box's first move, and its undo is a 
`delete`, which this observer ignores. The box stays put while its saved 
`commentBoxPosition` reverts. To reproduce: open a workflow with an anchored 
comment, drag the operator, press Ctrl+Z. Fix: on `delete` for a comment box 
still on the canvas, move it to its `commentBoxPosition`, and add a spec that 
undoes such a drag.



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