summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--polygerrit-ui/app/.eslintrc.js13
-rw-r--r--polygerrit-ui/app/api/plugin.ts2
-rw-r--r--polygerrit-ui/app/api/suggestions.ts2
-rw-r--r--polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-change.ts40
-rw-r--r--polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts2
-rw-r--r--polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog_test.ts24
-rw-r--r--polygerrit-ui/app/elements/plugins/gr-suggestions-api/gr-suggestions-api.ts48
-rw-r--r--polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts5
-rw-r--r--polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.ts5
9 files changed, 99 insertions, 42 deletions
diff --git a/polygerrit-ui/app/.eslintrc.js b/polygerrit-ui/app/.eslintrc.js
index 7abc658393..e0fe3b5f5c 100644
--- a/polygerrit-ui/app/.eslintrc.js
+++ b/polygerrit-ui/app/.eslintrc.js
@@ -234,19 +234,6 @@ module.exports = {
],
},
- // List of allowed globals in all files
- globals: {
- // Polygerrit global variables.
- // You must not add anything new in this list!
- // Instead export variables from modules
- // TODO(dmfilippov): Remove global variables from polygerrit
- // Global variables from 3rd party libraries.
- // You should not add anything in this list, always try to import
- // If import is not possible - you can extend this list
- ShadyCSS: 'readonly',
- linkify: 'readonly',
- security: 'readonly',
- },
overrides: [
{
files: ['.eslintrc.js', '.eslintrc-bazel.js'],
diff --git a/polygerrit-ui/app/api/plugin.ts b/polygerrit-ui/app/api/plugin.ts
index 4aa3aaad36..684429a666 100644
--- a/polygerrit-ui/app/api/plugin.ts
+++ b/polygerrit-ui/app/api/plugin.ts
@@ -15,6 +15,7 @@ import {ChangeActionsPluginApi} from './change-actions';
import {RestPluginApi} from './rest';
import {HookApi, RegisterOptions} from './hook';
import {StylePluginApi} from './styles';
+import {SuggestionsPluginApi} from './suggestions';
export enum TargetElement {
CHANGE_ACTIONS = 'changeactions',
@@ -58,6 +59,7 @@ export declare interface PluginApi {
changeActions(): ChangeActionsPluginApi;
changeReply(): ChangeReplyPluginApi;
checks(): ChecksPluginApi;
+ suggestions(): SuggestionsPluginApi;
eventHelper(element: Node): EventHelperPluginApi;
getPluginName(): string;
hook<T extends HTMLElement>(
diff --git a/polygerrit-ui/app/api/suggestions.ts b/polygerrit-ui/app/api/suggestions.ts
index f75f6e0636..4038102150 100644
--- a/polygerrit-ui/app/api/suggestions.ts
+++ b/polygerrit-ui/app/api/suggestions.ts
@@ -19,7 +19,7 @@ export declare interface SuggestCodeRequest {
patchsetNumber: RevisionPatchSetNum;
filePath: string;
range?: CommentRange;
- lineNumber?: Number;
+ lineNumber?: number;
}
export declare interface SuggestionsProvider {
diff --git a/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-change.ts b/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-change.ts
index 9bd56bed2e..90b05f627b 100644
--- a/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-change.ts
+++ b/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-change.ts
@@ -3,7 +3,7 @@
* Copyright 2021 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
-import {LitElement, css, html, nothing} from 'lit';
+import {LitElement, css, html} from 'lit';
import {customElement, property} from 'lit/decorators.js';
import {sharedStyles} from '../../../styles/shared-styles';
import {
@@ -87,11 +87,10 @@ export class GrRelatedChange extends LitElement {
.submittableCheck {
padding-left: var(--spacing-s);
color: var(--positive-green-text-color);
- display: inline;
- width: 20px;
+ display: none;
}
- .submittableCheck.submittable:after {
- content: '✓';
+ .submittableCheck.submittable {
+ display: inline;
}
`,
];
@@ -103,14 +102,22 @@ export class GrRelatedChange extends LitElement {
const linkClass = this.computeLinkClass(change);
return html`
<div class="changeContainer">
- ${this.showSubmittableCheck ? this.renderSubmittableCheck() : nothing}
<a
href=${ifDefined(this.href)}
aria-label=${ifDefined(this.label)}
class=${linkClass}
><slot></slot
></a>
-
+ ${this.showSubmittableCheck
+ ? html`<span
+ tabindex="-1"
+ title="Submittable"
+ class="submittableCheck ${linkClass}"
+ role="img"
+ aria-label="Submittable"
+ >✓</span
+ >`
+ : ''}
${this.showChangeStatus
? html`<span class=${this.computeChangeStatusClass(change)}>
(${this.computeChangeStatus(change)})
@@ -120,25 +127,6 @@ export class GrRelatedChange extends LitElement {
`;
}
- private renderSubmittableCheck() {
- if (this.change?.submittable) {
- return html`<span
- tabindex="-1"
- title="Submittable"
- class="submittableCheck submittable"
- role="img"
- aria-label="Submittable"
- ></span>`;
- } else {
- // Empty place-holder to ensure that columns line up.
- return html`<span
- tabindex="-1"
- class="submittableCheck"
- role="img"
- ></span>`;
- }
- }
-
private computeLinkClass(change: ChangeInfo | RelatedChangeAndCommitInfo) {
const statuses = [];
if (change.status === ChangeStatus.ABANDONED) {
diff --git a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts
index fc4e74756c..1836f907c7 100644
--- a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts
+++ b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts
@@ -489,7 +489,7 @@ export class GrReplyDialog extends LitElement {
}
.edit-attention-button gr-icon {
color: inherit;
-
+ }
.attentionSummary .edit-attention-button gr-icon {
/* The line-height:26px hack (see below) requires us to do this.
Normally the gr-icon would account for a proper positioning
diff --git a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog_test.ts b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog_test.ts
index 5766d80762..7855834fcf 100644
--- a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog_test.ts
+++ b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog_test.ts
@@ -13,6 +13,7 @@ import {
query,
queryAll,
queryAndAssert,
+ stubReporting,
stubRestApi,
waitUntilVisible,
} from '../../../test/test-utils';
@@ -69,6 +70,7 @@ import {
} from '../../../models/comments/comments-model';
import {isOwner} from '../../../utils/change-util';
import {createNewPatchsetLevel} from '../../../utils/comment-util';
+import {Timing} from '../../../constants/reporting';
function cloneableResponse(status: number, text: string) {
return {
@@ -437,6 +439,28 @@ suite('gr-reply-dialog tests', () => {
);
});
+ test('save review fires sendReply metric', async () => {
+ const timeEndStub = stubReporting('timeEnd');
+
+ // Async tick is needed because iron-selector content is distributed and
+ // distributed content requires an observer to be set up.
+ await element.updateComplete;
+ element.patchsetLevelDraftMessage = 'I wholeheartedly disapprove';
+ element.draftCommentThreads = [createCommentThread([createComment()])];
+
+ element.includeComments = true;
+
+ // This is needed on non-Blink engines most likely due to the ways in
+ // which the dom-repeat elements are stamped.
+ await element.updateComplete;
+ queryAndAssert<GrButton>(element, '.send').click();
+
+ await interceptSaveReview();
+ await element.updateComplete;
+
+ await waitUntil(() => timeEndStub.calledWith(Timing.SEND_REPLY));
+ });
+
test('default to publishing draft comments with reply', async () => {
// Async tick is needed because iron-selector content is distributed and
// distributed content requires an observer to be set up.
diff --git a/polygerrit-ui/app/elements/plugins/gr-suggestions-api/gr-suggestions-api.ts b/polygerrit-ui/app/elements/plugins/gr-suggestions-api/gr-suggestions-api.ts
new file mode 100644
index 0000000000..400684900e
--- /dev/null
+++ b/polygerrit-ui/app/elements/plugins/gr-suggestions-api/gr-suggestions-api.ts
@@ -0,0 +1,48 @@
+/**
+ * @license
+ * Copyright 2023 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+import {PluginApi} from '../../../api/plugin';
+import {ReportingService} from '../../../services/gr-reporting/gr-reporting';
+import {PluginsModel} from '../../../models/plugins/plugins-model';
+import {
+ SuggestionsPluginApi,
+ SuggestionsProvider,
+} from '../../../api/suggestions';
+
+enum State {
+ NOT_REGISTERED,
+ REGISTERED,
+}
+
+/**
+ * Plugin API for suggestions.
+ *
+ * This object is returned to plugins that want to provide suggestions data.
+ * Plugins normally just call register() once at startup and then wait for
+ * suggestCode() being called on the provider interface.
+ */
+export class GrSuggestionsApi implements SuggestionsPluginApi {
+ private state = State.NOT_REGISTERED;
+
+ constructor(
+ private readonly reporting: ReportingService,
+ private readonly pluginsModel: PluginsModel,
+ readonly plugin: PluginApi
+ ) {
+ this.reporting.trackApi(this.plugin, 'suggestions', 'constructor');
+ }
+
+ register(provider: SuggestionsProvider): void {
+ this.reporting.trackApi(this.plugin, 'suggestions', 'register');
+ if (this.state === State.REGISTERED) {
+ throw new Error('Only one provider can be registered per plugin.');
+ }
+ this.state = State.REGISTERED;
+ this.pluginsModel.suggestionsRegister({
+ pluginName: this.plugin.getPluginName(),
+ provider,
+ });
+ }
+}
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
index e2229b5ce7..6ca47022c1 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -889,7 +889,10 @@ export class GrComment extends LitElement {
});
const replacement = suggestion.suggestions?.[0].replacement;
if (!replacement) return;
- this.messageText += `${USER_SUGGESTION_START_PATTERN}${suggestion}${'\n```'}`;
+ const addNewLine = this.messageText.length !== 0;
+ this.messageText += `${
+ addNewLine ? '\n' : ''
+ }${'```\n'}${replacement}${'\n```'}`;
}
private renderRobotActions() {
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.ts b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.ts
index 832b97efee..d3dea78cc4 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.ts
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.ts
@@ -37,6 +37,7 @@ import {RestApiService} from '../../../services/gr-rest-api/gr-rest-api';
import {PluginsModel} from '../../../models/plugins/plugins-model';
import {GrPluginStyleApi} from './gr-plugin-style-api';
import {StylePluginApi} from '../../../api/styles';
+import {GrSuggestionsApi} from '../../plugins/gr-suggestions-api/gr-suggestions-api';
const PLUGIN_NAME_NOT_SET = 'NULL';
@@ -214,6 +215,10 @@ export class Plugin implements PluginApi {
return new GrChecksApi(this.report, this.pluginsModel, this);
}
+ suggestions(): GrSuggestionsApi {
+ return new GrSuggestionsApi(this.report, this.pluginsModel, this);
+ }
+
reporting(): ReportingPluginApi {
return new GrReportingJsApi(this.report, this);
}