Skip to content

Commit 99b6dea

Browse files
ergunshDevtools-frontend LUCI CQ
authored andcommitted
[AiAssistance] Render "change summary" after messages and update styling
The remaining TODOs are: * Adding the disclaimer icon next to the "stage to workspace" button. * Updating project selection texts. * Handling loading state as described in the mocks. Bug: 396064984 Change-Id: I7ba67e014315855454474aa35807c32f288293be Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6257570 Auto-Submit: Ergün Erdoğmuş <[email protected]> Reviewed-by: Alex Rudenko <[email protected]> Commit-Queue: Alex Rudenko <[email protected]>
1 parent 6aaad34 commit 99b6dea

File tree

3 files changed

+90
-83
lines changed

3 files changed

+90
-83
lines changed

front_end/panels/ai_assistance/AiAssistancePanel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ export class AiAssistancePanel extends UI.Panel.Panel {
651651
onCancelCrossOriginChat: this.#blockedByCrossOrigin && this.#previousSameOriginContext ?
652652
this.#handleCrossOriginChatCancellation.bind(this) :
653653
undefined,
654-
onStageToWorkspace: this.#onStageToWorkspace.bind(this)
654+
onApplyToWorkspace: this.#onApplyToWorkspace.bind(this)
655655
},
656656
this.#viewOutput, this.#contentContainer);
657657
}
@@ -909,7 +909,7 @@ export class AiAssistancePanel extends UI.Panel.Panel {
909909
UI.ARIAUtils.alert(lockedString(UIStringsNotTranslate.answerReady));
910910
}
911911

912-
async #onStageToWorkspace(): Promise<void> {
912+
async #onApplyToWorkspace(): Promise<void> {
913913
if (!this.#project) {
914914
throw new Error('Project does not exist');
915915
}

front_end/panels/ai_assistance/components/ChatView.ts

Lines changed: 78 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,11 @@ const UIStringsNotTranslate = {
263263
/**
264264
*@description Text displayed for showing change summary view.
265265
*/
266-
changeSummary: 'Change summary',
266+
changeSummary: 'Changes summary',
267+
/**
268+
*@description Button text for staging changes to workspace.
269+
*/
270+
applyToWorkspace: 'Apply to workspace',
267271
};
268272

269273
const str_ = i18n.i18n.registerUIStrings('panels/ai_assistance/components/ChatView.ts', UIStrings);
@@ -336,7 +340,7 @@ export interface Props {
336340
patchSuggestion?: string;
337341
patchSuggestionLoading?: boolean;
338342
projectName?: string;
339-
onStageToWorkspace?: () => void;
343+
onApplyToWorkspace?: () => void;
340344
}
341345

