Skip to content

Commit 94aff48

Browse files
yangzhang75claude
andcommitted
fix(workflow-form): let ui-udf-parameters show the form's renames and hides, and add a parameter to the card's operator
The ui-udf-parameters widget hides formly's labels and draws fixed column headers (Value / Name / Type), so the author's per-sub-field overrides from the Form View changed nothing a reader saw: a renamed column kept its old name and a hidden one kept its header over an empty cell. On a Form View card the widget now decides which columns are in view from the first row's sub-fields (a hidden column, or one whose group is hidden, is left out, header and cells alike), read live, since the form's hide lands on a row after formly has built it; the header shows the author's name for the column, else the panel's fixed label. The Form View names the operator on every field it renders (props.operatorID, FIELD_OPERATOR_ID_PROP / fieldOperatorID), since nothing is highlighted on the form; the same mark tells a shared widget which host it is on. Add parameter uses it: it inserts a declaration into an operator's code, and it took that operator from the canvas highlight, so on the form it edited the wrong operator or failed. It now adds to the field's operator on a card, and to the highlighted one on the panel. The declared parameters then reach the operator: the panel's frame writes them only for the operator it shows while it acts as the editor, so the form writes them when the frame does not (a writer only, the operator still on the graph). A reader's value cells stay locked: the Form View marks a reader's field props.disabled, and the widget's own "the value is editable" used to re-enable the control after formly had disabled it. And the widget's own lock on the Name and Type cells (inferred from the code; a name typed there no longer matches a declaration) now holds under any host: the 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 did not survive on the canvas while the form showed the cells locked. The widget holds a locked cell through the control's disabled-change hook, which disables it again whenever a host enables it; a cell configured editable is released. Closes apache#8763 Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 2082021 commit 94aff48

10 files changed

