From 3b40e7eb820eb4c0baa0d4f8a9c0086eee8f43ff Mon Sep 17 00:00:00 2001 From: Keith Daulton Date: Fri, 31 Mar 2023 15:01:35 -0400 Subject: [PATCH] Adds explain commit UI to commit details --- src/webviews/apps/commitDetails/commitDetails.html | 16 ++++++++++++ src/webviews/apps/commitDetails/commitDetails.scss | 30 +++++++++++++++++++++- src/webviews/apps/commitDetails/commitDetails.ts | 16 ++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/webviews/apps/commitDetails/commitDetails.html b/src/webviews/apps/commitDetails/commitDetails.html index 6dcd2a8..cd84d08 100644 --- a/src/webviews/apps/commitDetails/commitDetails.html +++ b/src/webviews/apps/commitDetails/commitDetails.html @@ -228,6 +228,22 @@ + + + AI assistance + +
+

Let OpenAI assist in understanding the changes made with this commit.

+

+ + + +

+
+
+
#{endOfBody} diff --git a/src/webviews/apps/commitDetails/commitDetails.scss b/src/webviews/apps/commitDetails/commitDetails.scss index 1b62f5d..bfec6ac 100644 --- a/src/webviews/apps/commitDetails/commitDetails.scss +++ b/src/webviews/apps/commitDetails/commitDetails.scss @@ -226,9 +226,37 @@ ul { } } +.pane-content { + padding: 0 var(--gitlens-scrollbar-gutter-width) 1.5rem var(--gitlens-gutter-width); + + > :first-child { + margin-top: 0; + } +} + +[data-action='explain-commit'] { + code-icon { + margin-right: 0.5rem; + } + + &[aria-busy='true'] { + opacity: 0.5; + } + + &:not([aria-busy='true']) { + code-icon { + display: none; + } + } +} + // webview-specific styles +.ai-content { +} + .change-list { list-style: none; + margin-bottom: 1rem; &__item { // & + & { @@ -539,7 +567,7 @@ ul { } &__main { - padding-bottom: 1rem; + // padding-bottom: 1rem; } } diff --git a/src/webviews/apps/commitDetails/commitDetails.ts b/src/webviews/apps/commitDetails/commitDetails.ts index 10c4e07..f3fefa5 100644 --- a/src/webviews/apps/commitDetails/commitDetails.ts +++ b/src/webviews/apps/commitDetails/commitDetails.ts @@ -86,6 +86,7 @@ export class CommitDetailsApp extends App> { 'expanded-change', e => this.onExpandedChange(e.detail), ), + DOM.on('[data-action="explain-commit"]', 'click', e => this.onExplainCommit(e)), ]; return disposables; @@ -131,6 +132,21 @@ export class CommitDetailsApp extends App> { } } + onExplainCommit(e: MouseEvent) { + const el = e.target as HTMLButtonElement; + if (el.getAttribute('aria-busy') === 'true') return; + + el.setAttribute('aria-busy', 'true'); + setTimeout(() => { + el.removeAttribute('aria-busy'); + const explanationEL = document.querySelector('[data-region="commit-explanation"]')!; + explanationEL.innerHTML = ` +

No explanation available

+ `; + explanationEL.scrollIntoView(); + }, 2000); + } + onDismissBanner(e: MouseEvent) { const dismissed = this.state.preferences?.dismissed ?? []; if (dismissed.includes('sidebar')) {