Skip to content

Commit 6fb6238

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[Freestyler] Ability to unclick a rating
This sends the correct Rating back to the Client effectively removing the user's rating. Also render Report issue even when rate buttons are not rendered. Bug: 377428838 Change-Id: I9d5b171cc12ebf70f2a117cfbf7a6aaf56fd596c Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5993738 Auto-Submit: Nikolay Vitkov <[email protected]> Reviewed-by: Alex Rudenko <[email protected]> Commit-Queue: Alex Rudenko <[email protected]> Reviewed-by: Ergün Erdoğmuş <[email protected]>
1 parent c588fc1 commit 6fb6238

File tree

4 files changed

+75
-53
lines changed

4 files changed

+75
-53
lines changed

front_end/core/host/AidaClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export enum Entity {
1616
}
1717

1818
export const enum Rating {
19+
SENTIMENT_UNSPECIFIED = 'SENTIMENT_UNSPECIFIED',
1920
POSITIVE = 'POSITIVE',
2021
NEGATIVE = 'NEGATIVE',
2122
}

front_end/panels/freestyler/components/FreestylerChatUi.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -737,14 +737,14 @@ export class FreestylerChatUi extends HTMLElement {
737737
// clang-format on
738738
}
739739

740-
const shouldShowSuggestions = (isLast && !this.#props.isLoading && message.suggestions);
741740
// clang-format off
742741
return html`
743-
<section class="chat-message answer" jslog=${VisualLogging.section('answer')}>
742+
<section
743+
class="chat-message answer"
744+
jslog=${VisualLogging.section('answer')}
745+
>
744746
<div class="message-info">
745-
<devtools-icon
746-
name="smart-assistant"
747-
></devtools-icon>
747+
<devtools-icon name="smart-assistant"></devtools-icon>
748748
<div class="message-name">
749749
<h2>${lockedString(UIStringsNotTranslate.ai)}</h2>
750750
</div>
@@ -758,14 +758,17 @@ export class FreestylerChatUi extends HTMLElement {
758758
});
759759
},
760760
)}
761-
${
762-
message.answer
763-
? html`<p>${this.#renderTextAsMarkdown(message.answer)}</p>`
764-
: LitHtml.nothing
765-
}
761+
${message.answer
762+
? html`<p>${this.#renderTextAsMarkdown(message.answer)}</p>`
763+
: LitHtml.nothing}
766764
${this.#renderError(message)}
767765
<div class="actions">
768-
${this.#renderUserActionRow(message.rpcId, shouldShowSuggestions ? message.suggestions : undefined)}
766+
${isLast && this.#props.isLoading
767+
? LitHtml.nothing
768+
: this.#renderUserActionRow(
769+
message.rpcId,
770+
isLast ? message.suggestions : undefined,
771+
)}
769772
</div>
770773
</section>
771774
`;

front_end/panels/freestyler/components/UserActionRow.ts

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ export class UserActionRow extends HTMLElement {
139139

140140
#handleRateClick(rating: Host.AidaClient.Rating): void {
141141
if (this.#currentRating === rating) {
142+
this.#currentRating = undefined;
143+
this.#isShowingFeedbackForm = false;
144+
// This effectively reset the user rating
145+
this.#props.onFeedbackSubmit(Host.AidaClient.Rating.SENTIMENT_UNSPECIFIED);
146+
this.#render();
142147
return;
143148
}
144149

@@ -168,36 +173,42 @@ export class UserActionRow extends HTMLElement {
168173
Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(REPORT_URL);
169174
};
170175

171-
#renderButtons(): LitHtml.TemplateResult {
176+
#renderButtons(): LitHtml.LitTemplate {
172177
// clang-format off
173-
return html`
174-
<devtools-button
175-
.data=${{
176-
variant: Buttons.Button.Variant.ICON,
177-
size: Buttons.Button.Size.SMALL,
178-
iconName: 'thumb-up',
179-
toggledIconName: 'thumb-up-filled',
180-
toggled: this.#currentRating === Host.AidaClient.Rating.POSITIVE,
181-
toggleType: Buttons.Button.ToggleType.PRIMARY,
182-
title: lockedString(UIStringsNotTranslate.thumbsUp),
183-
jslogContext: 'thumbs-up',
184-
} as Buttons.Button.ButtonData}
185-
@click=${() => this.#handleRateClick(Host.AidaClient.Rating.POSITIVE)}
186-
></devtools-button>
178+
const rateButtons = html`
187179
<devtools-button
188-
.data=${{
189-
variant: Buttons.Button.Variant.ICON,
190-
size: Buttons.Button.Size.SMALL,
191-
iconName: 'thumb-down',
192-
toggledIconName: 'thumb-down-filled',
193-
toggled: this.#currentRating === Host.AidaClient.Rating.NEGATIVE,
194-
toggleType: Buttons.Button.ToggleType.PRIMARY,
195-
title: lockedString(UIStringsNotTranslate.thumbsDown),
196-
jslogContext: 'thumbs-down',
197-
} as Buttons.Button.ButtonData}
198-
@click=${() => this.#handleRateClick(Host.AidaClient.Rating.NEGATIVE)}
199-
></devtools-button>
200-
<div class="vertical-separator"></div>
180+
.data=${{
181+
variant: Buttons.Button.Variant.ICON,
182+
size: Buttons.Button.Size.SMALL,
183+
iconName: 'thumb-up',
184+
toggledIconName: 'thumb-up-filled',
185+
toggled: this.#currentRating === Host.AidaClient.Rating.POSITIVE,
186+
toggleType: Buttons.Button.ToggleType.PRIMARY,
187+
title: lockedString(UIStringsNotTranslate.thumbsUp),
188+
jslogContext: 'thumbs-up',
189+
} as Buttons.Button.ButtonData}
190+
@click=${() => this.#handleRateClick(Host.AidaClient.Rating.POSITIVE)}
191+
></devtools-button>
192+
<devtools-button
193+
.data=${{
194+
variant: Buttons.Button.Variant.ICON,
195+
size: Buttons.Button.Size.SMALL,
196+
iconName: 'thumb-down',
197+
toggledIconName: 'thumb-down-filled',
198+
toggled: this.#currentRating === Host.AidaClient.Rating.NEGATIVE,
199+
toggleType: Buttons.Button.ToggleType.PRIMARY,
200+
title: lockedString(UIStringsNotTranslate.thumbsDown),
201+
jslogContext: 'thumbs-down',
202+
} as Buttons.Button.ButtonData}
203+
@click=${() => this.#handleRateClick(Host.AidaClient.Rating.NEGATIVE)}
204+
></devtools-button>
205+
<div class="vertical-separator"></div>`;
206+
// clang-format off
207+
208+
// clang-format off
209+
return html`
210+
<div class="rate-buttons">
211+
${this.#props.showRateButtons ? rateButtons : LitHtml.nothing}
201212
<devtools-button
202213
.data=${
203214
{
@@ -210,7 +221,7 @@ export class UserActionRow extends HTMLElement {
210221
}
211222
@click=${this.#handleReportClick}
212223
></devtools-button>
213-
`;
224+
</div>`;
214225
// clang-format on
215226
}
216227

@@ -240,6 +251,10 @@ export class UserActionRow extends HTMLElement {
240251
};
241252

242253
#renderFeedbackForm(): LitHtml.LitTemplate {
254+
if (!this.#isShowingFeedbackForm) {
255+
return LitHtml.nothing;
256+
}
257+
243258
// clang-format off
244259
return html`
245260
<form class="feedback-form" @submit=${this.#handleSubmit}>
@@ -295,11 +310,10 @@ export class UserActionRow extends HTMLElement {
295310
}
296311

297312
#renderSuggestions(): LitHtml.LitTemplate {
298-
// clang-format off
299313
if (!this.#props.suggestions) {
300314
return LitHtml.nothing;
301315
}
302-
316+
// clang-format off
303317
return html`<div class="suggestions-container">
304318
<div class="scroll-button-container left hidden" ${LitHtml.Directives.ref(this.#suggestionsLeftScrollButtonContainerRef)}>
305319
<devtools-button
@@ -347,15 +361,10 @@ export class UserActionRow extends HTMLElement {
347361
LitHtml.render(
348362
html`
349363
<div class="feedback">
350-
<div class="rate-buttons">
351-
${this.#props.showRateButtons ? this.#renderButtons() : LitHtml.nothing}
352-
</div>
353-
${this.#props.suggestions ? this.#renderSuggestions() : LitHtml.nothing}
364+
${this.#renderButtons()}
365+
${this.#renderSuggestions()}
354366
</div>
355-
${this.#isShowingFeedbackForm
356-
? this.#renderFeedbackForm()
357-
: LitHtml.nothing
358-
}
367+
${this.#renderFeedbackForm()}
359368
`,
360369
this.#shadow,
361370
{host: this},

front_end/panels/freestyler/components/userActionRow.css

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
display: flex;
1717
gap: var(--sys-size-8);
1818
justify-content: space-between;
19-
align-items: flex-end;
19+
align-items: center;
2020
}
2121

2222
.rate-buttons {
@@ -100,12 +100,21 @@
100100

101101
.scroll-button-container.left {
102102
left: 0;
103-
background: linear-gradient(90deg, var(--sys-color-cdt-base-container) 0%, var(--sys-color-cdt-base-container) 50%, transparent);
103+
background: linear-gradient(
104+
90deg,
105+
var(--sys-color-cdt-base-container) 0%,
106+
var(--sys-color-cdt-base-container) 50%,
107+
transparent
108+
);
104109
}
105110

106111
.scroll-button-container.right {
107112
right: 0;
108-
background: linear-gradient(90deg, transparent, var(--sys-color-cdt-base-container) 50%);
113+
background: linear-gradient(
114+
90deg,
115+
transparent,
116+
var(--sys-color-cdt-base-container) 50%
117+
);
109118
justify-content: flex-end;
110119
}
111120
}

0 commit comments

Comments
 (0)