kz930 commented on code in PR #9058:
URL: https://github.com/apache/texera/pull/9058#discussion_r4434553136


##########
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:
   Fixed in 7e4e75ff4. The card now closes on a native capture `pointerdown` on 
the paper, so pressing an output port closes it too. A pending card is 
cancelled as well.



##########
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:
   Fixed in 7e4e75ff4. The card subscribes to `getOperatorDeleteStream()` like 
the pinned windows do. Deleting its operator closes it and cancels a pending 
one, and deleting another operator leaves it open.



##########
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:
   Fixed in 7e4e75ff4. `ngOnDestroy` now clears both timers.



##########
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:
   Fixed in 7e4e75ff4. The card fetches again on its operator's result updates 
until it shows 5 rows, and keeps the shown rows while it does.



##########
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:
   Fixed in 7e4e75ff4. It now runs in `fakeAsync` and ticks past the delay, and 
it fails with the heat-map guard removed. I added the same test for the Layers 
> Result preview toggle.



##########
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:
   Fixed here instead of a separate PR, in 7e4e75ff4. The default is now 
`ALL_COLUMNS`, the same value `peekFirstRows` sends, and the row details modal 
gets its answer.



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