342346
export class ChatView extends HTMLElement {
@@ -710,11 +714,16 @@ export class ChatView extends HTMLElement {
710714
userInfo: this.#props.userInfo,
711715
markdownRenderer: this.#markdownRenderer,
712716
agentType: this.#props.agentType,
717+
changeSummary: this.#props.changeSummary,
718+
patchSuggestion: this.#props.patchSuggestion,
719+
patchSuggestionLoading: this.#props.patchSuggestionLoading,
720+
projectName: this.#props.projectName,
713721
getUnavailableAidaAvailabilityContents: this.#getUnavailableAidaAvailabilityContents,
714722
onSuggestionClick: this.#handleSuggestionClick,
715723
onFeedbackSubmit: this.#props.onFeedbackSubmit,
716724
onLastAnswerMarkdownViewRef: this.#handleLastAnswerMarkdownViewRef,
717725
onMessageContainerRef: this.#handleMessageContainerRef,
726+
onApplyToWorkspace: this.#props.onApplyToWorkspace,
718727
})}
719728
${this.#props.isReadOnly
720729
? renderReadOnlySection({
@@ -730,7 +739,6 @@ export class ChatView extends HTMLElement {
730739
selectedContext: this.#props.selectedContext,
731740
inspectElementToggled: this.#props.inspectElementToggled,
732741
agentType: this.#props.agentType,
733-
changeSummary: this.#props.changeSummary,
734742
onContextClick: this.#props.onContextClick,
735743
onInspectElementClick: this.#props.onInspectElementClick,
736744
onSubmit: this.#handleSubmit,
@@ -767,47 +775,47 @@ function renderChangeSummary({
767775
patchSuggestion,
768776
patchSuggestionLoading,
769777
projectName,
770-
onStageToWorkspace,
778+
onApplyToWorkspace,
771779
}: {
772-
changeSummary?: string,
780+
changeSummary: string,
773781
patchSuggestion?: string,
774782
patchSuggestionLoading?: boolean,
775783
projectName?: string,
776-
onStageToWorkspace?: () => void,
784+
onApplyToWorkspace?: () => void,
777785
}): Lit.LitTemplate {
778-
if (!changeSummary) {
779-
return Lit.nothing;
780-
}
781-
786+
// clang-format off
782787
return html`<details class="change-summary">
783788
<summary>
784-
<devtools-icon class="difference-icon" .name=${'difference'}
789+
<devtools-icon class="difference-icon" .name=${'pen-spark'}
785790
></devtools-icon>
786791
<span class="header-text">
787792
${lockedString(UIStringsNotTranslate.changeSummary)}
788793
</span>
789794
<devtools-icon
790795
class="arrow"
791-
.name=${'chevron-up'}
796+
.name=${'chevron-down'}
792797
></devtools-icon>
793798
</summary>
794799
<devtools-code-block
795800
.code=${changeSummary}
796801
.codeLang=${'css'}
797-
.displayNotice=${false}
802+
.displayNotice=${true}
798803
></devtools-code-block>
799-
<div class="patch-tmp-message">
800-
${(patchSuggestion ? '\nI suggest changing these files\n' + patchSuggestion : '')}
801-
</div>
802-
<div class="workspace">
803-
<devtools-button
804-
@click=${onStageToWorkspace}
805-
.jslogContext=${'stage-to-workspace'}
806-
.variant=${Buttons.Button.Variant.PRIMARY}>${
807-
!patchSuggestionLoading ? 'Stage to workspace' : 'Loading...'}</devtools-button>
808-
<div>Selected folder: ${projectName}</div>
809-
</div>
804+
<div class="workspace">
805+
<devtools-button
806+
class='apply-to-workspace'
807+
@click=${onApplyToWorkspace}
808+
.jslogContext=${'stage-to-workspace'}
809+
.variant=${Buttons.Button.Variant.OUTLINED}>
810+
${!patchSuggestionLoading ? lockedString(UIStringsNotTranslate.applyToWorkspace) : 'Loading...'}
811+
</devtools-button>
812+
<div>Selected folder: ${projectName}</div>
813+
</div>
814+
${patchSuggestion ? html`<div class="patch-tmp-message">
815+
I suggest changing these files ${patchSuggestion}
816+
</div>` : Lit.nothing}
810817
</details>`;
818+
// clang-format on
811819
}
812820

813821
function renderTextAsMarkdown(text: string, markdownRenderer: MarkdownRendererWithCodeBlock, {animate, ref: refFn}: {
@@ -1217,21 +1225,32 @@ function renderMessages({
12171225
canShowFeedbackForm,
12181226
userInfo,
12191227
markdownRenderer,
1228+
changeSummary,
1229+
patchSuggestion,
1230+
patchSuggestionLoading,
1231+
projectName,
12201232
onSuggestionClick,
12211233
onFeedbackSubmit,
12221234
onLastAnswerMarkdownViewRef,
12231235
onMessageContainerRef,
1236+
onApplyToWorkspace,
12241237
}: {
12251238
messages: ChatMessage[],
12261239
isLoading: boolean,
12271240
isReadOnly: boolean,
12281241
canShowFeedbackForm: boolean,
12291242
userInfo: Pick<Host.InspectorFrontendHostAPI.SyncInformation, 'accountImage'|'accountFullName'>,
12301243
markdownRenderer: MarkdownRendererWithCodeBlock,
1231-
onSuggestionClick: (suggestion: string) => void,
1232-
onFeedbackSubmit: (rpcId: Host.AidaClient.RpcGlobalId, rate: Host.AidaClient.Rating, feedback?: string) => void,
1233-
onLastAnswerMarkdownViewRef: (el: Element|undefined) => void,
1234-
onMessageContainerRef: (el: Element|undefined) => void,
1244+
changeSummary?: string,
1245+
patchSuggestion?: string,
1246+
patchSuggestionLoading?: boolean,
1247+
projectName?: string,
1248+
onApplyToWorkspace?: () => void,
1249+
onSuggestionClick: (suggestion: string) => void,
1250+
onFeedbackSubmit:
1251+
(rpcId: Host.AidaClient.RpcGlobalId, rate: Host.AidaClient.Rating, feedback?: string) => void,
1252+
onLastAnswerMarkdownViewRef: (el: Element|undefined) => void,
1253+
onMessageContainerRef: (el: Element|undefined) => void,
12351254
}): Lit.TemplateResult {
12361255
// clang-format off
12371256
return html`
@@ -1250,6 +1269,13 @@ function renderMessages({
12501269
onLastAnswerMarkdownViewRef,
12511270
}),
12521271
)}
1272+
${(changeSummary && !isLoading) ? renderChangeSummary({
1273+
changeSummary,
1274+
patchSuggestion,
1275+
patchSuggestionLoading,
1276+
projectName,
1277+
onApplyToWorkspace,
1278+
}) : Lit.nothing}
12531279
</div>
12541280
`;
12551281
// clang-format on
@@ -1403,18 +1429,13 @@ function renderChatInput({
14031429
selectedContext,
14041430
inspectElementToggled,
14051431
agentType,
1406-
changeSummary,
1407-
patchSuggestion,
1408-
patchSuggestionLoading,
1409-
projectName,
14101432
onContextClick,
14111433
onInspectElementClick,
14121434
onSubmit,
14131435
onTextAreaKeyDown,
14141436
onCancel,
14151437
onNewConversation,
14161438
onCancelCrossOriginChat,
1417-
onStageToWorkspace,
14181439
}: {
14191440
isLoading: boolean,
14201441
blockedByCrossOrigin: boolean,
@@ -1424,18 +1445,13 @@ function renderChatInput({
14241445
selectedContext: ConversationContext<unknown> | null,
14251446
inspectElementToggled: boolean,
14261447
agentType?: AgentType,
1427-
changeSummary?: string,
1428-
patchSuggestion?: string,
1429-
patchSuggestionLoading?: boolean,
1430-
projectName?: string,
14311448
onContextClick: () => void | Promise<void>,
14321449
onInspectElementClick: () => void,
14331450
onSubmit: (ev: SubmitEvent) => void,
14341451
onTextAreaKeyDown: (ev: KeyboardEvent) => void,
14351452
onCancel: (ev: SubmitEvent) => void,
14361453
onNewConversation: () => void,
14371454
onCancelCrossOriginChat?: () => void,
1438-
onStageToWorkspace?: () => void,
14391455
}): Lit.LitTemplate {
14401456
if (!agentType) {
14411457
return Lit.nothing;
@@ -1463,13 +1479,6 @@ function renderChatInput({
14631479
onInspectElementClick,
14641480
})}
14651481
</div>
1466-
${renderChangeSummary({
1467-
changeSummary,
1468-
patchSuggestion,
1469-
patchSuggestionLoading,
1470-
projectName,
1471-
onStageToWorkspace,
1472-
})}
14731482
</div>
14741483
` : Lit.nothing}
14751484
<div class="chat-input-container">
@@ -1599,11 +1608,16 @@ function renderMainContents({
15991608
userInfo,
16001609
markdownRenderer,
16011610
agentType,
1611+
changeSummary,
1612+
patchSuggestion,
1613+
patchSuggestionLoading,
1614+
projectName,
16021615
getUnavailableAidaAvailabilityContents,
16031616
onSuggestionClick,
16041617
onFeedbackSubmit,
16051618
onLastAnswerMarkdownViewRef,
16061619
onMessageContainerRef,
1620+
onApplyToWorkspace,
16071621
}: {
16081622
state: State,
16091623
aidaAvailability: Host.AidaClient.AidaAccessPreconditions,
@@ -1617,15 +1631,20 @@ function renderMainContents({
16171631
userInfo: Pick<Host.InspectorFrontendHostAPI.SyncInformation, 'accountImage'|'accountFullName'>,
16181632
markdownRenderer: MarkdownRendererWithCodeBlock,
16191633
agentType?: AgentType,
1620-
getUnavailableAidaAvailabilityContents:
1621-
(aidaAvailability: Exclude<
1622-
Host.AidaClient.AidaAccessPreconditions, Host.AidaClient.AidaAccessPreconditions.AVAILABLE>) =>
1623-
Lit.TemplateResult,
1624-
onSuggestionClick: (suggestion: string) => void,
1625-
onFeedbackSubmit: (rpcId: Host.AidaClient.RpcGlobalId, rate: Host.AidaClient.Rating, feedback?: string) =>
1626-
void,
1627-
onLastAnswerMarkdownViewRef: (el: Element|undefined) => void,
1628-
onMessageContainerRef: (el: Element|undefined) => void,
1634+
changeSummary?: string,
1635+
patchSuggestion?: string,
1636+
patchSuggestionLoading?: boolean,
1637+
projectName?: string,
1638+
getUnavailableAidaAvailabilityContents:
1639+
(aidaAvailability: Exclude<
1640+
Host.AidaClient.AidaAccessPreconditions, Host.AidaClient.AidaAccessPreconditions.AVAILABLE>) =>
1641+
Lit.TemplateResult,
1642+
onSuggestionClick: (suggestion: string) => void,
1643+
onFeedbackSubmit: (rpcId: Host.AidaClient.RpcGlobalId, rate: Host.AidaClient.Rating, feedback?: string) =>
1644+
void,
1645+
onLastAnswerMarkdownViewRef: (el: Element|undefined) => void,
1646+
onMessageContainerRef: (el: Element|undefined) => void,
1647+
onApplyToWorkspace?: () => void,
16291648
}): Lit.TemplateResult {
16301649
if (state === State.CONSENT_VIEW) {
16311650
return renderDisabledState(consentViewContents);
@@ -1647,6 +1666,11 @@ function renderMainContents({
16471666
canShowFeedbackForm,
16481667
userInfo,
16491668
markdownRenderer,
1669+
changeSummary,
1670+
patchSuggestion,
1671+
patchSuggestionLoading,
1672+
projectName,
1673+
onApplyToWorkspace,
16501674
onSuggestionClick,
16511675
onFeedbackSubmit,
16521676
onLastAnswerMarkdownViewRef,

front_end/panels/ai_assistance/components/chatView.css

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@
7878
animation-timeline: --scroll-timeline;
7979
}
8080
}
81-
82-
&:has(.change-summary) .input-form-shadow-container {
83-
display: none;
84-
}
8581
}
8682

8783
.chat-readonly-container {
@@ -218,7 +214,7 @@
218214
word-break: break-word;
219215
border-bottom: var(--sys-size-1) solid var(--sys-color-divider);
220216

221-
&:last-child {
217+
&:last-of-type {
222218
border-bottom: 0;
223219
}
224220

@@ -472,10 +468,6 @@
472468
gap: var(--sys-size-8);
473469
position: relative;
474470

475-
&:has(.change-summary) {
476-
min-height: var(--sys-size-13);
477-
}
478-
479471
& .feedback-icon {
480472
width: var(--sys-size-8);
481473
height: var(--sys-size-8);
@@ -677,21 +669,18 @@ main {
677669
}
678670

679671
.change-summary {
680-
width: fit-content;
681672
background-color: var(--sys-color-surface3);
682-
border-radius: var(--sys-size-6);
673+
border-radius: var(--sys-shape-corner-medium-small);
683674
position: relative;
684-
max-height: 80cqh;
685-
overflow: auto;
686-
scrollbar-width: none;
675+
margin: 0 var(--sys-size-5);
676+
padding: 0 var(--sys-size-5);
687677

688678
summary {
689-
padding-left: var(--sys-size-6);
690-
padding-right: var(--sys-size-4);
691679
display: flex;
692680
align-items: center;
693681
gap: var(--sys-size-3);
694-
height: var(--sys-size-13);
682+
height: var(--sys-size-14);
683+
padding-left: var(--sys-size-3);
695684

696685
& .difference-icon {
697686
color: var(--sys-color-on-tonal-container);
@@ -700,8 +689,8 @@ main {
700689
}
701690

702691
& .header-text {
703-
font: var(--sys-typescale-body5-bold);
704-
color: var(--sys-color-on-surface-subtle);
692+
font: var(--sys-typescale-body4);
693+
color: var(--sys-color-on-surface);
705694
}
706695

707696
& .arrow {
@@ -726,12 +715,6 @@ main {
726715
}
727716

728717
&[open] {
729-
flex: 1;
730-
position: absolute;
731-
bottom: 0;
732-
right: 0;
733-
width: 100%;
734-
735718
&::details-content {
736719
height: fit-content;
737720
padding: var(--sys-size-2) 0;
@@ -744,9 +727,9 @@ main {
744727
}
745728

746729
devtools-code-block {
747-
margin-top: calc(-1 * var(--sys-size-5));
730+
margin-bottom: var(--sys-size-5);
748731

749-
--code-block-background-color: inherit;
732+
--code-block-background-color: var(--sys-color-surface1);
750733
}
751734

752735
.workspace {

0 commit comments

Comments
 (0)