Fix rebase action in new change summary

Old gr-related-changes-list after running rest API getRelatedChanges,
calculates if change hasParent and set it by 2-way binding to
gr-change-view, which sends it to gr-change-actions.

Since lit-element doesn't have 2-way binding, we are moving call
rest API getRelatedChanges to gr-change-view, which is send to
gr-related-changes-list-experimental and calculates hasParent in
reload and sends it to gr-change-actions.

Change-Id: Ia702397c862e17b506d240d22698878b5bec6719
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 8f74f76..304939c 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
@@ -108,6 +108,9 @@
   QuickLabelInfo,
   ApprovalInfo,
   ElementPropertyDeepChange,
+  ChangeId,
+  RelatedChangeAndCommitInfo,
+  RelatedChangesInfo,
 } from '../../../types/common';
 import {DiffPreferencesInfo} from '../../../types/diff';
 import {GrReplyDialog, FocusTarget} from '../gr-reply-dialog/gr-reply-dialog';
@@ -2293,7 +2296,26 @@
       const relatedChangesLoaded = coreDataPromise.then(() => {
         this.getRelatedChangesList()?.reload();
         if (this._isNewChangeSummaryUiEnabled) {
-          this.getRelatedChangesListExperimental()?.reload();
+          let relatedChangesPromise:
+            | Promise<RelatedChangesInfo | undefined>
+            | undefined;
+          const patchNum = this._computeLatestPatchNum(this._allPatchSets);
+          if (this._change && patchNum) {
+            relatedChangesPromise = this.restApiService
+              .getRelatedChanges(this._change._number, patchNum)
+              .then(response => {
+                if (this._change && response) {
+                  this.hasParent = this._calculateHasParent(
+                    this._change.change_id,
+                    response.changes
+                  );
+                }
+                return response;
+              });
+          }
+          this.getRelatedChangesListExperimental()?.reload(
+            relatedChangesPromise
+          );
         }
       });
       allDataPromises.push(relatedChangesLoaded);
@@ -2310,6 +2332,21 @@
   }
 
   /**
+   * Determines whether or not the given change has a parent change. If there
+   * is a relation chain, and the change id is not the last item of the
+   * relation chain, there is a parent.
+   */
+  _calculateHasParent(
+    currentChangeId: ChangeId,
+    relatedChanges: RelatedChangeAndCommitInfo[]
+  ) {
+    return (
+      relatedChanges.length > 0 &&
+      relatedChanges[relatedChanges.length - 1].change_id !== currentChangeId
+    );
+  }
+
+  /**
    * Kicks off requests for resources that rely on the patch range
    * (`this._patchRange`) being defined.
    */
@@ -2780,7 +2817,7 @@
   /**
    * Wrapper for using in the element template and computed properties
    */
-  _computeLatestPatchNum(allPatchSets: PatchSet[]) {
+  _computeLatestPatchNum(allPatchSets?: PatchSet[]) {
     return computeLatestPatchNum(allPatchSets);
   }
 
diff --git a/polygerrit-ui/app/elements/change/gr-related-changes-list-experimental/gr-related-changes-list-experimental.ts b/polygerrit-ui/app/elements/change/gr-related-changes-list-experimental/gr-related-changes-list-experimental.ts
index fbbef12..11f0fd3 100644
--- a/polygerrit-ui/app/elements/change/gr-related-changes-list-experimental/gr-related-changes-list-experimental.ts
+++ b/polygerrit-ui/app/elements/change/gr-related-changes-list-experimental/gr-related-changes-list-experimental.ts
@@ -170,24 +170,25 @@
     };
   }
 
-  reload() {
+  reload(getRelatedChanges?: Promise<RelatedChangesInfo | undefined>) {
     if (!this.change) return Promise.reject(new Error('change missing'));
-    if (!this.patchNum) return Promise.reject(new Error('patchNum missing'));
     const promises: Array<Promise<void>> = [
       this.restApiService
-        .getRelatedChanges(this.change._number, this.patchNum)
-        .then(response => {
-          if (!response) {
-            throw new Error('getRelatedChanges returned undefined response');
-          }
-          this._relatedResponse = response;
-        }),
-      this.restApiService
         .getChangesSubmittedTogether(this.change._number)
         .then(response => {
           this._submittedTogether = response;
         }),
     ];
+    if (getRelatedChanges) {
+      promises.push(
+        getRelatedChanges.then(response => {
+          if (!response) {
+            throw new Error('getRelatedChanges returned undefined response');
+          }
+          this._relatedResponse = response;
+        })
+      );
+    }
 
     return Promise.all(promises);
   }