yangzhang75 commented on code in PR #8304: URL: https://github.com/apache/texera/pull/8304#discussion_r3908903858
########## 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: Fixed. updateBinding now takes Partial<Omit<FormFieldBinding, "id">>, so the stable id cannot be changed through a patch, enforced at compile time. The only internal caller patches overrides, so nothing else is affected. -- 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]
