yangzhang75 commented on code in PR #8456:
URL: https://github.com/apache/texera/pull/8456#discussion_r4001152665


##########
frontend/src/app/workspace/component/menu/menu.component.ts:
##########
@@ -617,14 +628,94 @@ export class MenuComponent implements OnInit, OnDestroy {
   }
 
   public onClickExportWorkflow(): void {
-    const workflowContent: WorkflowContent = 
this.workflowActionService.getWorkflowContent();
-    const workflowContentJson = JSON.stringify(workflowContent, null, 2);
-    const fileName = this.currentWorkflowName + ".json";
-    // Through the injectable wrapper (as the dashboard downloads already do), 
so a spec stubs it
-    // with TestBed instead of module-mocking the CommonJS file-saver package, 
which the unit-test
-    // builder cannot hoist reliably.
-    this.fileSaverService.saveAs(new Blob([workflowContentJson], { type: 
"text/plain;charset=utf-8" }), fileName);
+    // The same shape the dashboard download produces (see exportedWorkflow): 
the content plus the
+    // landing view as a sibling key, so a file exported here uploads as a 
form-default workflow too.
+    // The content is what is on screen at the click; the landing view is read 
from the row now,
+    // not from this page's copy, since it is set from the dashboard and may 
have changed since load.
+    const content = this.workflowActionService.getWorkflowContent();
+    const { wid, defaultView } = 
this.workflowActionService.getWorkflowMetadata();
+    this.workflowPersistService
+      .currentDefaultView(wid, defaultView)

Review Comment:
   Agreed, reverted: Export is instant again and reads the page's copy of the 
landing view, which every save's response refreshes. `currentDefaultView` is 
gone.



##########
frontend/src/app/common/service/workflow-persist/workflow-persist.service.ts:
##########
@@ -301,4 +339,24 @@ export class WorkflowPersistService {
   public setDefaultView(wid: number, view: DefaultView): Observable<void> {
     return 
this.http.put<void>(`${AppSettings.getApiEndpoint()}/${WORKFLOW_SET_DEFAULT_VIEW_URL}/${wid}`,
 { view });
   }
+
+  /**
+   * The landing view as the workflow row holds it now, for an export taken 
from an open page (the
+   * canvas or the form). The page's own copy dates from its load, while the 
default is set from the
+   * dashboard and may have changed since; whichever page the file is saved 
from, it should carry the
+   * default of that moment. The page's copy is the fallback when the row 
cannot be read, and the
+   * answer outright for a workflow not saved yet.
+   */
+  public currentDefaultView(
+    wid: number | undefined,
+    fallback: DefaultView | undefined
+  ): Observable<DefaultView | undefined> {
+    if (wid === undefined) {
+      return of(fallback);
+    }

Review Comment:
   Moot: `currentDefaultView` was removed (see the thread on 
menu.component.ts:638); the export no longer issues a request.



##########
frontend/src/app/workspace/component/menu/menu.component.ts:
##########
@@ -617,14 +628,94 @@ export class MenuComponent implements OnInit, OnDestroy {
   }
 
   public onClickExportWorkflow(): void {
-    const workflowContent: WorkflowContent = 
this.workflowActionService.getWorkflowContent();
-    const workflowContentJson = JSON.stringify(workflowContent, null, 2);
-    const fileName = this.currentWorkflowName + ".json";
-    // Through the injectable wrapper (as the dashboard downloads already do), 
so a spec stubs it
-    // with TestBed instead of module-mocking the CommonJS file-saver package, 
which the unit-test
-    // builder cannot hoist reliably.
-    this.fileSaverService.saveAs(new Blob([workflowContentJson], { type: 
"text/plain;charset=utf-8" }), fileName);
+    // The same shape the dashboard download produces (see exportedWorkflow): 
the content plus the
+    // landing view as a sibling key, so a file exported here uploads as a 
form-default workflow too.
+    // The content is what is on screen at the click; the landing view is read 
from the row now,
+    // not from this page's copy, since it is set from the dashboard and may 
have changed since load.
+    const content = this.workflowActionService.getWorkflowContent();
+    const { wid, defaultView } = 
this.workflowActionService.getWorkflowMetadata();
+    this.workflowPersistService
+      .currentDefaultView(wid, defaultView)
+      .pipe(untilDestroyed(this))
+      .subscribe(current => {
+        const workflowContentJson = JSON.stringify(exportedWorkflow(content, 
current), null, 2);
+        const fileName = this.currentWorkflowName + ".json";
+        // Through the injectable wrapper (as the dashboard downloads already 
do), so a spec stubs it
+        // with TestBed instead of module-mocking the CommonJS file-saver 
package, which the unit-test
+        // builder cannot hoist reliably.
+        this.fileSaverService.saveAs(new Blob([workflowContentJson], { type: 
"text/plain;charset=utf-8" }), fileName);
+      });
+  }
+
+  /**
+   * Open the Form View -- a full page load, not a route: the two views share 
root-level
+   * singletons (graph, Yjs shared model), and routing left the old 
collaboration client
+   * alive (you appeared as your own coeditor). A fresh document is the clean 
handover.
+   */
+  public onClickOpenFormView(): void {
+    const wid = this.workflowActionService.getWorkflowMetadata().wid;
+    if (wid === undefined || this.handingOverToFormView) {
+      return;

Review Comment:
   Done: the hand-over opens the id the save answers with, so a never-saved 
workflow (default id 0) is created by the switch's save and the form opens on 
the created id, as the autosave already moves the URL to it. Spec: "hands over 
to the id the save assigned when the canvas held a workflow never saved yet".



##########
frontend/src/app/workspace/component/menu/menu.component.ts:
##########
@@ -219,6 +223,13 @@ export class MenuComponent implements OnInit, OnDestroy {
   }
 
   public ngOnInit(): void {
+    // Marks an edit for the Form View hand-over (see onClickOpenFormView): 
set the moment an edit is
+    // reported, before the autosave debounce, cleared when the switch's save 
snapshots the workflow.
+    this.workflowActionService
+      .workflowChanged()
+      .pipe(untilDestroyed(this))
+      .subscribe(() => (this.editedSinceSwitchSnapshot = true));

Review Comment:
   Right, and this is the metadata-edit case deferred on the earlier review 
(thread on menu.component.ts:692): the rule that a newer local edit must not be 
overtaken belongs in `WorkflowPersistService` for every caller, and is being 
filed as its own item rather than grown here.



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