Merge branch 'main' into avm99963-monorail

Merged commit cd4b3b336f1f14afa02990fdc2eec5d9467a827e

GitOrigin-RevId: e67bbf185d5538e1472bb42e0abb2a141f88bac1
diff --git a/static_src/elements/issue-detail/metadata/mr-edit-metadata/mr-edit-issue.js b/static_src/elements/issue-detail/metadata/mr-edit-metadata/mr-edit-issue.js
index 69ef43f..d9cec5e 100644
--- a/static_src/elements/issue-detail/metadata/mr-edit-metadata/mr-edit-issue.js
+++ b/static_src/elements/issue-detail/metadata/mr-edit-metadata/mr-edit-issue.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-import {LitElement, html} from 'lit-element';
+import {LitElement, html, css} from 'lit-element';
 import debounce from 'debounce';
 
 import {store, connectStore} from 'reducers/base.js';
@@ -37,11 +37,66 @@
       blockingRefs = blockingRefs.concat(issue.danglingBlockingRefs);
     }
 
+    let migratedNotice = html``;
+    if (this._isMigrated) {
+      migratedNotice = html`
+        <div class="migrated-banner">
+          <i
+            class="warning-icon material-icons"
+            icon="warning"
+          >warning</i>
+          <p>
+            This issue has moved to
+            ${this._migratedLink}. Updates should be posted in
+            ${this._migratedLink}.
+          </p>
+        </div>
+        <chops-button
+          class="legacy-edit"
+          @click=${this._allowLegacyEdits}
+        >
+          I want to edit the old version of this issue.
+        </chops-button>
+      `;
+    }
+
     return html`
+      <link href="https://fonts.googleapis.com/icon?family=Material+Icons"
+        rel="stylesheet">
+      <style>
+        mr-edit-issue .migrated-banner {
+          width: 100%;
+          background-color: var(--chops-orange-50);
+          border: var(--chops-normal-border);
+          border-top: 0;
+          font-size: var(--chops-main-font-size);
+          padding: 0.25em 8px;
+          box-sizing: border-box;
+          display: flex;
+          flex-direction: row;
+          justify-content: flex-start;
+          align-items: center;
+          margin-bottom: 1em;
+        }
+        mr-edit-issue i.material-icons {
+          color: var(--chops-primary-icon-color);
+          font-size: var(--chops-icon-font-size);
+        }
+        mr-edit-issue .warning-icon {
+          margin-right: 4px;
+        }
+        mr-edit-issue .legacy-edit {
+          margin-bottom: 2em;
+        }
+      </style>
       <h2 id="makechanges" class="medium-heading">
         <a href="#makechanges">Add a comment and make changes</a>
       </h2>
+
+      ${migratedNotice}
+
       <mr-edit-metadata
+        ?hidden=${this._isMigrated && !this._editLegacyIssue}
         formName="Issue Edit"
         .ownerName=${this._ownerDisplayName(this.issue.ownerRef)}
         .cc=${issue.ccRefs}
@@ -69,6 +124,12 @@
   static get properties() {
     return {
       /**
+       * ID of an Issue Tracker issue that the issue migrated to.
+       */
+      migratedId: {
+        type: String,
+      },
+      /**
        * All comments, including descriptions.
        */
       comments: {
@@ -113,6 +174,9 @@
       _fieldDefs: {
         type: Array,
       },
+      _editLegacyIssue: {
+        type: Boolean,
+      },
     };
   }
 
@@ -124,6 +188,8 @@
     this.updateError = '';
 
     this.presubmitDebounceTimeOut = DEBOUNCED_PRESUBMIT_TIME_OUT;
+
+    this._editLegacyIssue = false;
   }
 
   /** @override */
@@ -144,6 +210,8 @@
 
   /** @override */
   stateChanged(state) {
+    this.migratedId = issueV0.migratedId(state);
+
     this.issue = issueV0.viewedIssue(state);
     this.issueRef = issueV0.viewedIssueRef(state);
     this.comments = issueV0.comments(state);
@@ -272,6 +340,28 @@
   }
 
   /**
+   * @return {boolean} Whether this issue is migrated or not.
+   */
+  get _isMigrated() {
+    return this.migratedId && this.migratedId !== '';
+  }
+
+  /**
+   * @return {string} the link of the issue in Issue Tracker.
+   */
+  get _migratedLink() {
+    return html`<a href="https://issuetracker.google.com/issues/${this.migratedId}">b/${this.migratedId}</a>`;
+  }
+
+  /**
+   * Let the user override th edit form being hidden, in case of mistakes or
+   * similar.
+   */
+  _allowLegacyEdits() {
+    this._editLegacyIssue = true;
+  }
+
+  /**
    * Gets the displayName of the owner. Only uses the displayName if a
    * userId also exists in the ref.
    * @param {UserRef} ownerRef The owner of the issue.