Add web links to project:<project>

Requsted on [1].

[1] https://groups.google.com/g/repo-discuss/c/hbvSHHM8sVQ

Change-Id: Iefda4bb5571d917d5fa9f24c02c8e4a3be2c6c52
(cherry picked from commit 01a7ba04a6f4e42a3898f538f176b131d26d7a05)
This commit is contained in:
Paladox none 2021-04-11 18:49:06 +00:00
parent 380117a3a1
commit 7b193168ad
3 changed files with 48 additions and 1 deletions

View File

@ -23,6 +23,8 @@ import {htmlTemplate} from './gr-repo-header_html';
import {GerritNav} from '../../core/gr-navigation/gr-navigation';
import {customElement, property} from '@polymer/decorators';
import {RepoName} from '../../../types/common';
import {WebLinkInfo} from '../../../types/diff';
import {appContext} from '../../../services/app-context';
@customElement('gr-repo-header')
class GrRepoHeader extends PolymerElement {
@ -36,12 +38,23 @@ class GrRepoHeader extends PolymerElement {
@property({type: String})
_repoUrl: string | null = null;
@property({type: Array})
_webLinks: WebLinkInfo[] = [];
private readonly restApiService = appContext.restApiService;
_repoChanged(repoName: RepoName) {
if (!repoName) {
this._repoUrl = null;
return;
}
this._repoUrl = GerritNav.getUrlForRepo(repoName);
this.restApiService.getRepo(repoName).then(repo => {
if (!repo?.web_links) return;
this._webLinks = repo.web_links;
});
}
}

View File

@ -18,6 +18,12 @@ import {html} from '@polymer/polymer/lib/utils/html-tag';
export const htmlTemplate = html`
<style include="shared-styles">
.browse {
display: inline-block;
font-weight: var(--font-weight-bold);
text-align: right;
width: 4em;
}
/* Workaround for empty style block - see https://github.com/Polymer/tools/issues/408 */
</style>
<style include="dashboard-header-styles">
@ -29,5 +35,13 @@ export const htmlTemplate = html`
</h1>
<hr />
<div><span>Detail:</span> <a href$="[[_repoUrl]]">Repo settings</a></div>
<span is="dom-if" if="[[_webLinks]]">
<div>
<span class="browse">Browse:</span>
<template is="dom-repeat" items="[[_webLinks]]" as="weblink">
<a target="_blank" href$="[[weblink.url]]">[[weblink.name]]</a>
</template>
</div>
</span>
</div>
`;

View File

@ -18,6 +18,7 @@
import '../../../test/common-test-setup-karma.js';
import './gr-repo-header.js';
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
import {stubRestApi} from '../../../test/test-utils.js';
const basicFixture = fixtureFromElement('gr-repo-header');
@ -36,5 +37,24 @@ suite('gr-repo-header tests', () => {
element.repo = 'test';
assert.equal(element._repoUrl, 'http://test.com/test');
});
});
test('webLinks set', () => {
const repoRes = {
web_links: [
{
name: 'gitiles',
url: 'https://gerrit.test/g',
},
],
};
stubRestApi('getRepo').returns(Promise.resolve(repoRes));
assert.deepEqual(element._webLinks, []);
element.repo = 'test';
flush(() => {
assert.deepEqual(element._webLinks, repoRes.web_links);
});
});
});