From 6d074c6ea4b22768e7735fcb81b0bf559be39ef9 Mon Sep 17 00:00:00 2001 From: Ben Rohlfs Date: Thu, 29 Apr 2021 13:43:18 +0200 Subject: [PATCH] Update all the plugin examples Change-Id: Idc6473377bb5966f0bc199bfc68977297df4f802 --- .../samples/add-from-favorite-reviewers.js | 3 +- polygerrit-ui/app/samples/bind-parameters.js | 12 +-- polygerrit-ui/app/samples/coverage-plugin.js | 76 ------------------- .../app/samples/extra-column-on-file-list.js | 3 +- polygerrit-ui/app/samples/lgtm-plugin.js | 5 +- polygerrit-ui/app/samples/repo-command.js | 53 ++++--------- polygerrit-ui/app/samples/some-screen.js | 12 +-- polygerrit-ui/app/samples/suggest-vote.js | 4 +- 8 files changed, 26 insertions(+), 142 deletions(-) delete mode 100644 polygerrit-ui/app/samples/coverage-plugin.js diff --git a/polygerrit-ui/app/samples/add-from-favorite-reviewers.js b/polygerrit-ui/app/samples/add-from-favorite-reviewers.js index 76b2787b84..1616ef3219 100644 --- a/polygerrit-ui/app/samples/add-from-favorite-reviewers.js +++ b/polygerrit-ui/app/samples/add-from-favorite-reviewers.js @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + /** * This plugin will a button to quickly add favorite reviewers to * reviewers in reply dialog. @@ -142,4 +143,4 @@ Gerrit.install(plugin => { 'reply-reviewers', ReviewerShortcut.is, {slot: 'right'}); plugin.registerCustomComponent( 'reply-reviewers', ReviewerShortcutContent.is, {slot: 'below'}); -}); \ No newline at end of file +}); diff --git a/polygerrit-ui/app/samples/bind-parameters.js b/polygerrit-ui/app/samples/bind-parameters.js index 30c7c3db90..4527a80114 100644 --- a/polygerrit-ui/app/samples/bind-parameters.js +++ b/polygerrit-ui/app/samples/bind-parameters.js @@ -14,15 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -// Element class exists in all browsers: -// https://developer.mozilla.org/en-US/docs/Web/API/Element -// Rename it to PolymerElement to avoid conflicts. Also, -// typescript reports the following error: -// error TS2451: Cannot redeclare block-scoped variable 'Element'. -const {html, Element: PolymerElement} = Polymer; - -class MyBindSample extends PolymerElement { +class MyBindSample extends Polymer.Element { static get is() { return 'my-bind-sample'; } static get properties() { @@ -39,7 +31,7 @@ class MyBindSample extends PolymerElement { } static get template() { - return html` + return Polymer.html` Template example: Patchset number [[revision._number]].
Computed example: [[computedExample]]. `; diff --git a/polygerrit-ui/app/samples/coverage-plugin.js b/polygerrit-ui/app/samples/coverage-plugin.js deleted file mode 100644 index 8d321c7eb4..0000000000 --- a/polygerrit-ui/app/samples/coverage-plugin.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - * @license - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -function populateWithDummyData(coverageData) { - coverageData['/COMMIT_MSG'] = { - linesMissingCoverage: [3, 4, 7, 14], - totalLines: 14, - changeNum: 94, - patchNum: 2, - }; - - // more coverage info on other files -} - -/** - * This plugin will add a toggler on file diff page to - * display fake coverage data. - * - * As the fake coverage data only provided for COMMIT_MSG file, - * so it will only work for COMMIT_MSG file diff. - */ -Gerrit.install(plugin => { - const coverageData = {}; - let displayCoverage = false; - const annotationApi = plugin.annotationApi(); - const styleApi = plugin.styles(); - - const coverageStyle = styleApi.css('background-color: #EF9B9B !important'); - const emptyStyle = styleApi.css(''); - - annotationApi.setLayer(context => { - if (Object.keys(coverageData).length === 0) { - // Coverage data is not ready yet. - return; - } - const path = context.path; - const line = context.line; - // Highlight lines missing coverage with this background color if - // coverage should be displayed, else do nothing. - const annotationStyle = displayCoverage - ? coverageStyle - : emptyStyle; - - // ideally should check to make sure its the same patch for same change - // for demo purpose, this is only checking to make sure we have fake data - if (coverageData[path]) { - const linesMissingCoverage = coverageData[path].linesMissingCoverage; - if (linesMissingCoverage.includes(line.afterNumber)) { - context.annotateRange(0, line.text.length, annotationStyle, 'right'); - context.annotateLineNumber(annotationStyle, 'right'); - } - } - }).enableToggleCheckbox('Display Coverage', checkbox => { - populateWithDummyData(coverageData); - checkbox.disabled = false; - checkbox.onclick = e => { - displayCoverage = e.target.checked; - Object.keys(coverageData).forEach(file => { - annotationApi.notify(file, 0, coverageData[file].totalLines, 'right'); - }); - }; - }); -}); diff --git a/polygerrit-ui/app/samples/extra-column-on-file-list.js b/polygerrit-ui/app/samples/extra-column-on-file-list.js index 2e37c01a99..c64bcd4b55 100644 --- a/polygerrit-ui/app/samples/extra-column-on-file-list.js +++ b/polygerrit-ui/app/samples/extra-column-on-file-list.js @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + /** * This plugin will an extra column to file list on change page to show * the first character of the path. @@ -74,4 +75,4 @@ Gerrit.install(plugin => { 'change-view-file-list-header-prepend', ColumnHeader.is); plugin.registerDynamicCustomComponent( 'change-view-file-list-content-prepend', ColumnContent.is); -}); \ No newline at end of file +}); diff --git a/polygerrit-ui/app/samples/lgtm-plugin.js b/polygerrit-ui/app/samples/lgtm-plugin.js index 9de1496171..537b1faea8 100644 --- a/polygerrit-ui/app/samples/lgtm-plugin.js +++ b/polygerrit-ui/app/samples/lgtm-plugin.js @@ -14,8 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + /** - * This plugin will +1 on Code-Review label if detect that you have + * This plugin will +1 on Code-Review label if it detects that you have * LGTM as start of your reply. */ Gerrit.install(plugin => { @@ -29,4 +30,4 @@ Gerrit.install(plugin => { replyApi.setLabelValue(label, '+1'); } }); -}); \ No newline at end of file +}); diff --git a/polygerrit-ui/app/samples/repo-command.js b/polygerrit-ui/app/samples/repo-command.js index 4f64059a6c..acecd7db69 100644 --- a/polygerrit-ui/app/samples/repo-command.js +++ b/polygerrit-ui/app/samples/repo-command.js @@ -15,14 +15,7 @@ * limitations under the License. */ -// Element class exists in all browsers: -// https://developer.mozilla.org/en-US/docs/Web/API/Element -// Rename it to PolymerElement to avoid conflicts. Also, -// typescript reports the following error: -// error TS2451: Cannot redeclare block-scoped variable 'Element'. -const {html, Element: PolymerElement} = Polymer; - -class RepoCommandLow extends PolymerElement { +class RepoCommandLow extends Polymer.Element { static get is() { return 'repo-command-low'; } static get properties() { @@ -32,20 +25,16 @@ class RepoCommandLow extends PolymerElement { } static get template() { - return html` - -

Low-level bork

- - Low-level bork - - `; + return Polymer.html` + +

Plugin Bork

+ Bork + `; } connectedCallback() { @@ -56,32 +45,16 @@ class RepoCommandLow extends PolymerElement { } _handleCommandTap() { - alert('(softly) bork, bork.'); + alert('bork'); } } -// register the custom component customElements.define(RepoCommandLow.is, RepoCommandLow); /** - * This plugin will add two new commands in command page for - * All-Projects. - * - * The added commands will simply alert you when click. + * This plugin adds a new command to the command page of the repo All-Projects. */ Gerrit.install(plugin => { - // High-level API - plugin.project() - .createCommand('Bork', (repoName, projectConfig) => { - if (repoName !== 'All-Projects') { - return false; - } - }) - .onTap(() => { - alert('Bork, bork!'); - }); - - // Low-level API plugin.registerCustomComponent( 'repo-command', 'repo-command-low'); }); diff --git a/polygerrit-ui/app/samples/some-screen.js b/polygerrit-ui/app/samples/some-screen.js index c600fe4ccc..8edaaa9538 100644 --- a/polygerrit-ui/app/samples/some-screen.js +++ b/polygerrit-ui/app/samples/some-screen.js @@ -15,14 +15,7 @@ * limitations under the License. */ -// Element class exists in all browsers: -// https://developer.mozilla.org/en-US/docs/Web/API/Element -// Rename it to PolymerElement to avoid conflicts. Also, -// typescript reports the following error: -// error TS2451: Cannot redeclare block-scoped variable 'Element'. -const {html, Element: PolymerElement} = Polymer; - -class SomeScreenMain extends PolymerElement { +class SomeScreenMain extends Polymer.Element { static get is() { return 'some-screen-main'; } static get properties() { @@ -32,7 +25,7 @@ class SomeScreenMain extends PolymerElement { } static get template() { - return html` + return Polymer.html` This is the main plugin screen at [[token]]