This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-8968-27f37b81bf87358c3f8688d3dfbf5b4d92ec40b8
in repository https://gitbox.apache.org/repos/asf/texera.git

commit 93438d13fb8c34052ce3552380f65043e1a24a38
Author: Eugene Gu <[email protected]>
AuthorDate: Tue Oct 27 03:42:23 2026 +0000

    fix(frontend): block clicks on disabled context menu items (#8968)
    
    ### What changes were proposed in this PR?
    
    **Root cause.** Two items in the operator context menu grey themselves
    out with `nzDisabled` but keep a `(click)` binding on the same `<li
    nz-menu-item>`. In ng-zorro-antd 21.3.2, `nzDisabled` only adds the
    disabled class and makes the component's own host click listener call
    `preventDefault()` and `stopPropagation()`; the template `(click)` is a
    sibling listener on the same element and still runs (`pointer-events:
    none` is applied only to a nested `<a>`, which these items do not have).
    
    - "execute to this operator": `[nzDisabled]="!canExecuteOperator()"`
    with `(click)="operatorMenuService.executeUpToOperator()"`. Clicked
    while greyed out mid-run, it sends a new execution request; the backend
    shuts down the in-flight execution and clears its results, and that
    execution's row stays RUNNING.
    - "reuse result": hardcoded `[nzDisabled]="true"` with a `(click)` that
    still ran.
    
    ```
    Before:  greyed "execute to this operator" clicked mid-run -> new 
execution; the running one is shut down, its row left RUNNING
    After:   greyed "execute to this operator" clicked -> 
onExecuteUpToOperator() returns early; nothing is sent
    ```
    
    | Before: greyed item during a run (clicking it started eid 10 and shut
    down eid 9) | After: greyed item clicked, same run continues |
    | --- | --- |
    | <img width="1568" height="287"
    alt="01-greyed-execute-to-operator-during-run"
    
src="https://github.com/user-attachments/assets/aa0193fb-3df8-4fc4-b6e7-588ac8b62c8c";
    /> | <img width="1312" height="773"
    alt="03-after-fix-greyed-item-clicked-same-run-continues"
    
src="https://github.com/user-attachments/assets/660049f0-8925-40a8-b83c-50d314a96ea2";
    /> |
    
    **Changes.**
    
    1. `context-menu.component.ts`: new `onExecuteUpToOperator()` that
    returns early unless `canExecuteOperator()` holds, in the style of
    `onCopy`/`onPaste`/`onCut`/`onDelete`; the template binds to it. Same
    shape as `onClickComputingUnitRow` in
    `computing-unit-selection.component.html`.
    2. `context-menu.component.html`: the `(click)` on the
    hardcoded-disabled "reuse result" item is removed. "remove reusing
    result" keeps its binding.
    3. `context-menu.component.spec.ts`: `clickItem` dispatches a real DOM
    `MouseEvent` instead of `triggerEventHandler("click", null)`, so the
    nz-menu-item host listener and the template binding both run as in the
    browser; an `isItemDisabled(label)` helper reads `nzDisabled` from the
    rendered `NzMenuItemComponent`.
    
    ### Any related issues, documentation, discussions?
    
    Closes #8966
    
    ### How was this PR tested?
    
    New tests in `context-menu.component.spec.ts`: "execute to this
    operator" does nothing while greyed out (operator invalid, workflow not
    modifiable, operator disabled), is not offered with more than one
    operator highlighted, and checks the state at click time rather than at
    the last render; "reuse result" renders greyed out and does nothing when
    clicked. The existing enabled-path test still passes through the real
    click.
    
    ```
    cd frontend
    NODE_OPTIONS="--no-experimental-webstorage" npx ng test --watch=false 
--include 
src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.spec.ts
    # 50 passed (50)
    NODE_OPTIONS="--no-experimental-webstorage" npx ng test --watch=false
    # 235 files, 6617 passed | 1 skipped
    npx tsc --noEmit -p tsconfig.json; npx eslint <changed files>; npx prettier 
--check <changed files>   # clean
    ```
    
    Mutation check: removing the guard in `onExecuteUpToOperator()` fails
    the three "does nothing" tests and the click-time test; restoring the
    `(click)` on "reuse result" fails its test. (`NODE_OPTIONS` is only
    needed locally on Node 25; CI runs Node 24.)
    
    Manual check in Chrome on the local stack: Text Input -> Python UDF
    yielding once per second -> Python Lambda; Run; right-click the Python
    Lambda while running and click the greyed "execute to this operator". On
    main a second execution started and the first was shut down; on this
    branch the same execution keeps running and no second
    `workflow_executions` row appears.
    
    ### Was this PR authored or co-authored using generative AI tooling?
    
    Yes. Generated-by: Claude Code (claude-fable-5-1). Co-authored with
    Claude; the author reviewed the change before submission.
    
    Co-authored-by: Kunwoo (Chris) <[email protected]>
