blob: e97f203cddcbc7266677bd7bddaa546b8036b9a9 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import page from 'page';
6import {LitElement, html, css} from 'lit-element';
7
8import {connectStore} from 'reducers/base.js';
9import * as issueV0 from 'reducers/issueV0.js';
10import 'elements/framework/mr-autocomplete/mr-autocomplete.js';
11import 'elements/chops/chops-button/chops-button.js';
12import 'elements/chops/chops-dialog/chops-dialog.js';
13import {SHARED_STYLES} from 'shared/shared-styles.js';
14import {prpcClient} from 'prpc-client-instance.js';
15
16export class MrMoveCopyIssue extends connectStore(LitElement) {
17 /** @override */
18 static get styles() {
19 return [
20 SHARED_STYLES,
21 css`
22 .target-project-dialog {
23 display: block;
24 font-size: var(--chops-main-font-size);
25 }
26 .error {
27 max-width: 100%;
28 color: red;
29 margin-bottom: 1em;
30 }
31 .edit-actions {
32 width: 100%;
33 margin: 0.5em 0;
34 text-align: right;
35 }
36 input {
37 box-sizing: border-box;
38 width: 95%;
39 padding: 0.25em 4px;
40 }
41 `,
42 ];
43 }
44
45 /** @override */
46 render() {
47 return html`
48 <link href="https://fonts.googleapis.com/icon?family=Material+Icons"
49 rel="stylesheet">
50 <chops-dialog closeOnOutsideClick>
51 <div class="target-project-dialog">
52 <h3 class="medium-heading">${this._action} issue</h3>
53 <div class="input-grid">
54 <label for="targetProjectInput">Target project:</label>
55 <div>
56 <input id="targetProjectInput" />
57 <mr-autocomplete
58 vocabularyName="project"
59 for="targetProjectInput"
60 ></mr-autocomplete>
61 </div>
62 </div>
63
64 ${this._targetProjectError ? html`
65 <div class="error">
66 ${this._targetProjectError}
67 </div>
68 ` : ''}
69
70 <div class="edit-actions">
71 <chops-button @click=${this.cancel} class="de-emphasized">
72 Cancel
73 </chops-button>
74 <chops-button @click=${this.save} class="emphasized">
75 ${this._action} issue
76 </chops-button>
77 </div>
78 </div>
79 </chops-dialog>
80 `;
81 }
82
83 /** @override */
84 static get properties() {
85 return {
86 issueRef: {type: Object},
87 _action: {type: String},
88 _targetProjectError: {type: String},
89 };
90 }
91
92 /** @override */
93 stateChanged(state) {
94 this.issueRef = issueV0.viewedIssueRef(state);
95 }
96
97 open(e) {
98 this.shadowRoot.querySelector('chops-dialog').open();
99 this._action = e.detail.action;
100 this.reset();
101 }
102
103 reset() {
104 this.shadowRoot.querySelector('#targetProjectInput').value = '';
105 this._targetProjectError = '';
106 }
107
108 cancel() {
109 this.shadowRoot.querySelector('chops-dialog').close();
110 }
111
112 save() {
113 const method = this._action + 'Issue';
114 prpcClient.call('monorail.Issues', method, {
115 issueRef: this.issueRef,
116 targetProjectName: this.shadowRoot.querySelector(
117 '#targetProjectInput').value,
118 }).then((response) => {
119 const projectName = response.newIssueRef.projectName;
120 const localId = response.newIssueRef.localId;
121 page(`/p/${projectName}/issues/detail?id=${localId}`);
122 this.cancel();
123 }, (error) => {
124 this._targetProjectError = error;
125 });
126 }
127}
128
129customElements.define('mr-move-copy-issue', MrMoveCopyIssue);