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