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-8848-3ba45ee5a5f641388d1a9eda90afa26a62d70d30
in repository https://gitbox.apache.org/repos/asf/texera.git

commit e14f9acf7f6fd023c1afb8cd052a4af6ff9db271
Author: yangzhang75 <[email protected]>
AuthorDate: Thu Oct 22 22:05:49 2026 +0000

    fix(frontend): hold the Python UDF parameter table's Name and Type cells 
locked when the panel enables its form group (#8848)
    
    ### What changes were proposed in this PR?
    
    Closes #8847. The Python UDF operator's "UI parameters" table (#5043)
    infers each parameter's name and type from the `self.UiParameter(...)`
    declarations in the operator's code, so the widget disables those two
    columns' controls as it builds each row: a name typed into the table
    does not reach the code, and the parameter's value then never reaches it
    either (checked on main: the table's name changes, the code's does not).
    
    The lock does not survive on the operator property panel.
    `setInteractivity(true)` enables the whole form group -- one task after
    every render, and again whenever the workflow becomes modifiable, for
    instance when a run ends -- and formly mirrors a control's state back
    into `props.disabled`, so the one-time disable is simply undone. Which
    state a given panel opening shows depends on which of the two ran last:
    measured on main, the cells were editable on 4 of 5 openings, and always
    after a run. The Form View, which never enables a group wholesale, has
    always shown them locked, so the two views disagreed as well.
    
    The widget now holds its own lock. On each cell it locks it registers
    Angular's disabled-change hook of the control
    (`registerOnDisabledChange`, the same hook formly's mirror and the
    input's value accessor use): when a host enables the control, the hook
    disables it again in the microtask after that enable, and announces the
    status change as the enable did. Both details matter and were found on a
    running instance:
    
    - deferred to the microtask, because the input's value accessor is one
    more hook on the same control, registered after this one when the cell
    renders; disabling from inside the enable's own round of hooks left the
    accessor having been told "enabled" last, so the box was editable over a
    locked control;
    - announced rather than silent (`disable()`, not `disable({emitEvent:
    false})`), because ng-zorro's `nz-input` paints its `disabled` attribute
    from the control's status changes; a silent disable left it painting the
    box editable again at the next change detection.
    
    A cell the widget configures editable -- the Value column, or any cell
    once reconfigured -- is released from the hold, so whether it is
    editable stays the host's call: a read-only panel still locks
    everything, and a host that disables the whole field still reaches the
    Value cell. The frame is untouched: two other approaches were tried
    first and dropped, re-disabling from the frame after `enable()`
    (formly's mirror has already set `props.disabled` to false by then) and
    a formly expression on `props.disabled` (formly re-evaluates expressions
    on model changes only, and registers them at populate, so `enable()`
    never triggers one).
    
    ### Any related issues, documentation, discussions?
    
    Closes #8847. Split out of #8846 (the same table under the Form View's
    renames and hides), which is based on main and does not touch this; the
    two are independent and can land in either order. The table's fixed
    250px columns clip Name and Type at the panel's default 260px width,
    which is why the cells have to be brought into view to see any of this;
    that is a separate layout bug, filed separately.
    
    ### How was this PR tested?
    
    Unit tests (vitest). The widget's spec: a locked cell's control is held
    locked when a host enables it, in the microtask after the enable and
    announcing the status change, while the Value cell is left to the host;
    a cell configured editable again is released from the hold; a cell the
    host disables again before the microtask is left alone; a control that
    is not a `FormControl` gets no hook, and a control is hooked once
    however often it is configured. A second spec stands the table up under
    real formly (`FormlyModule.forRoot`, a form, the builder row template
    formly-jsonschema produces, `nz-input` cells as in the app): the rows
    build with Name and Type locked and Value editable; a wholesale
    `form.enable()`, as the panel does, leaves Name and Type locked, read
    from the inputs' `disabled` state and not only from the controls'; a
    read-only `form.disable()` locks everything and a later `enable()` gives
    only the Value cell back. Each guard was deletion-checked and turned a
    named test red. eslint, prettier and the production (AOT) build pass;
    the full frontend suite passes; every statement, function and branch
    this PR adds is covered.
    
    Checked on a local instance (a Python source feeding a Python UDF whose
    code declares two UI parameters), the panel widened so the columns are
    in view. On main the cells are editable on most openings (4 of 5) and
    after every run; with this PR they stayed locked on every opening and
    through a forced `setInteractivity(true)` followed by real
    change-detection passes, read from the DOM as well as from the controls.
    The Value cell follows the host in both.
    
    #### Video
    
    **Before**
    
    
    
https://github.com/user-attachments/assets/53ac4826-b5ec-4852-a5c9-22685306839d
    
    
    
    **After**
    
    
    
https://github.com/user-attachments/assets/9bcc2a52-fdb3-4764-99cb-63a31a18fa44
    
    
    ### Was this PR authored or co-authored using generative AI tooling?
    
    Yes. Generated-by: Claude Code (Anthropic). Co-authored with Claude,
    reviewed line by line by the author before submission.
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
---
 .../ui-udf-parameters.component.formly.spec.ts     | 161 +++++++++++++++++++++
 .../ui-udf-parameters.component.spec.ts            |  84 ++++++++++-
 .../ui-udf-parameters.component.ts                 |  48 +++++-
 3 files changed, 290 insertions(+), 3 deletions(-)

diff --git 
a/frontend/src/app/workspace/component/ui-udf-parameters/ui-udf-parameters.component.formly.spec.ts
 
b/frontend/src/app/workspace/component/ui-udf-parameters/ui-udf-parameters.component.formly.spec.ts
new file mode 100644
index 0000000000..a3d7c75314
--- /dev/null
+++ 
b/frontend/src/app/workspace/component/ui-udf-parameters/ui-udf-parameters.component.formly.spec.ts
@@ -0,0 +1,161 @@
+/**
+ * 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 } from "@angular/core";
+import { TestBed } from "@angular/core/testing";
+import { ReactiveFormsModule, UntypedFormGroup } from "@angular/forms";
+import { FieldType, FieldTypeConfig, FormlyFieldConfig, FormlyForm, 
FormlyModule } from "@ngx-formly/core";
+import { NzInputModule } from "ng-zorro-antd/input";
+import { NotificationService } from 
"../../../common/service/notification/notification.service";
+import { UiUdfParametersSyncService } from 
"../../service/code-editor/ui-udf-parameters-sync.service";
+import { WorkflowActionService } from 
"../../service/workflow-graph/model/workflow-action.service";
+import { UiUdfParametersComponent } from "./ui-udf-parameters.component";
+
+/**
+ * The cell formly builds a string column into: an nz-input bound to the 
control, as in the app.
+ * nz-input paints its disabled attribute from the control's status changes, 
so a lock the control
+ * carries silently is not one the reader sees -- which is why these tests 
read the inputs.
+ */
+@Component({
+  template: '<input nz-input [formControl]="formControl" />',
+  imports: [ReactiveFormsModule, NzInputModule],
+})
+class InputCellType extends FieldType<FieldTypeConfig> {}
+
+/** A form holding one parameter table, with the builder row template 
formly-jsonschema produces. */
+@Component({
+  template:
+    '<form [formGroup]="form"><formly-form [form]="form" [model]="model" 
[fields]="fields"></formly-form></form>',
+  imports: [ReactiveFormsModule, FormlyForm],
+})
+class HostComponent {
+  form = new UntypedFormGroup({});
+  model = {
+    uiParameters: [
+      { value: "0.5", attribute: { attributeName: "threshold", attributeType: 
"double" } },
+      { value: "high", attribute: { attributeName: "label", attributeType: 
"string" } },
+    ],
+  };
+  fields: FormlyFieldConfig[] = [
+    {
+      key: "uiParameters",
+      type: "ui-udf-parameters",
+      fieldArray: () => ({
+        fieldGroup: [
+          { key: "value", type: "plain" },
+          {
+            key: "attribute",
+            fieldGroup: [
+              { key: "attributeName", type: "plain" },
+              { key: "attributeType", type: "plain" },
+            ],
+          },
+        ],
+      }),
+    },
+  ];
+}
+
+/**
+ * Real formly, no mocks of it: the operator property panel enables and 
disables its whole form
+ * group (setInteractivity), and formly mirrors a control's state into 
props.disabled, so the
+ * widget's lock on the Name and Type columns has to survive a wholesale 
enable(). The widget's own
+ * spec drives populate on hand-made rows; this one proves the lock under 
formly's own build.
+ */
+describe("UiUdfParametersComponent under real formly", () => {
+  beforeEach(async () => {
+    await TestBed.configureTestingModule({
+      imports: [
+        HostComponent,
+        FormlyModule.forRoot({
+          types: [
+            { name: "ui-udf-parameters", component: UiUdfParametersComponent },
+            { name: "plain", component: InputCellType },
+          ],
+        }),
+      ],
+      providers: [
+        {
+          provide: WorkflowActionService,
+          useValue: {
+            checkWorkflowModificationEnabled: () => true,
+            getJointGraphWrapper: () => ({ getCurrentHighlightedOperatorIDs: 
() => ["op-1"] }),
+          },
+        },
+        { provide: UiUdfParametersSyncService, useValue: { addParameter: 
vi.fn() } },
+        { provide: NotificationService, useValue: { error: vi.fn() } },
+      ],
+    }).compileComponents();
+  });
+
+  function render() {
+    const fixture = TestBed.createComponent(HostComponent);
+    fixture.detectChanges();
+    const form = fixture.componentInstance.form;
+    const cell = (row: number, path: string) => 
form.get(`uiParameters.${row}.${path}`)!;
+    const locks = () => [
+      cell(0, "value").disabled,
+      cell(0, "attribute.attributeName").disabled,
+      cell(0, "attribute.attributeType").disabled,
+      cell(1, "attribute.attributeName").disabled,
+    ];
+    return { fixture, form, locks };
+  }
+
+  it("builds the rows with the Name and Type cells locked and the Value cell 
editable", () => {
+    const { locks } = render();
+
+    expect(locks()).toEqual([false, true, true, true]);
+  });
+
+  // The lock goes back on in the microtask after the host's enable() (see 
keepLocked), so the
+  // assertions wait one; what the reader sees is read from the inputs, not 
only the controls.
+  const settled = async (fixture: { detectChanges(): void }) => {
+    await Promise.resolve();
+    fixture.detectChanges();
+  };
+  const inputsDisabled = (fixture: { nativeElement: HTMLElement }) =>
+    
Array.from(fixture.nativeElement.querySelectorAll<HTMLInputElement>(".ui-udf-parameter-row:not(.header)
 input"))
+      .slice(0, 3)
+      .map(input => input.disabled);
+
+  it("keeps the Name and Type cells locked when the host enables the whole 
form group, as the panel does", async () => {
+    const { fixture, form, locks } = render();
+
+    form.enable();
+    await settled(fixture);
+
+    expect(locks()).toEqual([false, true, true, true]);
+    expect(inputsDisabled(fixture)).toEqual([false, true, true]);
+  });
+
+  it("locks everything for a read-only host and gives only the Value cell back 
on enable", async () => {
+    const { fixture, form, locks } = render();
+
+    form.disable();
+    await settled(fixture);
+    expect(locks()).toEqual([true, true, true, true]);
+    expect(inputsDisabled(fixture)).toEqual([true, true, true]);
+
+    form.enable();
+    await settled(fixture);
+    expect(locks()).toEqual([false, true, true, true]);
+    expect(inputsDisabled(fixture)).toEqual([false, true, true]);
+  });
+});
diff --git 
a/frontend/src/app/workspace/component/ui-udf-parameters/ui-udf-parameters.component.spec.ts
 
