aglinxinyuan commented on code in PR #9058:
URL: https://github.com/apache/texera/pull/9058#discussion_r4418732193
##########
frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.ts:
##########
@@ -590,6 +608,77 @@ export class WorkflowEditorComponent implements OnInit,
AfterViewInit, OnDestroy
});
}
+ /**
+ * Shows the hovered operator's result preview beside it. Off when Layers >
Result preview is
+ * unchecked, and while the heat-map overlay is on, whose own tooltip
answers the hover then.
+ */
+ private handleResultPreviewHover(): void {
+ fromJointPaperEvent(this.paper, "element:mouseenter")
+ .pipe(untilDestroyed(this))
+ .subscribe(([elementView, evt]) => {
+ clearTimeout(this.previewHideTimer);
+ clearTimeout(this.previewShowTimer);
+ if (this.wrapper.getHeatmapView() !== null ||
!this.wrapper.isResultPreviewEnabled()) {
+ return;
+ }
+ const operatorId = elementView.model.id.toString();
+ // no preview while a button is held: the pointer is dragging an
operator or a link
+ if
(!this.workflowActionService.getTexeraGraph().hasOperator(operatorId) ||
isButtonHeld(evt)) {
+ return;
+ }
+ // Only a pointer that rests on the operator opens the card, so
passing over one does not.
+ this.previewShowTimer = setTimeout(() => {
+ this.resultPreview = { operatorId,
...this.operatorAnchor(operatorId) };
+ // JointJS paper events fire outside Angular's zone (see
handleHeatmapHover).
+ this.changeDetectorRef.detectChanges();
+ }, RESULT_PREVIEW_DELAY_MS);
+ });
+
+ fromJointPaperEvent(this.paper, "element:mouseleave")
+ .pipe(untilDestroyed(this))
+ .subscribe(() => {
+ clearTimeout(this.previewShowTimer);
+ this.hideResultPreviewSoon();
+ });
+
+ // A click or a drag on the canvas closes the card at once.
+ merge(fromJointPaperEvent(this.paper, "element:pointerdown"),
fromJointPaperEvent(this.paper, "blank:pointerdown"))
Review Comment:
Pressing an operator's output port to drag a link doesn't close the card.
JointJS's `dragMagnetStart` calls `evt.stopPropagation()`, so
`element:pointerdown` never fires here. An open card stays to the right of the
operator, where the downstream operator usually is, and so does a card whose
0.5 s timer is still pending. The card's `(mouseenter)` then keeps it open
while the link is dragged across it. We could close it on a capture-phase
`pointerdown` on the paper element instead.
##########
frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.ts:
##########
@@ -119,6 +132,10 @@ export class WorkflowEditorComponent implements OnInit,
AfterViewInit, OnDestroy
metricLabel: string;
heatLabel: string;
} | null = null;
+ // The hovered operator's result preview, and where to show it. Null when
hidden.
+ public resultPreview: { operatorId: string; x: number; y: number } | null =
null;
+ private previewShowTimer?: ReturnType<typeof setTimeout>;
+ private previewHideTimer?: ReturnType<typeof setTimeout>;
Review Comment:
`ngOnDestroy` should also clear `previewShowTimer` and `previewHideTimer`.
##########
frontend/src/app/workspace/component/workflow-editor/operator-result-preview/operator-result-preview.component.ts:
##########
@@ -0,0 +1,170 @@
+/**
+ * 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 { ChangeDetectorRef, Component, Input, OnChanges, SimpleChanges } from
"@angular/core";
+import { NgFor, NgIf } from "@angular/common";
+import { Subscription } from "rxjs";
+import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
+import { WorkflowActionService } from
"../../../service/workflow-graph/model/workflow-action.service";
+import { WorkflowResultService } from
"../../../service/workflow-result/workflow-result.service";
+import { WorkflowCompilingService } from
"../../../service/compile-workflow/workflow-compiling.service";
+import { ExecuteWorkflowService } from
"../../../service/execute-workflow/execute-workflow.service";
+import { WorkflowConsoleService } from
"../../../service/workflow-console/workflow-console.service";
+import { ExecutionState } from "../../../types/execute-workflow.interface";
+
+/** How many columns the preview shows before it says how many more there are.
*/
+export const PREVIEW_COLUMN_LIMIT = 6;
+/** How many rows the preview shows. */
+export const PREVIEW_ROW_LIMIT = 5;
+/** How many characters of a cell the preview shows; the rest is in the cell's
tooltip. */
+export const PREVIEW_CELL_LIMIT = 24;
+
+/** A cell as the preview prints it: short, and never "[object Object]". */
+export function formatPreviewCell(value: unknown): string {
+ if (value === null || value === undefined) return "";
+ const text = typeof value === "object" ? JSON.stringify(value) :
String(value);
+ return text.length > PREVIEW_CELL_LIMIT ? text.slice(0, PREVIEW_CELL_LIMIT -
1) + "…" : text;
+}
+
+export interface OperatorResultPreview {
+ title: string;
+ kind: "table" | "chart" | "error" | "none";
+ summary: string;
+ columns: readonly string[];
+ moreColumns: number;
+ detail?: string;
+}
+
+/**
+ * What hovering an operator on the canvas shows about its result: the first
rows of a table,
+ * that it drew a chart, its error, or why there is nothing. The rows are
fetched on their own
+ * request, which leaves the page the result table is on alone.
+ */
+@UntilDestroy()
+@Component({
+ selector: "texera-operator-result-preview",
+ templateUrl: "./operator-result-preview.component.html",
+ styleUrls: ["./operator-result-preview.component.scss"],
+ imports: [NgIf, NgFor],
+})
+export class OperatorResultPreviewComponent implements OnChanges {
+ @Input() operatorId = "";
+
+ // The first rows of a table result, one string per shown column; undefined
while they load.
+ rows: readonly (readonly string[])[] | undefined = undefined;
+ private rowsSubscription?: Subscription;
+
+ constructor(
+ private workflowActionService: WorkflowActionService,
+ private workflowResultService: WorkflowResultService,
+ private workflowCompilingService: WorkflowCompilingService,
+ private executeWorkflowService: ExecuteWorkflowService,
+ private workflowConsoleService: WorkflowConsoleService,
+ private changeDetectorRef: ChangeDetectorRef
+ ) {}
+
+ ngOnChanges(changes: SimpleChanges): void {
+ if (changes["operatorId"]) {
+ this.loadRows();
Review Comment:
Rows are fetched only when `operatorId` changes. Hover a running operator
before its first tuple and `rows` stays `[]`, while the summary's row count
keeps growing over an empty table. Fetching again on that operator's result
update would fix it.
##########
frontend/src/app/workspace/service/workflow-result/workflow-result.service.ts:
##########
@@ -239,6 +262,12 @@ export class OperatorResultService {
}
}
+/**
+ * A column limit that asks for every column. The server reads the limit as a
32-bit Int, so it is
+ * Int.MaxValue there; Number.MAX_SAFE_INTEGER fails to parse and the request
is never answered.
+ */
Review Comment:
Optional follow-up, not blocking: `selectPage` below still defaults
`columnLimit` to `Number.MAX_SAFE_INTEGER`, and the row-details modal's
`selectTuple` uses that default. On main today that request fails Jackson's
`Int` parse, and the catch in `WorkflowWebsocketResource` records it as a
`COMPILATION_ERROR`. Worth a separate small fix.
##########
frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.ts:
##########
@@ -590,6 +608,77 @@ export class WorkflowEditorComponent implements OnInit,
AfterViewInit, OnDestroy
});
}
+ /**
+ * Shows the hovered operator's result preview beside it. Off when Layers >
Result preview is
+ * unchecked, and while the heat-map overlay is on, whose own tooltip
answers the hover then.
+ */
+ private handleResultPreviewHover(): void {
+ fromJointPaperEvent(this.paper, "element:mouseenter")
+ .pipe(untilDestroyed(this))
+ .subscribe(([elementView, evt]) => {
+ clearTimeout(this.previewHideTimer);
+ clearTimeout(this.previewShowTimer);
+ if (this.wrapper.getHeatmapView() !== null ||
!this.wrapper.isResultPreviewEnabled()) {
+ return;
+ }
+ const operatorId = elementView.model.id.toString();
+ // no preview while a button is held: the pointer is dragging an
operator or a link
+ if
(!this.workflowActionService.getTexeraGraph().hasOperator(operatorId) ||
isButtonHeld(evt)) {
+ return;
+ }
+ // Only a pointer that rests on the operator opens the card, so
passing over one does not.
+ this.previewShowTimer = setTimeout(() => {
Review Comment:
Deleting the hovered operator leaves its card open, and its title falls back
to the raw id. A pending show timer opens it at `{0, 0}`. #9063 unpins windows
on `getOperatorDeleteStream()`, and the card needs the same.
##########
frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.spec.ts:
##########
@@ -374,6 +374,39 @@ describe("WorkflowEditorComponent", () => {
expect(linkView.hasTools()).toBe(false);
});
+ it("previews a hovered operator's result once the pointer rests, and hides
it when the pointer leaves", fakeAsync(() => {
+ addLinkedPair();
+ const view =
component.paper.findViewByModel(mockScanPredicate.operatorID);
+
+ component.paper.trigger("element:mouseenter", view, new
MouseEvent("mouseenter"));
+ // passing over an operator opens nothing; only a pointer that rests on
it does
+ tick(RESULT_PREVIEW_DELAY_MS - 1);
+ expect(component.resultPreview).toBeNull();
+ tick(1);
+ fixture.detectChanges();
+
expect(component.resultPreview?.operatorId).toBe(mockScanPredicate.operatorID);
+
expect(fixture.debugElement.query(By.css("texera-operator-result-preview"))).toBeTruthy();
+
+ component.paper.trigger("element:mouseleave", view, new
MouseEvent("mouseleave"));
+ // the card lingers a moment, so the pointer can cross into it
+ tick(RESULT_PREVIEW_HIDE_MS);
+ fixture.detectChanges();
+ expect(component.resultPreview).toBeNull();
+
expect(fixture.debugElement.query(By.css("texera-operator-result-preview"))).toBeNull();
+ }));
+
+ it("leaves the hover to the heat-map tooltip while that overlay is on", ()
=> {
Review Comment:
This passes with the guard removed. It checks `resultPreview` right after
`mouseenter`, before the 500 ms timer. It needs `fakeAsync` and a
`tick(RESULT_PREVIEW_DELAY_MS)`.
--
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]