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-9408-cc1f201596936a12e79f6243cdc38bef3f73c767 in repository https://gitbox.apache.org/repos/asf/texera.git
commit 07db1dac3bd03206a33ead5602d9fbd356fd1438 Author: yangzhang75 <[email protected]> AuthorDate: Thu Nov 12 06:25:37 2026 +0000 fix(workspace, workflow-form): show the step the shared selection already holds (#9408) ### What changes were proposed in this PR? Closes #9400. A workflow's two views share one selection: it lives in the root-provided `JointGraphWrapper`, which the switch between the canvas and the Form View hands over rather than rebuilds. Nothing is lost in the switch, but everything that shows the selection followed only the highlight streams and never read it when it mounted. The event that made the selection had already happened, so the view arriving at it waited for an event that never came: the panel showed nothing, and the step was drawn as not selected. Clicking that step did not help, since the wrapper treats an already-highlighted element as a no-op and emits nothing; it took clicking a *different* step to bring the panel back. Each of the three now reads the selection it mounts into, then follows the changes as before: - `PropertyEditorComponent` (the canvas's panel and every host of it, so not specific to the Form View, to any operator type, or to operators as opposed to ports): the body of the highlight subscription becomes `showHighlighted()`, the same decision as before (one operator, one port, or nothing) with the `syncTexeraGraph` guard that the stream applied as a `filter` now inside it, so it is applied once on both paths. `registerHighlightEventsHandler()` calls it before subscribing, and only when something is highlighted: the no-frame branch is for a selection being dropped (it clears the editing marker on the shared awareness channel and resizes the docked panel to its empty content), which a fresh mount must not do. It is also called after the toolbar's choosing toggle has replayed its value, so the frame it builds carries `choosing` from the start instead of being torn down and rebuilt by the replay inside the page's first change-detection pass. Not `startWith` on the stream: its initial emission is unconditional, which is exactly the empty-branch-at-mount this avoids. - `WorkflowEditorComponent`: the ring. The paper is new on every switch, and the highlighter was applied only from the stream, so the arriving view would have shown its panel for a step drawn as not selected. The handler now rings the operators and comment boxes the wrapper already holds, then follows the streams; the `findViewByModel` guard the unhighlight branch already had is shared with it. - `WorkflowFormComponent`: one call to the `syncSelectionFromHighlight()` it already has, in `ngOnInit` after it subscribes, so the form's step panel opens on the selection it arrives with. The template note that justified `[hidden]` over `*ngIf` by the panel having "no initial pull" is reworded to the reason that still holds. No change to who owns the selection, to what a click does, or to the canvas's own behaviour when it is the only view open: with nothing selected, nothing is read, and both panels mount empty exactly as before. The wrapper's no-op for an already-highlighted element is deliberately untouched (it is what keeps a shift-selection stable); it simply stops mattering, because the arriving view already shows that step. #### Video **Before** https://github.com/user-attachments/assets/e00affd4-46aa-4691-acc4-5d33060da766 **After** https://github.com/user-attachments/assets/f50674e4-b0fd-4941-bcca-860d1aa61abe ### Any related issues, documentation, discussions? Closes #9400. Part of the Form View (#8011). Related to #8846, which touches `workflow-form.component.ts` elsewhere and does not read the selection on mount: its `frameWrites` guard compares `selectedOperatorId`, which only `syncSelectionFromHighlight()` sets, so on arriving in the Form View with a step selected that guard saw `undefined` and the form wrote the declared parameters even while the live panel showed that step. With this change `selectedOperatorId` is set on arrival and the guard holds. The two do not overlap in code; whichever lands second rebases. ### How was this PR tested? - `property-editor.component.spec.ts`: a panel mounting into an existing selection shows that operator; mounting into no selection leaves the panel alone and mounting into two shows no frame (the two-operator selection is made explicit with `setMultiSelectMode(true)` and asserted before the check); and the frame a panel mounts into is built with the toolbar's choosing state, with no rebuild, which pins the order of the two subscriptions. - `workflow-editor.component.spec.ts`: wiring the highlight handler into a selection the wrapper already holds rings that operator once (a spy installed after the stream has done its work). - `workflow-form.component.spec.ts`: the form's step panel opens on the step the canvas had selected, and stays closed for none or several — seeded with a stale id, so a read that never happened could not pass as "undefined". - Existing specs for all three components pass unchanged; they cover what the streams do after mount. - The full frontend suite, eslint, prettier and the production (AOT) build pass. - By hand on a local deployment, `main` (`cfca8e1e5`) and this branch served side by side on the same backend and the same workflow, driven by a Playwright probe that reads what the panel shows at each step: | step | main | this branch | | --- | --- | --- | | click the step on the canvas | the step | the step | | switch to the Form View | empty | the step, ringed on the preview | | click that same step on the preview | empty | the step | | switch back to the canvas | empty | the step, ringed on the canvas | ### Was this PR authored or co-authored using generative AI tooling? Yes. Generated-by: Claude Code (Claude Fable 5.1, Anthropic). Co-authored with Claude, reviewed line by line by the author before submission. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.1 <[email protected]> --- .../property-editor.component.spec.ts | 66 +++++++++++++++ .../property-editor/property-editor.component.ts | 97 +++++++++++++--------- .../workflow-editor.component.spec.ts | 19 +++++ .../workflow-editor/workflow-editor.component.ts | 17 ++-- .../workflow-form/workflow-form.component.html | 7 +- .../workflow-form/workflow-form.component.spec.ts | 30 +++++++ .../workflow-form/workflow-form.component.ts | 4 + 7 files changed, 191 insertions(+), 49 deletions(-) diff --git a/frontend/src/app/workspace/component/property-editor/property-editor.component.spec.ts b/frontend/src/app/workspace/component/property-editor/property-editor.component.spec.ts index 8faca7d0c0..a0fba29f5e 100644 --- a/frontend/src/app/workspace/component/property-editor/property-editor.component.spec.ts +++ b/frontend/src/app/workspace/component/property-editor/property-editor.component.spec.ts @@ -147,6 +147,72 @@ describe("PropertyEditorComponent", () => { expect(getById).not.toHaveBeenCalledWith("right-container"); }); + // The selection lives in the graph wrapper, which both views of a workflow share and hand over + // between them: a panel that only followed the streams stayed empty on arrival, since the event + // that made the selection fired before it existed -- and clicking the selected operator emits + // nothing, so it took clicking a different one to bring the panel back. ngOnInit is re-run on the + // live fixture, which is what a fresh mount into the same shared selection comes down to. + it("shows what is already selected when it mounts, not only what is selected next", () => { + const jointGraphWrapper = workflowActionService.getJointGraphWrapper(); + workflowActionService.addOperator(mockScanPredicate, mockPoint); + jointGraphWrapper.highlightOperators(mockScanPredicate.operatorID); + // As a panel that was not there when the selection was made: it has shown nothing so far. + component.currentComponent = null; + component.componentInputs = {}; + + component.ngOnInit(); + + expect(component.currentComponent).toBe(OperatorPropertyEditFrameComponent); + expect(component.componentInputs).toEqual( + expect.objectContaining({ currentOperatorId: mockScanPredicate.operatorID }) + ); + }); + + it("leaves the panel alone when it mounts into no selection, and shows no frame into several", () => { + const jointGraphWrapper = workflowActionService.getJointGraphWrapper(); + // Nothing selected: the no-frame branch is for a selection being dropped (it clears the + // editing marker and resizes the docked panel), so a fresh mount must not run it. + component.currentComponent = OperatorPropertyEditFrameComponent; + component.ngOnInit(); + expect(component.currentComponent).toBe(OperatorPropertyEditFrameComponent); + + // Two selected: a selection exists but no single step to show, so no frame. + workflowActionService.addOperatorsAndLinks( + [ + { op: mockScanPredicate, pos: mockPoint }, + { op: mockResultPredicate, pos: mockPoint }, + ], + [] + ); + jointGraphWrapper.setMultiSelectMode(true); + jointGraphWrapper.highlightOperators(mockScanPredicate.operatorID, mockResultPredicate.operatorID); + expect(jointGraphWrapper.getCurrentHighlightedOperatorIDs()).toHaveLength(2); + component.currentComponent = OperatorPropertyEditFrameComponent; + + component.ngOnInit(); + expect(component.currentComponent).toBeNull(); + }); + + // The toolbar's choosing toggle replays its current value on subscribe. A frame built before + // that replay would be built without it and then torn down and rebuilt by it, inside the page's + // first change-detection pass; so the mount-time read comes after the subscription. Checked on + // a panel whose own toggle state is fresh, as a mounting panel's is. + it("builds the frame it mounts into with the toolbar's choosing state, without a rebuild", () => { + const jointGraphWrapper = workflowActionService.getJointGraphWrapper(); + workflowActionService.addOperator(mockScanPredicate, mockPoint); + jointGraphWrapper.highlightOperators(mockScanPredicate.operatorID); + TestBed.inject(FormBindingService).setChoosing(true); + component.currentComponent = null; + component.componentInputs = {}; + (component as unknown as { choosingFromToolbar: boolean }).choosingFromToolbar = false; + + component.ngOnInit(); + + // Built once, with choosing on -- not built off and then nulled by the replay for a rebuild. + expect(component.currentComponent).toBe(OperatorPropertyEditFrameComponent); + expect(component.componentInputs).toEqual(expect.objectContaining({ exposeChoosing: true })); + }); + /** * test if the property editor correctly receives the operator unhighlight stream * and clears all the operator data, and hide the form. diff --git a/frontend/src/app/workspace/component/property-editor/property-editor.component.ts b/frontend/src/app/workspace/component/property-editor/property-editor.component.ts index 08be5974a9..39dacaf9c5 100644 --- a/frontend/src/app/workspace/component/property-editor/property-editor.component.ts +++ b/frontend/src/app/workspace/component/property-editor/property-editor.component.ts @@ -35,7 +35,7 @@ import { merge } from "rxjs"; import { WorkflowActionService } from "../../service/workflow-graph/model/workflow-action.service"; import { OperatorPropertyEditFrameComponent } from "./operator-property-edit-frame/operator-property-edit-frame.component"; import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy"; -import { distinctUntilChanged, filter } from "rxjs/operators"; +import { distinctUntilChanged } from "rxjs/operators"; import { PortPropertyEditFrameComponent } from "./port-property-edit-frame/port-property-edit-frame.component"; import { NzResizeEvent, NzResizableDirective, NzResizeHandlesComponent } from "ng-zorro-antd/resizable"; import { calculateTotalTranslate3d } from "../../../common/util/panel-dock"; @@ -171,7 +171,6 @@ export class PropertyEditorComponent implements OnInit, OnDestroy, OnChanges { const [xOffset, yOffset, _] = calculateTotalTranslate3d(container.style.transform); this.returnPosition = { x: -xOffset, y: -yOffset }; } - this.registerHighlightEventsHandler(); // The toolbar's "choose fields" toggle lives in the service so both the canvas toolbar // and this panel see the same state. Re-emit the frame's inputs when it changes, so tick // boxes appear and disappear without needing a re-selection. @@ -187,6 +186,10 @@ export class PropertyEditorComponent implements OnInit, OnDestroy, OnChanges { // Rebuild the frame so the tick boxes appear/disappear (see remountOperatorFrame). this.remountOperatorFrame(); }); + // After the toggle above has replayed its current value: the frame this may build on mount + // takes `choosing` from it, and building first would have the replay tear the frame down and + // rebuild it inside the page's first change-detection pass. + this.registerHighlightEventsHandler(); this.panelService.closePanelStream.pipe(untilDestroyed(this)).subscribe(() => this.closePanel()); this.panelService.resetPanelStream.pipe(untilDestroyed(this)).subscribe(() => { this.resetPanelPosition(); @@ -257,13 +260,23 @@ export class PropertyEditorComponent implements OnInit, OnDestroy, OnChanges { } /** - * This method changes the property editor according to how operators are highlighted on the workflow editor. - * - * Displays the form of the highlighted operator if only one operator is highlighted; - * Displays the form of the link breakpoint if only one link is highlighted; - * hides the form if no operator/link is highlighted or multiple operators and/or links are highlighted. + * Shows the selection the panel mounts into, then follows every change to it: one operator or + * one port opens its frame, anything else (nothing, several things, a link) shows no frame. */ registerHighlightEventsHandler() { + // The selection outlives this panel: it lives in the graph wrapper, which both views of a + // workflow share and hand over between them, so a panel mounting into an existing selection + // never sees the event that made it. Show it now, then follow the changes -- otherwise the + // panel looks empty until the selection changes, and clicking the very step it should be + // showing is a no-op (an already-highlighted element emits nothing). Only when something is + // selected: a fresh mount has no frame to clear, and the no-frame branch is for a selection + // being dropped (it clears the editing marker and resizes the docked panel to its empty + // content), which a mount must not do. A link or a comment box alone leaves the panel as it + // mounted, empty -- what the branch would have shown anyway. + const wrapper = this.workflowActionService.getJointGraphWrapper(); + if (wrapper.getCurrentHighlightedOperatorIDs().length > 0 || wrapper.getCurrentHighlightedPortIDs().length > 0) { + this.showHighlighted(); + } merge( this.workflowActionService.getJointGraphWrapper().getJointOperatorHighlightStream(), this.workflowActionService.getJointGraphWrapper().getJointOperatorUnhighlightStream(), @@ -274,40 +287,44 @@ export class PropertyEditorComponent implements OnInit, OnDestroy, OnChanges { this.workflowActionService.getJointGraphWrapper().getJointPortHighlightStream(), this.workflowActionService.getJointGraphWrapper().getJointPortUnhighlightStream() ) - .pipe( - filter(() => this.workflowActionService.getTexeraGraph().getSyncTexeraGraph()), - untilDestroyed(this) - ) - .subscribe(_ => { - const highlightedOperators = this.workflowActionService - .getJointGraphWrapper() - .getCurrentHighlightedOperatorIDs(); - const highlightLinks = this.workflowActionService.getJointGraphWrapper().getCurrentHighlightedLinkIDs(); - this.workflowActionService.getJointGraphWrapper().getCurrentHighlightedCommentBoxIDs(); - const highlightedPorts = this.workflowActionService.getJointGraphWrapper().getCurrentHighlightedPortIDs(); + .pipe(untilDestroyed(this)) + .subscribe(_ => this.showHighlighted()); + } - if (highlightedOperators.length === 1 && highlightLinks.length === 0 && highlightedPorts.length === 0) { - this.currentComponent = OperatorPropertyEditFrameComponent; - this.componentInputs = { - currentOperatorId: highlightedOperators[0], - exposeChoosing: this.choosing, - actsAsEditor: this.actsAsEditor, - }; - } else if (highlightedPorts.length === 1 && highlightLinks.length === 0) { - this.currentComponent = PortPropertyEditFrameComponent; - this.componentInputs = { currentPortID: highlightedPorts[0] }; - } else { - this.currentComponent = null; - this.componentInputs = {}; - // Same gate as the frame's own broadcast: a viewer mount publishes nothing on the - // shared awareness channel, in either direction. - if (this.actsAsEditor) { - this.workflowActionService.getTexeraGraph().updateSharedModelAwareness("currentlyEditing", undefined); - } - } - this.changeDetectorRef.detectChanges(); - this.updateHeightBasedOnContent(); - }); + /** + * Show whatever the shared selection holds right now: one operator, one port, or nothing. Not + * while the graph is mid-sync with the shared model: the highlight set is then in flux and would + * be read again when the sync ends. + */ + private showHighlighted(): void { + if (!this.workflowActionService.getTexeraGraph().getSyncTexeraGraph()) { + return; + } + const highlightedOperators = this.workflowActionService.getJointGraphWrapper().getCurrentHighlightedOperatorIDs(); + const highlightedLinks = this.workflowActionService.getJointGraphWrapper().getCurrentHighlightedLinkIDs(); + const highlightedPorts = this.workflowActionService.getJointGraphWrapper().getCurrentHighlightedPortIDs(); + + if (highlightedOperators.length === 1 && highlightedLinks.length === 0 && highlightedPorts.length === 0) { + this.currentComponent = OperatorPropertyEditFrameComponent; + this.componentInputs = { + currentOperatorId: highlightedOperators[0], + exposeChoosing: this.choosing, + actsAsEditor: this.actsAsEditor, + }; + } else if (highlightedPorts.length === 1 && highlightedLinks.length === 0) { + this.currentComponent = PortPropertyEditFrameComponent; + this.componentInputs = { currentPortID: highlightedPorts[0] }; + } else { + this.currentComponent = null; + this.componentInputs = {}; + // Same gate as the frame's own broadcast: a viewer mount publishes nothing on the + // shared awareness channel, in either direction. + if (this.actsAsEditor) { + this.workflowActionService.getTexeraGraph().updateSharedModelAwareness("currentlyEditing", undefined); + } + } + this.changeDetectorRef.detectChanges(); + this.updateHeightBasedOnContent(); } onResize({ width, height }: NzResizeEvent) { cancelAnimationFrame(this.id); diff --git a/frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.spec.ts b/frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.spec.ts index 641c646dac..4dc5df7a75 100644 --- a/frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.spec.ts +++ b/frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.spec.ts @@ -499,6 +499,25 @@ describe("WorkflowEditorComponent", () => { expect(model.attr(".add-input-port-button/visibility")).toBe("hidden"); expect(model.attr(".texera-operator-state/visibility")).toBe("visible"); }); + + // The selection lives in the wrapper, which both views of a workflow share and hand over + // between them, while this paper is new on every switch: a paper that only followed the + // highlight stream left the step the other view had selected drawn as not selected, beside a + // panel showing it. The highlight handler is re-run here, which is what a new paper wiring + // itself into the same shared selection comes down to. + it("rings the operators the shared selection already holds when the paper wires itself up", () => { + const workflowActionService = TestBed.inject(WorkflowActionService); + workflowActionService.addOperator(mockScanPredicate, mockPoint); + workflowActionService.getJointGraphWrapper().highlightOperators(mockScanPredicate.operatorID); + const view = component.paper.findViewByModel(mockScanPredicate.operatorID); + // Installed after the stream has done its work, so only the wiring-up pass is counted. + const highlight = vi.spyOn(view, "highlight"); + + (component as unknown as { handleElementHightlightEvent: () => void }).handleElementHightlightEvent(); + + expect(highlight).toHaveBeenCalledTimes(1); + expect(highlight).toHaveBeenCalledWith("rect.body", expect.anything()); + }); }); /** diff --git a/frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.ts b/frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.ts index 023f2624da..04a19bb005 100644 --- a/frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.ts +++ b/frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.ts @@ -1118,14 +1118,21 @@ export class WorkflowEditorComponent implements OnInit, AfterViewInit, OnDestroy }, }; + const ring = (elementID: string) => + this.paper.findViewByModel(elementID)?.highlight("rect.body", { highlighter: highlightOptions }); + + // The selection outlives this paper: it lives in the wrapper, which both views of a workflow + // share and hand over between them, while the paper is new on every switch. Ring what is + // selected now, or the view arriving at a selection would show its panel for a step drawn as + // not selected; then follow the changes. + [...this.wrapper.getCurrentHighlightedOperatorIDs(), ...this.wrapper.getCurrentHighlightedCommentBoxIDs()].forEach( + ring + ); + // highlight on OperatorHighlightStream or CommentBoxHighlightStream merge(this.wrapper.getJointOperatorHighlightStream(), this.wrapper.getJointCommentBoxHighlightStream()) .pipe(untilDestroyed(this)) - .subscribe(elementIDs => - elementIDs.forEach(elementID => { - this.paper.findViewByModel(elementID).highlight("rect.body", { highlighter: highlightOptions }); - }) - ); + .subscribe(elementIDs => elementIDs.forEach(ring)); // unhighlight on OperatorUnhighlightStream or CommentBoxUnhighlightStream merge(this.wrapper.getJointOperatorUnhighlightStream(), this.wrapper.getJointCommentBoxUnhighlightStream()) diff --git a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.html b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.html index 8eb83f29b5..a142107331 100644 --- a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.html +++ b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.html @@ -468,10 +468,9 @@ inert mount and turns live when the run ends. The panel's own tab stop goes away with inert, so it does not sit in front of the form it now contains. persistPlacement stays off either way (this is not the docked canvas panel). - [hidden], not *ngIf: the property editor shows its operator by REACTING to the highlight - stream (no initial pull), so it must already be mounted and subscribed when the click - highlights a step. Mounting it on selection (*ngIf) subscribes too late, misses that - emission, and the panel opens empty. So keep it mounted and just hide it. --> + [hidden], not *ngIf: one mounted panel keeps its subscriptions, its frame and its size + across selections, where mounting it per step (*ngIf) would rebuild all of that on + every click. So keep it mounted and just hide it. --> <div class="panel" role="group" diff --git a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.spec.ts b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.spec.ts index 0cd2ac4b20..bd74299136 100644 --- a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.spec.ts +++ b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.spec.ts @@ -2657,6 +2657,36 @@ describe("WorkflowFormComponent", () => { expect(workflowActionService.setHighlightingEnabled).toHaveBeenCalledWith(true); }); + // The selection is the canvas's too: the wrapper holding it is handed over, not rebuilt, when + // the views switch. A step chosen on the canvas is therefore already selected on arrival here, + // and no stream will say so -- the panel stayed shut until the reader clicked a DIFFERENT step + // (clicking the selected one emits nothing). + it("opens the panel for the step the canvas had selected, with no click of its own", () => { + withOp(); + h.highlightedIds.push("op-1"); + + build(formViewWorkflow).ngOnInit(); + + expect(component.selectedOperatorId).toBe("op-1"); + }); + + it("arrives with no panel when the canvas had nothing, or more than one step, selected", () => { + withOp(); + h.hasOperatorIds.add("op-2"); + h.graphOperators.push({ operatorID: "op-2", operatorType: "Filter" }); + // Seeded with a stale id, so a read that never happened would not pass as "undefined". + let c = build(formViewWorkflow); + c.selectedOperatorId = "op-1"; + c.ngOnInit(); + expect(c.selectedOperatorId).toBeUndefined(); + + h.highlightedIds.push("op-1", "op-2"); + c = build(formViewWorkflow); + c.selectedOperatorId = "op-1"; + c.ngOnInit(); + expect(c.selectedOperatorId).toBeUndefined(); + }); + it("opens the read-only panel for the clicked step", () => { build(formViewWorkflow).ngOnInit(); withOp(); diff --git a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.ts b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.ts index 06af03b12e..4c493ec71d 100644 --- a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.ts +++ b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.ts @@ -367,6 +367,10 @@ export class WorkflowFormComponent implements OnInit, OnDestroy { .pipe(untilDestroyed(this)) .subscribe(() => this.syncSelectionFromHighlight()); + // And once now: the selection is the canvas's too, handed over rather than rebuilt when the + // views switch, so a step chosen there is already selected here and no event will say so. + this.syncSelectionFromHighlight(); + // A result changing bumps that operator's version (so its chart frame is rebuilt, not reused), // re-limits what the form shows to the currently-viewed set, and re-fits the visualisations. this.workflowResultService
