Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update submit and stop buttons #1782

Merged
merged 5 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions lib/ui/src/Chat.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
}

.text-area-container {
width: 100%;
display: flex;
}

.chat-input-container {
width: 96%;
height: 100%;
position: relative;
}

Expand All @@ -27,26 +34,20 @@
}

.submit-button {
position: absolute;
right: 0;
bottom: 0;
fill: currentColor;
opacity: 0.8;
margin: 0 0 0.2rem 0;
background: none;
border: none;
cursor: pointer;
height: 2rem;
width: 2rem;
border-radius: 50%;
margin-left: 0.5rem;
}

.context-button {
color: var(--foreground);
color: var(--button-primary-background);
position: absolute;
right: 1rem;
right: 0;
bottom: 0;

fill: currentColor;
margin: 0rem 0.2rem 0rem 0rem;
background: none;
border: none;
cursor: pointer;
Expand Down
50 changes: 27 additions & 23 deletions lib/ui/src/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export interface ChatUISubmitButtonProps {
className: string
disabled: boolean
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void
onAbortMessageInProgress?: () => void
}

export interface ChatUISuggestionButtonProps {
Expand Down Expand Up @@ -616,32 +617,35 @@ export const Chat: React.FunctionComponent<ChatProps> = ({
setSelectedChatContext={setSelectedChatContext}
/>
)}
<TextArea
className={classNames(styles.chatInput, chatInputClassName)}
rows={inputRows}
value={isCodyEnabled ? formInput : 'Cody is disabled on this instance'}
autoFocus={true}
required={true}
disabled={needsEmailVerification || !isCodyEnabled}
onInput={onChatInput}
onKeyDown={onChatKeyDown}
setValue={inputHandler}
chatModels={chatModels}
/>
{ContextStatusComponent && EnhancedContextToggler && contextStatus && (
<div className={styles.contextButton}>
<EnhancedContextToggler
setEnhanceContext={setEnhanceContext}
enhanceContext={enhanceContext}
contextStatus={contextStatus}
/>
</div>
)}
<div className={styles.chatInputContainer}>
<TextArea
className={classNames(styles.chatInput, chatInputClassName)}
rows={inputRows}
value={isCodyEnabled ? formInput : 'Cody is disabled on this instance'}
autoFocus={true}
required={true}
disabled={needsEmailVerification || !isCodyEnabled}
onInput={onChatInput}
onKeyDown={onChatKeyDown}
setValue={inputHandler}
chatModels={chatModels}
/>
{ContextStatusComponent && EnhancedContextToggler && contextStatus && (
<div className={styles.contextButton}>
<EnhancedContextToggler
setEnhanceContext={setEnhanceContext}
enhanceContext={enhanceContext}
contextStatus={contextStatus}
/>
</div>
)}
</div>
<SubmitButton
className={styles.submitButton}
onClick={onChatSubmit}
disabled={
!!messageInProgress || needsEmailVerification || !isCodyEnabled || formInput.length === 0
disabled={needsEmailVerification || !isCodyEnabled || (!formInput.length && !messageInProgress)}
onAbortMessageInProgress={
!AbortMessageInProgressButton && messageInProgress ? onAbortMessageInProgress : undefined
}
/>
</div>
Expand Down
2 changes: 2 additions & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Starting from `0.2.0`, Cody is using `major.EVEN_NUMBER.patch` for release versi

### Changed

- Chat: Updated the design and location for the `chat submit` button and `stop generating` button. [pull/1782](https://github.com/sourcegraph/cody/pull/1782)

## [0.16.0]

### Added
Expand Down
6 changes: 4 additions & 2 deletions vscode/webviews/Chat.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ body[data-vscode-theme-kind='vscode-light'] .transcript-item pre > code {
}

.submit-button {
color: var(--foreground);
background: var(--vscode-button-background);
color: var(--vscode-button-foreground);
}

.submit-button,
Expand All @@ -203,7 +204,8 @@ body[data-vscode-theme-kind='vscode-light'] .transcript-item pre > code {
}

.submit-button[disabled] {
pointer-events: none;
opacity: 0.8;
cursor: text;
}

.stop-generating-button {
Expand Down
34 changes: 11 additions & 23 deletions vscode/webviews/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ export const Chat: React.FunctionComponent<React.PropsWithChildren<ChatboxProps>
insertButtonOnSubmit={onInsertBtnClick}
suggestions={suggestions}
setSuggestions={setSuggestions}
abortMessageInProgressComponent={AbortMessageInProgress}
onAbortMessageInProgress={abortMessageInProgress}
isTranscriptError={isTranscriptError}
// TODO: We should fetch this from the server and pass a pretty component
Expand Down Expand Up @@ -249,22 +248,6 @@ export const Chat: React.FunctionComponent<React.PropsWithChildren<ChatboxProps>
)
}

interface AbortMessageInProgressProps {
onAbortMessageInProgress: () => void
}

const AbortMessageInProgress: React.FunctionComponent<AbortMessageInProgressProps> = ({ onAbortMessageInProgress }) => (
<div className={classNames(styles.stopGeneratingButtonContainer)}>
<VSCodeButton
className={classNames(styles.stopGeneratingButton)}
onClick={onAbortMessageInProgress}
appearance="secondary"
>
<i className="codicon codicon-stop-circle" /> Stop generating
</VSCodeButton>
</div>
)

const ChatButton: React.FunctionComponent<ChatButtonProps> = ({ label, action, onClick }) => (
<VSCodeButton type="button" onClick={() => onClick(action)} className={styles.chatButton}>
{label}
Expand Down Expand Up @@ -333,16 +316,21 @@ const TextArea: React.FunctionComponent<ChatUITextAreaProps> = ({
)
}

const SubmitButton: React.FunctionComponent<ChatUISubmitButtonProps> = ({ className, disabled, onClick }) => (
const SubmitButton: React.FunctionComponent<ChatUISubmitButtonProps> = ({
className,
disabled,
onClick,
onAbortMessageInProgress,
}) => (
<VSCodeButton
className={classNames(styles.submitButton, className)}
appearance="icon"
className={classNames(styles.submitButton, className, disabled && styles.submitButtonDisabled)}
appearance="primary"
type="button"
disabled={disabled}
onClick={onClick}
title="Send Message"
onClick={onAbortMessageInProgress ?? onClick}
title={onAbortMessageInProgress ? 'Stop Generating' : disabled ? 'Message is empty' : 'Send Message'}
>
<SubmitSvg />
{onAbortMessageInProgress ? <i className="codicon codicon-debug-stop" /> : <SubmitSvg />}
</VSCodeButton>
)

Expand Down
48 changes: 35 additions & 13 deletions vscode/webviews/Components/EnhancedContextToggler.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
.pop-up-container {
background: var(--vscode-input-background);
color: var(--vscode-inputOption-activeForeground);
box-shadow: 0 0 8px 2px var(--vscode-widget-shadow);
box-shadow: 0 0 3px 2px var(--vscode-inputOption-activeBorder);

position: absolute;
bottom: 2.5rem;
right: 1rem;
right: -2.5rem;

width: 50%;
min-width: 300px;
Expand All @@ -21,28 +21,50 @@
flex-direction: column;
justify-content: center;
align-items: flex-start;
gap: 0.5rem;
gap: 0.25rem;

z-index: 100;
}

.enhanced-context-help-text {
margin: 0.5rem 0;
.pop-up-container:before {
content: '';
position: absolute;
top: 100%;
right: 3.4rem;

width: 0;
border-top: 0.5rem solid var(--vscode-input-background);
border-left: 0.5rem solid transparent;
border-right: 0.5rem solid transparent;
}

.enhanced-context-description {
font-size: smaller;
margin: 0;
color: var(--vscode-descriptionForeground);
}

.codebase-connection {
font-size: smaller;
margin: 0;
margin-top: 1rem;
}

.settings-btn {
position: relative;
color: var(--vscode-editor-foreground);
}

.pop-up-container:before {
content: '';
position: absolute;
top: 100%;
right: 0;
.settings-btn-active {
background: var(--vscode-button-background);
color: var(--vscode-button-foreground);
}

width: 0;
border-top: 1rem solid var(--vscode-input-background);
border-left: 1rem solid transparent;
.check-box {
margin: 0;
margin-bottom: 0.25rem;
}

.codebase {
border-bottom: 1px solid var(--vscode-selection-background);
}
11 changes: 8 additions & 3 deletions vscode/webviews/Components/EnhancedContextToggler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const EnhancedContextToggler: React.FunctionComponent<{
[setEnhanceContext]
)

const codebaseName = contextStatus.codebase ?? 'a local codebase'

return (
<div className={styles.container}>
{open && (
Expand All @@ -32,13 +34,16 @@ export const EnhancedContextToggler: React.FunctionComponent<{
>
Enhanced Context ✨
</VSCodeCheckbox>
<p className={styles.enhancedContextHelpText}>
Automatically include additional context from your codebase {contextStatus.codebase}
<p className={styles.enhancedContextDescription}>
Automatically include additional context from your codebase.
</p>
<p className={styles.codebaseConnection}>
Connected to <span className={contextStatus.codebase && styles.codebase}>{codebaseName}</span>
</p>
</div>
)}
<VSCodeButton
className={classNames(styles.settingsBtn)}
className={classNames(styles.settingsBtn, enhanceContext && styles.settingsBtnActive)}
appearance="icon"
type="button"
onClick={() => setOpen(!open)}
Expand Down