Lines changed: 968 additions & 18 deletions
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { Component } from "@angular/core";
21+
import { TestBed } from "@angular/core/testing";
22+
import { ReactiveFormsModule, UntypedFormGroup } from "@angular/forms";
23+
import { FieldType, FieldTypeConfig, FormlyFieldConfig, FormlyForm, FormlyModule } from "@ngx-formly/core";
24+
import { NzInputModule } from "ng-zorro-antd/input";
25+
import { NotificationService } from "../../../common/service/notification/notification.service";
26+
import { UiUdfParametersSyncService } from "../../service/code-editor/ui-udf-parameters-sync.service";
27+
import { WorkflowActionService } from "../../service/workflow-graph/model/workflow-action.service";
28+
import { UiUdfParametersComponent } from "./ui-udf-parameters.component";
29+
30+
/** The cell formly builds a string column into: an nz-input bound to the control, as in the app. */
31+
@Component({
32+
template: '<input nz-input [formControl]="formControl" />',
33+
imports: [ReactiveFormsModule, NzInputModule],
34+
})
35+
class InputCellType extends FieldType<FieldTypeConfig> {}
36+
37+
/** A form holding one parameter table, with the builder row template formly-jsonschema produces. */
38+
@Component({
39+
template:
40+
'<form [formGroup]="form"><formly-form [form]="form" [model]="model" [fields]="fields"></formly-form></form>',
41+
imports: [ReactiveFormsModule, FormlyForm],
42+
})
43+
class HostComponent {
44+
form = new UntypedFormGroup({});
45+
model = {
46+
uiParameters: [
47+
{ value: "0.5", attribute: { attributeName: "threshold", attributeType: "double" } },
48+
{ value: "high", attribute: { attributeName: "label", attributeType: "string" } },
49+
],
50+
};
51+
fields: FormlyFieldConfig[] = [
52+
{
53+
key: "uiParameters",
54+
type: "ui-udf-parameters",
55+
fieldArray: () => ({
56+
fieldGroup: [
57+
{ key: "value", type: "plain" },
58+
{
59+
key: "attribute",
60+
fieldGroup: [
61+
{ key: "attributeName", type: "plain" },
62+
{ key: "attributeType", type: "plain" },
63+
],
64+
},
65+
],
66+
}),
67+
},
68+
];
69+
}
70+
71+
/**
72+
* Real formly, no mocks of it: the widget's own spec drives populate on hand-made rows, which says
73+
* nothing about what formly builds from a row template or what it does with a field the Form View
74+
* marked for a reader. This one stands the table up the way the app does -- a form, the builder row
75+
* template formly-jsonschema produces, nz-input cells -- so the rows are formly's own and the
76+
* reader's lock is the one formly applied.
77+
*/
78+
describe("UiUdfParametersComponent under real formly", () => {
79+
/** The canvas's modification flag, which the Form View holds off outside edit mode. */
80+
let modificationEnabled = true;
81+
82+
beforeEach(async () => {
83+
modificationEnabled = true;
84+
await TestBed.configureTestingModule({
85+
imports: [
86+
HostComponent,
87+
FormlyModule.forRoot({
88+
types: [
89+
{ name: "ui-udf-parameters", component: UiUdfParametersComponent },
90+
{ name: "plain", component: InputCellType },
91+
],
92+
}),
93+
],
94+
providers: [
95+
{
96+
provide: WorkflowActionService,
97+
useValue: {
98+
checkWorkflowModificationEnabled: () => modificationEnabled,
99+
getJointGraphWrapper: () => ({ getCurrentHighlightedOperatorIDs: () => ["op-1"] }),
100+
},
101+
},
102+
{ provide: UiUdfParametersSyncService, useValue: { addParameter: vi.fn() } },
103+
{ provide: NotificationService, useValue: { error: vi.fn() } },
104+
],
105+
}).compileComponents();
106+
});
107+
108+
/**
109+
* Renders the host; `topProps` go on the table's field (the Form View puts its marks there), `rows`
110+
* replace the two parameters the model declares by default.
111+
*/
112+
function render(topProps?: Record<string, unknown>, rows?: unknown[]) {
113+
const fixture = TestBed.createComponent(HostComponent);
114+
if (topProps) {
115+
fixture.componentInstance.fields[0].props = topProps;
116+
}
117+
if (rows) {
118+
fixture.componentInstance.model = { uiParameters: rows as HostComponent["model"]["uiParameters"] };
119+
}
120+
fixture.detectChanges();
121+
const form = fixture.componentInstance.form;
122+
const cell = (row: number, path: string) => form.get(`uiParameters.${row}.${path}`)!;
123+
const locks = () => [
124+
cell(0, "value").disabled,
125+
cell(0, "attribute.attributeName").disabled,
126+
cell(0, "attribute.attributeType").disabled,
127+
cell(1, "attribute.attributeName").disabled,
128+
];
129+
return { fixture, form, locks };
130+
}
131+
132+
it("builds the rows with the Name and Type cells locked and the Value cell editable", () => {
133+
const { locks } = render();
134+
135+
expect(locks()).toEqual([false, true, true, true]);
136+
});
137+
138+
const addButton = (fixture: { nativeElement: HTMLElement }) =>
139+
fixture.nativeElement.querySelector(".add-parameter-button");
140+
141+
it("offers Add parameter on a writer's Form View card without the canvas's flag, and not on a reader's, whose field is disabled", () => {
142+
modificationEnabled = false;
143+
144+
const writer = render({ operatorID: "op-form" });
145+
expect(addButton(writer.fixture)).not.toBeNull();
146+
147+
const reader = render({ operatorID: "op-form", disabled: true });
148+
expect(reader.locks()).toEqual([true, true, true, true]);
149+
expect(addButton(reader.fixture)).toBeNull();
150+
});
151+
152+
// formly disables the controls it builds under a disabled field, not the array itself, and an
153+
// array with no rows reads as enabled; the form's mark on the field is what says "a reader's".
154+
it("offers Add parameter to a writer whose UDF declares no parameters yet, and not to a reader, though the empty array control is enabled", () => {
155+
modificationEnabled = false;
156+
157+
const writer = render({ operatorID: "op-form" }, []);
158+
expect(writer.form.get("uiParameters")!.enabled).toBe(true);
159+
expect(addButton(writer.fixture)).not.toBeNull();
160+
161+
const reader = render({ operatorID: "op-form", disabled: true }, []);
162+
expect(reader.form.get("uiParameters")!.enabled).toBe(true);
163+
expect(addButton(reader.fixture)).toBeNull();
164+
});
165+
});

‎frontend/src/app/workspace/component/ui-udf-parameters/ui-udf-parameters.component.html‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div class="ui-udf-parameters-field">
2020
<button
2121
class="add-parameter-button"
22-
*ngIf="workflowModificationEnabled && !draftVisible"
22+
*ngIf="editable && !draftVisible"
2323
nz-button
2424
nzType="dashed"
2525
nzBlock
@@ -37,8 +37,8 @@
3737
<div class="ui-udf-parameter-row header">
3838
<div
3939
class="field-cell"
40-
*ngFor="let column of fieldColumns">
41-
<span class="col-title">{{ column.label }}</span>
40+
*ngFor="let column of columns">
41+
<span class="col-title">{{ columnLabel(column) }}</span>
4242
</div>
4343
</div>
4444

@@ -95,7 +95,7 @@
9595
<ng-container *ngIf="field.fieldGroup?.[i] as rowField">
9696
<div
9797
class="field-cell"
98-
*ngFor="let column of fieldColumns">
98+
*ngFor="let column of columns">
9999
<formly-field
100100
*ngIf="getColumnField(rowField, column) as columnField"
101101
[field]="columnField"></formly-field>

0 commit comments

Comments
 (0)