yangzhang75 commented on code in PR #8846: URL: https://github.com/apache/texera/pull/8846#discussion_r4556796495
########## frontend/src/app/common/formly/sub-field-view.ts: ########## @@ -0,0 +1,99 @@ +/** + * 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. + */ + +/** + * What the Form View's author decided about each sub-field of an exposed input, resolved for the + * reader in front of it, for a widget that draws its own chrome. + * + * Formly expresses a rename as the field's label and a hide as `hide`, and renders both through the + * field's wrapper. A widget that renders its sub-fields itself -- a table with its own column + * headers, a legend, a summary line -- never goes through that wrapper, so it shows neither: a + * renamed column keeps its old heading, and a hidden one keeps its heading over an empty cell + * (#8763). Reading the state back out of the rendered fields is not the answer either: it is only + * there once formly has built a row, so a table whose operator declares nothing yet has nothing to + * read, and a group's hide is marked on the group while its children are merely not rendered. + * + * So the page that holds the author's decisions publishes them, once, on the field it hands the + * widget ({@link SUB_FIELD_VIEW_PROP}), and the widget asks here. Nothing published -- the operator + * property panel, where there is no author and no overrides -- means every sub-field is in view + * under its own name, which is what a widget's fixed headers already say. + */ +export interface SubFieldView { + /** + * The name the author gave this sub-field, or "" where they kept the one it came with: a widget + * has a name of its own for the part it draws (a table's column heading) and keeps it then. + */ + readonly label: string; + /** Whether this sub-field is in view at all. False only for a reader looking at a hidden one. */ + readonly shown: boolean; +} + +/** Where a host publishes {@link SubFieldView}s, keyed by sub-field path, in the field's `props`. */ +export const SUB_FIELD_VIEW_PROP = "subFieldView"; + +/** What the host published for this field, if it is a host that publishes. */ +export function subFieldViews(field: { + props?: Record<string, unknown>; +}): Readonly<Record<string, SubFieldView>> | undefined { + const published = field.props?.[SUB_FIELD_VIEW_PROP]; + return typeof published === "object" && published !== null Review Comment: Right on arrays (a function is `typeof "function"`, so it was already refused). The guard now refuses an array as it refuses a string, and the "not a map" test covers one. a354759f7. ########## frontend/src/app/workspace/component/ui-udf-parameters/ui-udf-parameters.component.ts: ########## @@ -69,28 +84,82 @@ export class UiUdfParametersComponent extends FieldArrayType<FormlyFieldConfig> readonly fieldColumns: UiUdfParameterColumn[] = [ VALUE_COLUMN, - { label: "Name", key: "attributeName", parentKey: "attribute", disabled: true }, - { label: "Type", key: "attributeType", parentKey: "attribute", disabled: true }, + { label: "Name", key: "attributeName", parentKey: "attribute", path: "attribute.attributeName", disabled: true }, + { label: "Type", key: "attributeType", parentKey: "attribute", path: "attribute.attributeType", disabled: true }, ]; + /** + * The columns in view: all three on the operator property panel, and on a Form View card the ones + * the author left (subFieldsInView, which keeps the array's identity so the header's ngFor does + * not redraw). All three come back while the draft row is open: that row names and types the + * parameter being added, so it needs them whatever the author hid, and a filtered header over its + * three cells put the name box under the wrong heading (Copilot on #8846). + * + * Read live rather than fixed at populate: the form publishes its decisions on the field, which + * this widget is handed after its first check. + */ + get columns(): readonly UiUdfParameterColumn[] { + return this.draftVisible ? this.fieldColumns : subFieldsInView(this.field ?? {}, this.fieldColumns); + } + readonly addParameterTypeOptions = UI_PARAMETER_TYPES; draftVisible = false; constructor( private workflowActionService: WorkflowActionService, private uiUdfParametersSyncService: UiUdfParametersSyncService, - private notificationService: NotificationService + private notificationService: NotificationService, + private executeWorkflowService: ExecuteWorkflowService ) { super(); } - get workflowModificationEnabled(): boolean { - return this.workflowActionService.checkWorkflowModificationEnabled(); + /** Whether this is a Form View card rather than the operator property panel; see editable. */ + get onFormView(): boolean { + return renderedInFormView(this.field ?? {}); } - /** Inserts the declaration into shared UDF code; the row then appears through the normal code sync. */ + /** + * Whether the table takes a new parameter here. On the operator property panel that is the + * canvas's rule, as it always was: the workflow may be modified (write access, no run in flight). + * + * A Form View card asks those two halves separately, because the canvas's flag does not answer + * either one there. Write access: the card is not a reader's, which the form marks on the field + * itself (props.disabled, its one lock on a card; see renderedReadOnly). A writer's card is + * editable in and out of edit mode, as every value on it is (adding a parameter is adding a row), + * and the flag is not that -- the Form View holds it off outside edit mode, against structural + * edits through its page, which hid the button on a card whose values could still be edited. No + * run in flight: asked of the execute service, which owns that rule, since the flag that would + * otherwise carry it is held off for the reason above. Adding a parameter inserts a declaration + * into the UDF's own code, straight into the shared document, and code is what a run must not have + * rewritten under it -- the property panel and the canvas code editor both refuse it then. + * + * The mark decides rather than the table's own control, which does not answer the question: + * formly disables the leaf controls under a disabled field, not the array itself, so a reader's + * table with no parameters yet reads as enabled (a reader's table with rows reads as disabled only + * because every row's controls are). + */ + get editable(): boolean { + if (!this.onFormView) { + return this.workflowActionService.checkWorkflowModificationEnabled(); + } + return !renderedReadOnly(this.field) && !this.executeWorkflowService.isExecutionInFlight(); + } + + /** + * Inserts the declaration into the operator's Python code; the row then appears through the normal + * code sync. The operator is the one the field is bound to on a Form View card (nothing is + * highlighted there, or another step is); on the operator property panel it is the highlighted one, + * as it always was. + */ addParameter(nameInput: HTMLInputElement, attributeType: string): void { - const operatorId = this.workflowActionService.getJointGraphWrapper().getCurrentHighlightedOperatorIDs()[0]; + // The button is hidden then too; the check belongs with the edit, not only with the button. + if (!this.editable) { + return; + } + const operatorId = + fieldOperatorID(this.field ?? {}) ?? + this.workflowActionService.getJointGraphWrapper().getCurrentHighlightedOperatorIDs()[0]; Review Comment: Not reachable: on the Form View `renderField` puts `operatorID` on every field it renders, and on the operator property panel the widget exists because an operator is highlighted -- the same `getCurrentHighlightedOperatorIDs()[0]` this line had on main. A guard here would be for a state neither host produces, so leaving it. ########## frontend/src/app/workspace/service/execute-workflow/execute-workflow.service.ts: ########## @@ -251,6 +251,17 @@ export class ExecuteWorkflowService { this.updateWorkflowActionLock(this.currentState); } + /** + * Whether a run is in flight: exactly the states that lock the graph, which is the same question + * {@link updateWorkflowActionLock} answers to lock it. A view that must refuse a structural edit + * mid-run asks here instead of re-listing the states, and a view that cannot read the lock itself + * -- the Form View clamps it off outside edit mode, so there it no longer means "a run is on" -- Review Comment: "there" meant the Form View, but it read as a typo; it says "on that page" now. a354759f7. -- 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]
