blob: 8e8626fb9128f6bf6abfc50447adbcd50f50a2ce [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 {html, css} from 'lit-element';
6import * as userV0 from 'reducers/userV0.js';
7import * as issueV0 from 'reducers/issueV0.js';
8import {store} from 'reducers/base.js';
9import 'elements/chops/chops-button/chops-button.js';
10import 'elements/chops/chops-dialog/chops-dialog.js';
11import {fromShortlink, GoogleIssueTrackerIssue} from 'shared/federated.js';
12import {MrCue} from './mr-cue.js';
13
14/**
15 * `<mr-fed-ref-cue>`
16 *
17 * Displays information and login/logout links for the federated references
18 * info popup.
19 *
20 */
21export class MrFedRefCue extends MrCue {
22 /** @override */
23 static get properties() {
24 return {
25 ...MrCue.properties,
26 fedRefShortlink: {type: String},
27 };
28 }
29
30 /** @override */
31 static get styles() {
32 return [
33 ...MrCue.styles,
34 css`
35 :host {
36 margin: 0;
37 width: 120px;
38 font-size: 11px;
39 }
40 `,
41 ];
42 }
43
44 get message() {
45 const fedRef = fromShortlink(this.fedRefShortlink);
46 if (fedRef && fedRef instanceof GoogleIssueTrackerIssue) {
47 let authLink;
48 if (this.user && this.user.gapiEmail) {
49 authLink = html`
50 <br /><br />
51 <a href="#"
52 @click=${() => store.dispatch(userV0.initGapiLogout())}
53 >Sign out</a>
54 <br />
55 (for references only)
56 `;
57 } else {
58 const clickLoginHandler = async () => {
59 await store.dispatch(userV0.initGapiLogin(this.issue));
60 // Re-fetch related issues.
61 store.dispatch(issueV0.fetchRelatedIssues(this.issue));
62 };
63 authLink = html`
64 <br /><br />
65 Googlers, to enable viewing status & title,
66 <a href="#"
67 @click=${clickLoginHandler}
68 >sign in here</a> with your Google email.
69 `;
70 }
71 return html`
72 This references an issue in the ${fedRef.trackerName} issue tracker.
73 ${authLink}
74 `;
75 } else {
76 return html`
77 This references an issue in another tracker. Status not displayed.
78 `;
79 }
80 }
81}
82
83customElements.define('mr-fed-ref-cue', MrFedRefCue);