---
 .../context-menu/context-menu.component.html       |   5 +-
 .../context-menu/context-menu.component.spec.ts    | 119 +++++++++++++++++++--
 .../context-menu/context-menu.component.ts         |   9 ++
 3 files changed, 121 insertions(+), 12 deletions(-)

diff --git 
a/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.html
 
b/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.html
index 7d423f58d5..db7f5c746a 100644
--- 
a/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.html
+++ 
b/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.html
@@ -109,8 +109,7 @@
     nz-menu-item
     [nzDisabled]="true"
     *ngIf="(operatorMenuService.isMarkForReuse && 
operatorMenuService.isReuseResultClickable) &&
-  !hasHighlightedLinks()"
-    (click)="operatorMenuService.reuseResultHighlightedOperator()">
+  !hasHighlightedLinks()">
     <span
       nz-icon
       nzType="database"
@@ -162,7 +161,7 @@
   highlightedCommentBoxIds.length === 0 &&
   !hasHighlightedLinks()"
     [nzDisabled]="!canExecuteOperator()"
-    (click)="operatorMenuService.executeUpToOperator()">
+    (click)="onExecuteUpToOperator()">
     <span
       nz-icon
       nzType="play-circle"
diff --git 
a/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.spec.ts
 
b/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.spec.ts
index 19d8a83f35..94f677f60a 100644
--- 
a/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.spec.ts
+++ 
b/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.spec.ts
@@ -32,6 +32,7 @@ import { BehaviorSubject, of } from "rxjs";
 import { ReactiveFormsModule } from "@angular/forms";
 import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
 import { NzDropDownModule } from "ng-zorro-antd/dropdown";
+import { NzMenuItemComponent } from "ng-zorro-antd/menu";
 import { ValidationWorkflowService } from 
"src/app/workspace/service/validation/validation-workflow.service";
 import { WorkflowCompilingService } from 
"src/app/workspace/service/compile-workflow/workflow-compiling.service";
 import { NzModalModule, NzModalService } from "ng-zorro-antd/modal";
