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


##########
frontend/src/app/workspace/component/menu/menu.component.ts:
##########
@@ -617,15 +628,99 @@ export class MenuComponent implements OnInit, OnDestroy {
   }
 
   public onClickExportWorkflow(): void {
-    const workflowContent: WorkflowContent = 
this.workflowActionService.getWorkflowContent();
-    const workflowContentJson = JSON.stringify(workflowContent, null, 2);
+    // 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.
+    const exported = exportedWorkflow(
+      this.workflowActionService.getWorkflowContent(),
+      this.workflowActionService.getWorkflowMetadata().defaultView
+    );
+    const workflowContentJson = JSON.stringify(exported, 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;
+    }
+    // A reader has nothing to save, and every save of theirs is a guaranteed 
403 that would keep
+    // them here with an error: straight over, as the form's own switch does 
for a reader.
+    if (!this.writeAccess) {
+      this.openFormViewPage(wid);
+      return;
+    }
+    // Save first, and hand over only once the save has completed. The 
full-page load that
+    // follows unloads this document, and a request still in flight at that 
moment is aborted, so
+    // navigating right after firing the save could lose the very edit the 
switch is meant to carry
+    // across; the workspace's beforeunload save runs into the same unload and 
is no safety net. A
+    // save that fails keeps the user here with the error shown, rather than 
leaving with changes
+    // that were never stored. The form's own switch (openRegularCanvas) does 
the same.
+    //
+    // Two more things the hand-over must not lose. An autosave already in 
flight when the switch
+    // is clicked: WorkflowPersistService sends saves one at a time and in 
order, so ours lands after
+    // it and completes after it. And an edit made while our save is out (the 
page stays editable
+    // until the load): workflowChanged marks a graph edit, persistWorkflow a 
rename or a
+    // description edit (those save through the menu itself, not the 
autosave), and the drain below
+    // saves once more before handing over rather than letting the full-page 
load abort that edit's
+    // own save.
+    this.handingOverToFormView = true;
+    this.isSaving = true;
+    this.saveThenOpenFormView(wid);
+  }
+
+  private saveThenOpenFormView(wid: number): void {
+    // The snapshot below carries everything reported up to now.
+    this.editedSinceSwitchSnapshot = false;
+    this.workflowPersistService
+      .persistWorkflow(this.workflowActionService.getWorkflow())
+      .pipe(untilDestroyed(this))
+      .subscribe({
+        next: (updatedWorkflow: Workflow) => {
+          // An edit since the snapshot makes this response stale: applying it 
would put the old
+          // name back just before the save below re-reads the workflow. That 
save's own response
+          // is the one applied.
+          if (!this.editedSinceSwitchSnapshot) {
+            this.workflowActionService.setWorkflowMetadata(updatedWorkflow);

Review Comment:
   Agreed, and reverted: the switch is back to the reader early-return only; 
`persistWorkflow` no longer marks the hand-over and the switch's response is 
applied as before. The staleness rule (do not apply a response a newer local 
edit has overtaken, in `WorkflowPersistService` for every caller) is filed 
separately.



##########
frontend/src/app/dashboard/component/user/list-item/card-item/card-item.component.html:
##########
@@ -36,12 +36,31 @@
         [(ngModel)]="entry.checked"
         (ngModelChange)="onCheckboxChange(entry)"></label>
     </div>
-    <!-- Cover-image controls -->
+    <!-- Cover controls: the owner's image controls, and the default-view 
toggle for anyone with
+         write access (the same toggle the list row offers, so switching to 
the card view does not
+         lose it). -->
     <div
       class="card-image-controls"
-      *ngIf="canEditCover"
+      *ngIf="hasCoverControls"
       (click)="$event.stopPropagation()">
+      <!-- A toggle button: constant name, state in aria-pressed (a name that 
changed with the state
+           would announce the opposite of what the state says); the title 
spells out what a click does. -->
       <button
+        *ngIf="canToggleDefaultView"
+        nz-button
+        nzType="text"
+        class="image-control-btn default-view-toggle"

Review Comment:
   Done: `.card-item:focus-within .card-image-controls { opacity: 1 }`, so the 
cover controls show while any of them has the keyboard focus.



##########
frontend/src/app/dashboard/component/user/list-item/list-item.component.html:
##########
@@ -194,6 +195,26 @@
         nz-icon
         nzType="eye"></i>
     </button>
+    <!-- Setting the default view is a write on the workflow row (the endpoint 
requires WRITE), so a
+         read-only collaborator is not offered a control that could only fail 
(the handler checks
+         the same rule, canToggleDefaultView). -->
+    <!-- A toggle button: the name stays constant and aria-pressed carries the 
state (a name that
+         changed with the state would announce the opposite of what the state 
says); the title spells
+         out what a click does. -->
+    <button
+      *ngIf="canToggleDefaultView"
+      nz-button
+      nzType="text"
+      class="default-view-toggle"

Review Comment:
   Done: `.list-item-card:focus-within .button-group { display: flex }`. 
Tabbing into the row (its checkbox, rename, like) reveals the action group, and 
the next Tab moves into it; this applies to the whole group, whose other 
actions had the same gap.



##########
frontend/src/app/workspace/component/menu/menu.component.html:
##########
@@ -75,6 +75,30 @@
         <span *ngIf="!displayParticularWorkflowVersion"> {{autoSaveState}} 
</span>
       </div>
 
+      <!-- One workflow, two ways of working on it: the Canvas and the Form 
View. The
+           same control sits in the same place on both, so switching never 
means hunting
+           for a different affordance; the pressed segment is the view you are 
looking at.
+           Every workflow offers both views, so this shows wherever the 
feature flag is on. -->
+      <div
+        class="view-switch"
+        *ngIf="this.config.env.formViewEnabled && 
!displayParticularWorkflowVersion">

Review Comment:
   Right: the flag flip moved to #8528 (the stack's closing PR) after the 
split. The title is now "wire the Form View entry points" and the description 
says the flag stays off here and #8528 flips it.



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