b/frontend/src/app/workspace/component/ui-udf-parameters/ui-udf-parameters.component.spec.ts
index cc2b8beaa0..7f79d14a50 100644
--- 
a/frontend/src/app/workspace/component/ui-udf-parameters/ui-udf-parameters.component.spec.ts
+++ 
b/frontend/src/app/workspace/component/ui-udf-parameters/ui-udf-parameters.component.spec.ts
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-import { FormControl, UntypedFormArray } from "@angular/forms";
+import { FormControl, FormGroup, UntypedFormArray } from "@angular/forms";
 import { ComponentFixture, TestBed } from "@angular/core/testing";
 import { By } from "@angular/platform-browser";
 import { FormlyFieldConfig } from "@ngx-formly/core";
@@ -130,6 +130,88 @@ describe("UiUdfParametersComponent", () => {
     });
   });
 
+  // The operator property panel enables its whole form group when it turns 
interactive, and formly
+  // mirrors a control's state into props.disabled, so a one-time disable of 
the Name and Type cells
+  // did not survive there (the Form View, which never enables a group 
wholesale, showed them
+  // locked). A locked cell's control is held through Angular's 
disabled-change hook.
+  it("holds a locked cell locked when the host enables its control, and leaves 
the Value cell to the host", async () => {
+    const valueControl = new FormControl("42");
+    const nameControl = new FormControl("threshold");
+    const typeControl = new FormControl("double");
+    const rowField = rowConfig([
+      { key: "value", formControl: valueControl },
+      { key: "attributeName", formControl: nameControl },
+      { key: "attributeType", formControl: typeControl },
+    ]);
+    component.onPopulate({ model: [{}], fieldGroup: [rowField] } as 
FormlyFieldConfig);
+    expect(nameControl.disabled).toBe(true);
+    const nameStatus = vitest.fn();
+    nameControl.statusChanges.subscribe(nameStatus);
+
+    nameControl.enable();
+    typeControl.enable();
+    valueControl.disable();
+    valueControl.enable();
+    // The lock goes back on in the microtask after the host's enable() has 
told every hook,
+    // the input's value accessor included; see keepLocked.
+    expect(nameControl.enabled).toBe(true);
+    await Promise.resolve();
+
+    expect(nameControl.disabled).toBe(true);
+    expect(typeControl.disabled).toBe(true);
+    expect(valueControl.enabled).toBe(true);
+    // Announced like the enable() was: the cell's nz-input paints its 
disabled attribute from it.
+    expect(nameStatus.mock.calls.map(call => call[0])).toEqual(["VALID", 
"DISABLED"]);
+  });
+
+  it("locks a cell whose control is not a FormControl without a hold hook, and 
does not register twice", () => {
+    const group = new FormGroup({ inner: new FormControl("x") });
+    (component as any).applyDisabledState({ formControl: group }, true);
+    expect(group.disabled).toBe(true);
+
+    const nameControl = new FormControl("threshold");
+    const register = vitest.spyOn(nameControl, "registerOnDisabledChange");
+    (component as any).applyDisabledState({ formControl: nameControl }, true);
+    (component as any).applyDisabledState({ formControl: nameControl }, true);
+    expect(register).toHaveBeenCalledTimes(1);
+  });
+
+  it("releases a cell from the hold once it is configured editable again", 
async () => {
+    const nameControl = new FormControl("threshold");
+    const rowField = rowConfig([
+      { key: "value", formControl: new FormControl("42") },
+      { key: "attributeName", formControl: nameControl },
+      { key: "attributeType", formControl: new FormControl("double") },
+    ]);
+    component.onPopulate({ model: [{}], fieldGroup: [rowField] } as 
FormlyFieldConfig);
+    expect(nameControl.disabled).toBe(true);
+
+    (component as any).applyDisabledState(component.getColumnField(rowField, 
component.fieldColumns[1]), false);
+    nameControl.disable();
+    nameControl.enable();
+    await Promise.resolve();
+
+    expect(nameControl.enabled).toBe(true);
+  });
+
+  it("leaves a locked cell alone when the host has disabled it again before 
the microtask", async () => {
+    const nameControl = new FormControl("threshold");
+    const rowField = rowConfig([
+      { key: "value", formControl: new FormControl("42") },
+      { key: "attributeName", formControl: nameControl },
+      { key: "attributeType", formControl: new FormControl("double") },
+    ]);
+    component.onPopulate({ model: [{}], fieldGroup: [rowField] } as 
FormlyFieldConfig);
+    const disable = vitest.spyOn(nameControl, "disable");
+
+    nameControl.enable();
+    nameControl.disable({ emitEvent: false });
+    await Promise.resolve();
+
+    expect(disable).toHaveBeenCalledTimes(1);
+    expect(nameControl.disabled).toBe(true);
+  });
+
   it("should edit a row that names a resource with that resource's browser, 
and leave others alone", () => {
     const columns = () =>
       rowConfig([
diff --git 
a/frontend/src/app/workspace/component/ui-udf-parameters/ui-udf-parameters.component.ts
 
b/frontend/src/app/workspace/component/ui-udf-parameters/ui-udf-parameters.component.ts
index 15afa66ccd..9f9998a4f5 100644
--- 
a/frontend/src/app/workspace/component/ui-udf-parameters/ui-udf-parameters.component.ts
+++ 
b/frontend/src/app/workspace/component/ui-udf-parameters/ui-udf-parameters.component.ts
@@ -18,6 +18,7 @@
  */
 import { Component } from "@angular/core";
 import { NgFor, NgIf } from "@angular/common";
+import { FormControl, type AbstractControl } from "@angular/forms";
 import { FieldArrayType, FormlyFieldConfig, FormlyModule } from 
"@ngx-formly/core";
 import { NzButtonComponent } from "ng-zorro-antd/button";
 import { NzWaveDirective } from "ng-zorro-antd/core/wave";
@@ -61,6 +62,9 @@ export class UiUdfParametersComponent extends 
FieldArrayType<FormlyFieldConfig>
   private readonly disabledStateConfigured = new WeakMap<FormlyFieldConfig, 
boolean>();
   // The resource each row's value editor was configured for.
   private readonly rowResources = new WeakMap<FormlyFieldConfig, string>();
+  // The controls of the cells currently locked, and the controls that carry 
the hold hook (see keepLocked).
+  private readonly lockedControls = new WeakSet<AbstractControl>();
+  private readonly hookedControls = new WeakSet<AbstractControl>();
 
   readonly fieldColumns: UiUdfParameterColumn[] = [
     VALUE_COLUMN,
@@ -207,8 +211,48 @@ export class UiUdfParametersComponent extends 
FieldArrayType<FormlyFieldConfig>
   }
 
   private applyDisabledState(field: FormlyFieldConfig, disabled: boolean): 
void {
-    if (disabled) field.formControl?.disable({ emitEvent: false });
-    else field.formControl?.enable({ emitEvent: false });
+    const control = field.formControl;
+    if (!control) return;
+    if (disabled) {
+      control.disable({ emitEvent: false });
+      this.keepLocked(control);
+    } else {
+      this.lockedControls.delete(control);
+      control.enable({ emitEvent: false });
+    }
+  }
+
+  /**
+   * Hold a locked cell locked under any host. The operator property panel 
enables its whole form
+   * group when it turns interactive (and again after a run), and formly 
mirrors a control's state
+   * back into props.disabled, so a one-time disable did not survive there: 
the Name and Type cells
+   * came back editable on the canvas, while the Form View, which never 
enables a group wholesale,
+   * showed them locked. Angular tells a control's disabled-change hooks about 
every enable() and
+   * disable(), whoever calls them (formly's mirror is such a hook), so the 
one registered here
+   * disables the control again once a host has enabled it, and formly's 
mirror then records the
+   * lock in props.disabled as well. The disabling waits for the microtask 
after the enable(): the
+   * input's own value accessor is one more of these hooks, registered after 
this one when the cell
+   * renders, and had the control been disabled from inside the enable()'s 
round of hooks, the
+   * accessor would still have been told "enabled" last and the box would have 
shown editable over a
+   * locked control. The disabling also announces itself (statusChanges), as 
the enable() did: the
+   * cell's nz-input paints its disabled attribute from the status it was last 
told, and told only
+   * "enabled" it would paint the box editable again at the next change 
detection. Registered once
+   * per control, for good; a cell configured editable again leaves 
lockedControls
+   * (applyDisabledState) and the hook lets it be.
+   */
+  private keepLocked(control: AbstractControl): void {
+    this.lockedControls.add(control);
+    // The hook is a FormControl's (a cell's control always is one; a group 
has none to register).
+    if (!(control instanceof FormControl) || this.hookedControls.has(control)) 
return;
+    this.hookedControls.add(control);
+    control.registerOnDisabledChange((isDisabled: boolean) => {
+      if (isDisabled) return;
+      queueMicrotask(() => {
+        if (control.enabled && this.lockedControls.has(control)) {
+          control.disable();
+        }
+      });
+    });
   }
 
   trackByParameterName = (index: number, parameter: any): string | number => {

Reply via email to