gr-change-actions: Use change-model for setting editBasedOnCurrentPatchSet and editPatchsetLoaded

Also fixes an issue where if you go directly to a patchnum for instance
/5 and click edit then click "restore" on a file, the change edit wouldn't
show either in the change actions or in the file list.

This is because we only look at latest patchnum if the patchnum is
not set. Thus editPatchsetLoaded in gr-change-actions doesn't
get set properly.

We fix that by erasing the patchnum when either deleting or restoring.
We had already set it for when renaming or when uploading.

Release-Notes: skip
Change-Id: Ic866cb85996a469af7662a5a5a81db2f84f7e124
(cherry picked from commit d22af55c6972ce065fd0aac18dd014ae3d3d0657)
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts
index 11269ed..524578e 100644
--- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts
+++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts
@@ -20,7 +20,10 @@
 import {navigationToken} from '../../core/gr-navigation/gr-navigation';
 import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader';
 import {getAppContext} from '../../../services/app-context';
-import {CURRENT} from '../../../utils/patch-set-util';
+import {
+  CURRENT,
+  hasEditBasedOnCurrentPatchSet,
+} from '../../../utils/patch-set-util';
 import {
   changeIsOpen,
   isOwner,
@@ -526,13 +529,15 @@
   // private but used in test
   @state() disabledMenuActions: string[] = [];
 
-  @property({type: Boolean})
+  // private but used in test
+  @state()
   editPatchsetLoaded = false;
 
   @property({type: Boolean})
   editMode = false;
 
-  @property({type: Boolean})
+  // private but used in test
+  @state()
   editBasedOnCurrentPatchSet = true;
 
   @property({type: Boolean})
@@ -557,6 +562,16 @@
       () => this.getChangeModel().latestPatchNum$,
       x => (this.latestPatchNum = x)
     );
+    subscribe(
+      this,
+      () => this.getChangeModel().patchsets$,
+      x => (this.editBasedOnCurrentPatchSet = hasEditBasedOnCurrentPatchSet(x))
+    );
+    subscribe(
+      this,
+      () => this.getChangeModel().patchNum$,
+      x => (this.editPatchsetLoaded = x === 'edit')
+    );
   }
 
   override connectedCallback() {
diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts
index 5a0f3bb..27c36ba 100644
--- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts
+++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts
@@ -57,8 +57,6 @@
   computeLatestPatchNum,
   findEdit,
   findEditParentRevision,
-  hasEditBasedOnCurrentPatchSet,
-  hasEditPatchsetLoaded,
   PatchSet,
 } from '../../../utils/patch-set-util';
 import {
@@ -1402,13 +1400,7 @@
         .changeStatus=${this.change?.status}
         .commitNum=${this.commitInfo?.commit}
         .commitMessage=${this.latestCommitMessage}
-        .editPatchsetLoaded=${this.patchRange
-          ? hasEditPatchsetLoaded(this.patchRange)
-          : false}
         .editMode=${this.getEditMode()}
-        .editBasedOnCurrentPatchSet=${hasEditBasedOnCurrentPatchSet(
-          this.allPatchSets ?? []
-        )}
         .privateByDefault=${this.projectConfig?.private_by_default}
         .loggedIn=${this.loggedIn}
         @edit-tap=${() => this.handleEditTap()}
diff --git a/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls.ts b/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls.ts
index a273a3e..c0dd00b 100644
--- a/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls.ts
+++ b/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls.ts
@@ -472,7 +472,7 @@
           return;
         }
         this.closeDialog(dialog);
-        fireReload(this);
+        fireReload(this, true);
       });
   };
 
@@ -490,7 +490,7 @@
           return;
         }
         this.closeDialog(dialog);
-        fireReload(this);
+        fireReload(this, true);
       });
   };