Copilot commented on code in PR #8304:
URL: https://github.com/apache/texera/pull/8304#discussion_r3908789176


##########
frontend/src/app/workspace/service/form-binding/form-binding.service.ts:
##########
@@ -0,0 +1,295 @@
+/**
+ * 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 { Injectable } from "@angular/core";
+import { BehaviorSubject, Observable } from "rxjs";
+import { CustomJSONSchema7 } from "../../types/custom-json-schema.interface";
+import { OperatorPredicate } from "../../types/workflow-common.interface";
+import { FormFieldBinding, FormFieldOverride, FormBindingConfig } from 
"../../../common/type/workflow";
+import { OperatorMetadataService } from 
"../operator-metadata/operator-metadata.service";
+import { DynamicSchemaService } from 
"../dynamic-schema/dynamic-schema.service";
+import { WorkflowActionService } from 
"../workflow-graph/model/workflow-action.service";
+
+/** A binding paired with the operator field that renders it. */
+export interface ResolvedField {
+  binding: FormFieldBinding;
+  /** The operator's current value -- what the form shows and what a run uses. 
*/
+  value: unknown;
+  /** Label for the operator this input belongs to, for the author's 
reference. */
+  operatorLabel: string;
+  schema?: CustomJSONSchema7;
+  /**
+   * Set when the binding no longer points at a real property, because the 
operator
+   * was deleted on the regular canvas or the raw key was mistyped. Broken 
inputs are
+   * shown to the author with the reason and hidden from everyone else, since 
filling
+   * one in could not do anything.
+   */
+  brokenReason?: string;
+}
+
+/**
+ * Reads and writes the Form View definition. The one rule it enforces: a 
definition never
+ * affects a run -- filling an input is the same `setOperatorProperty` edit 
the canvas makes,
+ * and everything else (names, help text, ordering, instruction) is 
presentation.
+ */
+@Injectable({ providedIn: "root" })
+export class FormBindingService {
+  /** Whether the author is choosing which properties the form offers. Sticky 
(choosing spans
+   *  several operators), so it stays on until the author turns it off. */
+  private choosingSubject = new BehaviorSubject<boolean>(false);
+  public readonly choosing$: Observable<boolean> = 
this.choosingSubject.asObservable();
+
+  constructor(
+    private workflowActionService: WorkflowActionService,
+    private operatorMetadataService: OperatorMetadataService,
+    private dynamicSchemaService: DynamicSchemaService
+  ) {}
+
+  public isChoosing(): boolean {
+    return this.choosingSubject.value;
+  }
+
+  public setChoosing(choosing: boolean): void {
+    if (this.choosingSubject.value !== choosing) {
+      this.choosingSubject.next(choosing);
+    }
+  }
+
+  public getConfig(): FormBindingConfig {
+    return this.workflowActionService.getFormBinding();
+  }
+
+  /** Apply a partial edit to the definition, announcing it so it gets saved. 
*/
+  public updateConfig(patch: Partial<FormBindingConfig>): void {
+    this.workflowActionService.setFormBinding({ ...this.getConfig(), ...patch 
});
+  }
+
+  public setFields(fields: FormFieldBinding[]): void {
+    this.updateConfig({ fields });
+  }
+
+  public updateBinding(id: string, patch: Partial<FormFieldBinding>): void {

Review Comment:
   `updateBinding` exposes the supposedly stable `id` in its patch type, so a 
caller can rename the identifier that reorder/removal and override updates key 
on. Exclude `id` from the accepted patch to enforce the interface's 
stable-identity contract at compile time.



##########
frontend/src/app/workspace/service/form-binding/form-binding.service.ts:
##########
@@ -0,0 +1,295 @@
+/**
+ * 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 { Injectable } from "@angular/core";
+import { BehaviorSubject, Observable } from "rxjs";
+import { CustomJSONSchema7 } from "../../types/custom-json-schema.interface";
+import { OperatorPredicate } from "../../types/workflow-common.interface";
+import { FormFieldBinding, FormFieldOverride, FormBindingConfig } from 
"../../../common/type/workflow";
+import { OperatorMetadataService } from 
"../operator-metadata/operator-metadata.service";
+import { DynamicSchemaService } from 
"../dynamic-schema/dynamic-schema.service";
+import { WorkflowActionService } from 
"../workflow-graph/model/workflow-action.service";
+
+/** A binding paired with the operator field that renders it. */
+export interface ResolvedField {
+  binding: FormFieldBinding;
+  /** The operator's current value -- what the form shows and what a run uses. 
*/
+  value: unknown;
+  /** Label for the operator this input belongs to, for the author's 
reference. */
+  operatorLabel: string;
+  schema?: CustomJSONSchema7;
+  /**
+   * Set when the binding no longer points at a real property, because the 
operator
+   * was deleted on the regular canvas or the raw key was mistyped. Broken 
inputs are
+   * shown to the author with the reason and hidden from everyone else, since 
filling
+   * one in could not do anything.
+   */
+  brokenReason?: string;
+}
+
+/**
+ * Reads and writes the Form View definition. The one rule it enforces: a 
definition never
+ * affects a run -- filling an input is the same `setOperatorProperty` edit 
the canvas makes,
+ * and everything else (names, help text, ordering, instruction) is 
presentation.
+ */
+@Injectable({ providedIn: "root" })
+export class FormBindingService {
+  /** Whether the author is choosing which properties the form offers. Sticky 
(choosing spans
+   *  several operators), so it stays on until the author turns it off. */
+  private choosingSubject = new BehaviorSubject<boolean>(false);
+  public readonly choosing$: Observable<boolean> = 
this.choosingSubject.asObservable();
+
+  constructor(
+    private workflowActionService: WorkflowActionService,
+    private operatorMetadataService: OperatorMetadataService,
+    private dynamicSchemaService: DynamicSchemaService
+  ) {}
+
+  public isChoosing(): boolean {
+    return this.choosingSubject.value;
+  }
+
+  public setChoosing(choosing: boolean): void {
+    if (this.choosingSubject.value !== choosing) {
+      this.choosingSubject.next(choosing);
+    }
+  }
+
+  public getConfig(): FormBindingConfig {
+    return this.workflowActionService.getFormBinding();
+  }
+
+  /** Apply a partial edit to the definition, announcing it so it gets saved. 
*/
+  public updateConfig(patch: Partial<FormBindingConfig>): void {
+    this.workflowActionService.setFormBinding({ ...this.getConfig(), ...patch 
});
+  }
+
+  public setFields(fields: FormFieldBinding[]): void {
+    this.updateConfig({ fields });
+  }
+
+  public updateBinding(id: string, patch: Partial<FormFieldBinding>): void {
+    this.setFields(this.getConfig().fields.map(p => (p.id === id ? { ...p, 
...patch } : p)));
+  }
+
+  public removeBinding(id: string): void {
+    this.setFields(this.getConfig().fields.filter(p => p.id !== id));
+  }
+
+  /** The binding for one operator property, if it is currently exposed on the 
form. */
+  private findBinding(operatorID: string, propertyKey: string): 
FormFieldBinding | undefined {
+    return this.getConfig().fields.find(p => p.operatorID === operatorID && 
p.propertyKey === propertyKey);
+  }
+
+  /**
+   * Expose an operator property on the form. A no-op if it is already 
exposed; the display
+   * name starts from the schema's title so the author begins with a readable 
label.
+   */
+  public addBinding(operatorID: string, propertyKey: string): void {
+    if (this.findBinding(operatorID, propertyKey)) {
+      return;
+    }
+    const schema = this.propertySchema(operatorID, propertyKey);
+    this.setFields([
+      ...this.getConfig().fields,
+      {
+        id: `field-${crypto.randomUUID()}`,
+        operatorID,
+        propertyKey,
+        displayName: (schema?.title as string) || propertyKey,
+        // Deliberately not seeded from the schema's description. That text 
describes the
+        // operator to whoever wired it up -- "Multiple string key/value 
pairs" -- and
+        // appearing unbidden under a reader's input it is worse than nothing: 
it reads
+        // as guidance the author never wrote and cannot be told apart from 
guidance
+        // they did. Empty until the author has something to say.
+        helpText: undefined,
+      },
+    ]);
+  }
+
+  /**
+   * Apply an override to one field. An entry that no longer says anything is 
deleted
+   * rather than left as an empty object, so the saved definition stays a 
record of the
+   * author's decisions instead of accumulating every field they happened to 
look at.
+   */
+  public setFieldOverride(bindingId: string, path: string, patch: 
Partial<FormFieldOverride>): void {
+    const binding = this.getConfig().fields.find(p => p.id === bindingId);
+    if (!binding) {
+      return;
+    }
+    const merged: FormFieldOverride = { ...(binding.overrides?.[path] ?? {}), 
...patch };
+    if (merged.displayName !== undefined && merged.displayName.trim() === "") {
+      delete merged.displayName;
+    }
+    if (merged.hidden === false) {
+      delete merged.hidden;
+    }

Review Comment:
   An explicit `undefined` in this partial patch leaves an own key in `merged`, 
so `Object.keys(merged)` is nonempty and the saved configuration retains an 
empty override (for example, `{ displayName: undefined }` serializes as `{}`). 
Normalize absent values as defaults too, matching the method's stated cleanup 
behavior.



##########
frontend/src/app/workspace/service/form-binding/form-binding.service.ts:
##########
@@ -0,0 +1,295 @@
+/**
+ * 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 { Injectable } from "@angular/core";
+import { BehaviorSubject, Observable } from "rxjs";
+import { CustomJSONSchema7 } from "../../types/custom-json-schema.interface";
+import { OperatorPredicate } from "../../types/workflow-common.interface";
+import { FormFieldBinding, FormFieldOverride, FormBindingConfig } from 
"../../../common/type/workflow";
+import { OperatorMetadataService } from 
"../operator-metadata/operator-metadata.service";
+import { DynamicSchemaService } from 
"../dynamic-schema/dynamic-schema.service";
+import { WorkflowActionService } from 
"../workflow-graph/model/workflow-action.service";
+
+/** A binding paired with the operator field that renders it. */
+export interface ResolvedField {
+  binding: FormFieldBinding;
+  /** The operator's current value -- what the form shows and what a run uses. 
*/
+  value: unknown;
+  /** Label for the operator this input belongs to, for the author's 
reference. */
+  operatorLabel: string;
+  schema?: CustomJSONSchema7;
+  /**
+   * Set when the binding no longer points at a real property, because the 
operator
+   * was deleted on the regular canvas or the raw key was mistyped. Broken 
inputs are
+   * shown to the author with the reason and hidden from everyone else, since 
filling
+   * one in could not do anything.
+   */
+  brokenReason?: string;
+}
+
+/**
+ * Reads and writes the Form View definition. The one rule it enforces: a 
definition never
+ * affects a run -- filling an input is the same `setOperatorProperty` edit 
the canvas makes,
+ * and everything else (names, help text, ordering, instruction) is 
presentation.
+ */
+@Injectable({ providedIn: "root" })
+export class FormBindingService {
+  /** Whether the author is choosing which properties the form offers. Sticky 
(choosing spans
+   *  several operators), so it stays on until the author turns it off. */
+  private choosingSubject = new BehaviorSubject<boolean>(false);
+  public readonly choosing$: Observable<boolean> = 
this.choosingSubject.asObservable();
+
+  constructor(
+    private workflowActionService: WorkflowActionService,
+    private operatorMetadataService: OperatorMetadataService,
+    private dynamicSchemaService: DynamicSchemaService
+  ) {}
+
+  public isChoosing(): boolean {
+    return this.choosingSubject.value;
+  }
+
+  public setChoosing(choosing: boolean): void {
+    if (this.choosingSubject.value !== choosing) {
+      this.choosingSubject.next(choosing);
+    }
+  }
+
+  public getConfig(): FormBindingConfig {
+    return this.workflowActionService.getFormBinding();
+  }
+
+  /** Apply a partial edit to the definition, announcing it so it gets saved. 
*/
+  public updateConfig(patch: Partial<FormBindingConfig>): void {
+    this.workflowActionService.setFormBinding({ ...this.getConfig(), ...patch 
});
+  }
+
+  public setFields(fields: FormFieldBinding[]): void {
+    this.updateConfig({ fields });
+  }
+
+  public updateBinding(id: string, patch: Partial<FormFieldBinding>): void {
+    this.setFields(this.getConfig().fields.map(p => (p.id === id ? { ...p, 
...patch } : p)));
+  }
+
+  public removeBinding(id: string): void {
+    this.setFields(this.getConfig().fields.filter(p => p.id !== id));
+  }
+
+  /** The binding for one operator property, if it is currently exposed on the 
form. */
+  private findBinding(operatorID: string, propertyKey: string): 
FormFieldBinding | undefined {
+    return this.getConfig().fields.find(p => p.operatorID === operatorID && 
p.propertyKey === propertyKey);
+  }
+
+  /**
+   * Expose an operator property on the form. A no-op if it is already 
exposed; the display
+   * name starts from the schema's title so the author begins with a readable 
label.
+   */
+  public addBinding(operatorID: string, propertyKey: string): void {
+    if (this.findBinding(operatorID, propertyKey)) {
+      return;
+    }
+    const schema = this.propertySchema(operatorID, propertyKey);
+    this.setFields([
+      ...this.getConfig().fields,
+      {
+        id: `field-${crypto.randomUUID()}`,
+        operatorID,
+        propertyKey,
+        displayName: (schema?.title as string) || propertyKey,
+        // Deliberately not seeded from the schema's description. That text 
describes the
+        // operator to whoever wired it up -- "Multiple string key/value 
pairs" -- and
+        // appearing unbidden under a reader's input it is worse than nothing: 
it reads
+        // as guidance the author never wrote and cannot be told apart from 
guidance
+        // they did. Empty until the author has something to say.
+        helpText: undefined,
+      },
+    ]);
+  }
+
+  /**
+   * Apply an override to one field. An entry that no longer says anything is 
deleted
+   * rather than left as an empty object, so the saved definition stays a 
record of the
+   * author's decisions instead of accumulating every field they happened to 
look at.
+   */
+  public setFieldOverride(bindingId: string, path: string, patch: 
Partial<FormFieldOverride>): void {
+    const binding = this.getConfig().fields.find(p => p.id === bindingId);
+    if (!binding) {
+      return;
+    }
+    const merged: FormFieldOverride = { ...(binding.overrides?.[path] ?? {}), 
...patch };
+    if (merged.displayName !== undefined && merged.displayName.trim() === "") {
+      delete merged.displayName;
+    }
+    if (merged.hidden === false) {
+      delete merged.hidden;
+    }
+    const overrides = { ...(binding.overrides ?? {}) };
+    if (Object.keys(merged).length === 0) {
+      delete overrides[path];
+    } else {
+      overrides[path] = merged;
+    }
+    this.updateBinding(bindingId, { overrides: Object.keys(overrides).length > 
0 ? overrides : undefined });
+  }
+
+  public isExposed(operatorID: string, propertyKey: string): boolean {
+    return this.findBinding(operatorID, propertyKey) !== undefined;
+  }
+
+  /** Add or remove an input from the form, driven by the property editor's 
tick box. */
+  public setExposed(operatorID: string, propertyKey: string, exposed: 
boolean): void {
+    if (exposed) {
+      this.addBinding(operatorID, propertyKey);
+      return;
+    }
+    const existing = this.findBinding(operatorID, propertyKey);
+    if (existing) {
+      this.removeBinding(existing.id);
+    }
+  }
+
+  /** Move an input to a new position; array order is what the form renders. */
+  public reorder(from: number, to: number): void {
+    const fields = [...this.getConfig().fields];
+    if (from === to || from < 0 || to < 0 || from >= fields.length || to >= 
fields.length) {
+      return;
+    }
+    fields.splice(to, 0, fields.splice(from, 1)[0]);
+    this.setFields(fields);
+  }
+
+  /**
+   * Choose whether an operator's output is shown on the form after a run. 
This records the
+   * form's own selection only and never changes the canvas's view-result 
flags: the form
+   * offers exactly the operators the workflow already views, so their results 
are already
+   * materialised and nothing here needs to touch the graph. Read-only, one 
direction.
+   */
+  public toggleResultOperator(operatorID: string): void {
+    const shown = this.getConfig().resultOperatorIds;
+    const next = shown.includes(operatorID) ? shown.filter(id => id !== 
operatorID) : [...shown, operatorID];
+    this.updateConfig({ resultOperatorIds: next });

Review Comment:
   This can select a result that execution will not materialize. The method 
neither verifies nor maintains the graph's `viewResult` set (and the test 
selects `mockScanPredicate`, whose flag is unset), while 
`ExecuteWorkflowService` builds `opsToViewResult` solely from 
`workflowGraph.getOperatorsToViewResult()` at 
`execute-workflow.service.ts:451`. Constrain selections to currently viewed 
operators and remove them when that flag/operator disappears, or make execution 
include Form View selections so every stored result ID can actually produce 
output.



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