@@ -476,7 +477,10 @@ describe("ContextMenuComponent", () => {
   describe("menu item click bindings", () => {
     const norm = (s: string | null) => (s ?? "").replace(/\s+/g, " 
").trim().toLowerCase();
 
-    /** Click the rendered <li nz-menu-item> whose text matches `label` 
exactly. */
+    /**
+     * Click the rendered <li nz-menu-item> whose text matches `label` 
exactly, with a real DOM
+     * click so that both the nz-menu-item host listener and the template 
(click) run as in the browser.
+     */
     function clickItem(label: string): void {
       const items = fixture.debugElement.queryAll(By.css("li[nz-menu-item]"));
       const item = items.find(li => norm(li.nativeElement.textContent) === 
norm(label));
@@ -485,7 +489,18 @@ describe("ContextMenuComponent", () => {
           `menu item "${label}" not rendered; present: [${items.map(i => 
norm(i.nativeElement.textContent)).join(" | ")}]`
         );
       }
-      item.triggerEventHandler("click", null);
+      item.nativeElement.dispatchEvent(new MouseEvent("click", { bubbles: 
true, cancelable: true }));
+    }
+
+    /** Whether the rendered <li nz-menu-item> with text `label` is greyed out 
through nzDisabled. */
+    function isItemDisabled(label: string): boolean {
+      const item = fixture.debugElement
+        .queryAll(By.css("li[nz-menu-item]"))
+        .find(li => norm(li.nativeElement.textContent) === norm(label));
+      if (!item) {
+        throw new Error(`menu item "${label}" not rendered`);
+      }
+      return item.injector.get(NzMenuItemComponent).nzDisabled;
     }
 
     it("copy invokes onCopy", () => {
@@ -561,17 +576,16 @@ describe("ContextMenuComponent", () => {
       
expect(operatorMenuService.viewResultHighlightedOperators).toHaveBeenCalledTimes(1);
     });
 
-    it("renders the reuse result item (disabled) when marked for reuse", () => 
{
-      // This entry is hardcoded `nzDisabled`, so it can't be clicked; assert 
it renders.
-      // Its (click) handler is the same as "remove reusing result", covered 
by the next test.
+    it("reuse result renders greyed out and does nothing when clicked", () => {
       operatorMenuService.isMarkForReuse = true;
       operatorMenuService.isReuseResultClickable = true;
       fixture.detectChanges();
 
-      const rendered = fixture.debugElement
-        .queryAll(By.css("li[nz-menu-item]"))
-        .some(li => norm(li.nativeElement.textContent) === "reuse result");
-      expect(rendered).toBe(true);
+      expect(isItemDisabled("reuse result")).toBe(true);
+
+      clickItem("reuse result");
+
+      
expect(operatorMenuService.reuseResultHighlightedOperator).not.toHaveBeenCalled();
     });
 
     it("remove reusing result invokes 
operatorMenuService.reuseResultHighlightedOperator", () => {
@@ -681,6 +695,93 @@ describe("ContextMenuComponent", () => {
       expect(operatorMenuService.executeUpToOperator).toHaveBeenCalledTimes(1);
     });
 
+    it("execute to this operator does nothing while the item is greyed out", 
() => {
+      highlightedOperatorsSubject.next(["op1"]);
+      component.isWorkflowModifiable = true;
+      
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(["op1"]);
+      validationWorkflowService.validateOperator.mockReturnValue({ isValid: 
false, messages: {} });
+      fixture.detectChanges();
+      expect(component.canExecuteOperator()).toBe(false);
+
+      expect(isItemDisabled("execute to this operator")).toBe(true);
+
+      clickItem("execute to this operator");
+
+      expect(operatorMenuService.executeUpToOperator).not.toHaveBeenCalled();
+    });
+
+    it("execute to this operator does nothing while the workflow is not 
modifiable", () => {
+      highlightedOperatorsSubject.next(["op1"]);
+      component.isWorkflowModifiable = false;
+      
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(["op1"]);
+      validationWorkflowService.validateOperator.mockReturnValue({ isValid: 
true });
+      (workflowActionService.getTexeraGraph() as unknown as 
Mocked<WorkflowGraph>).isOperatorDisabled.mockReturnValue(
+        false
+      );
+      fixture.detectChanges();
+      expect(component.canExecuteOperator()).toBe(false);
+
+      expect(isItemDisabled("execute to this operator")).toBe(true);
+
+      clickItem("execute to this operator");
+
+      expect(operatorMenuService.executeUpToOperator).not.toHaveBeenCalled();
+    });
+
+    it("execute to this operator does nothing while the operator is disabled", 
() => {
+      highlightedOperatorsSubject.next(["op1"]);
+      component.isWorkflowModifiable = true;
+      
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(["op1"]);
+      validationWorkflowService.validateOperator.mockReturnValue({ isValid: 
true });
+      (workflowActionService.getTexeraGraph() as unknown as 
Mocked<WorkflowGraph>).isOperatorDisabled.mockReturnValue(
+        true
+      );
+      fixture.detectChanges();
+      expect(component.canExecuteOperator()).toBe(false);
+
+      expect(isItemDisabled("execute to this operator")).toBe(true);
+
+      clickItem("execute to this operator");
+
+      expect(operatorMenuService.executeUpToOperator).not.toHaveBeenCalled();
+    });
+
+    it("execute to this operator is not offered while more than one operator 
is highlighted", () => {
+      highlightedOperatorsSubject.next(["op1", "op2"]);
+      component.isWorkflowModifiable = true;
+      
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(["op1", 
"op2"]);
+      fixture.detectChanges();
+      expect(component.canExecuteOperator()).toBe(false);
+
+      const rendered = fixture.debugElement
+        .queryAll(By.css("li[nz-menu-item]"))
+        .some(li => norm(li.nativeElement.textContent) === "execute to this 
operator");
+      expect(rendered).toBe(false);
+    });
+
+    it("execute to this operator checks the state at click time, not at the 
last render", () => {
+      highlightedOperatorsSubject.next(["op1"]);
+      component.isWorkflowModifiable = true;
+      
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(["op1"]);
+      validationWorkflowService.validateOperator.mockReturnValue({ isValid: 
true });
+      (workflowActionService.getTexeraGraph() as unknown as 
Mocked<WorkflowGraph>).isOperatorDisabled.mockReturnValue(
+        false
+      );
+      fixture.detectChanges();
+      expect(isItemDisabled("execute to this operator")).toBe(false);
+
+      clickItem("execute to this operator");
+      expect(operatorMenuService.executeUpToOperator).toHaveBeenCalledTimes(1);
+
+      // The workflow locks without a change-detection pass, so the item still 
looks enabled.
+      component.isWorkflowModifiable = false;
+      expect(isItemDisabled("execute to this operator")).toBe(false);
+
+      clickItem("execute to this operator");
+
+      expect(operatorMenuService.executeUpToOperator).toHaveBeenCalledTimes(1);
+    });
+
     it("Export result invokes onClickExportHighlightedExecutionResult", () => {
       (
         workflowResultExportService as unknown as { 
hasResultToExportOnHighlightedOperators: boolean }
diff --git 
a/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.ts
 
b/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.ts
index f7a0888e00..6d645a533e 100644
--- 
a/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.ts
+++ 
b/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.ts
@@ -119,6 +119,15 @@ export class ContextMenuComponent {
     return 
this.workflowActionService.getJointGraphWrapper().getCurrentHighlightedLinkIDs().length
 > 0;
   }
 
+  /** Runs the workflow up to the highlighted operator when the menu item is 
enabled. */
+  public onExecuteUpToOperator(): void {
+    // nzDisabled only greys the item out; it does not stop the template 
(click).
+    if (!this.canExecuteOperator()) {
+      return;
+    }
+    this.operatorMenuService.executeUpToOperator();
+  }
+
   public onCopy(): void {
     this.operatorMenuService.saveHighlightedElements();
   }

Reply via email to