Skip to content

Commit

Permalink
Merge pull request #25564 from brave/move_edit_answer_from_quick_acti…
Browse files Browse the repository at this point in the history
…on_to_menu

Move edit answer from quick action to menu
  • Loading branch information
yrliou committed Sep 16, 2024
2 parents 5b6f517 + 4e6df28 commit dabb50e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions components/ai_chat/core/browser/constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ base::span<const webui::LocalizedString> GetLocalizedStrings() {
{"saveButtonLabel", IDS_CHAT_UI_SAVE_BUTTON_LABEL},
{"editedLabel", IDS_CHAT_UI_EDITED_LABEL},
{"editButtonLabel", IDS_CHAT_UI_EDIT_BUTTON_LABEL},
{"editAnswerLabel", IDS_CHAT_UI_EDIT_ANSWER_LABEL},
{"optionNotHelpful", IDS_CHAT_UI_OPTION_NOT_HELPFUL},
{"optionIncorrect", IDS_CHAT_UI_OPTION_INCORRECT},
{"optionUnsafeHarmful", IDS_CHAT_UI_OPTION_UNSAFE_HARMFUL},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface ContextMenuAssistantProps {
isOpen: boolean
onClick: () => void
onClose: () => void
onEditAnswerClicked: () => void
}

enum RatingStatus {
Expand All @@ -35,6 +36,7 @@ function ContextMenuAssistant_(
ref: React.RefObject<Map<number, Element>>
) {
const context = React.useContext(DataContext)
const {shouldDisableUserInput} = context
const [feedbackId, setFeedbackId] = React.useState<string | null>()
const [isFormVisible, setIsFormVisible] = React.useState(false)
const [currentRatingStatus, setCurrentRatingStatus] =
Expand Down Expand Up @@ -157,6 +159,14 @@ function ContextMenuAssistant_(
>
<Icon name='more-vertical' />
</Button>
{!shouldDisableUserInput && (
<leo-menu-item
onClick={props.onEditAnswerClicked}
>
<Icon name='edit-pencil' />
<span>{getLocale('editAnswerLabel')}</span>
</leo-menu-item>
)}
<leo-menu-item
class={classnames({
[styles.liked]: currentRatingStatus === RatingStatus.Liked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ function ConversationList(props: ConversationListProps) {
)}
<div className={styles.turnActions}>
<CopyButton onClick={handleCopyText} />
<EditButton
onClick={() => setEditInputId(id)}
isDisabled={isAIAssistant && shouldDisableUserInput}
/>
{!isAIAssistant &&
<EditButton
onClick={() => setEditInputId(id)}
/>
}
{isAIAssistant &&
context.currentModel?.options.leoModelOptions && (
<ContextMenuAssistant
Expand All @@ -198,6 +199,7 @@ function ConversationList(props: ConversationListProps) {
isOpen={activeMenuId === id}
onClick={() => showAssistantMenu(id)}
onClose={hideAssistantMenu}
onEditAnswerClicked={() => setEditInputId(id)}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import styles from './style.module.scss'

interface Props {
onClick: () => void
isDisabled: boolean
}

function EditButton (props: Props) {
Expand All @@ -20,7 +19,6 @@ function EditButton (props: Props) {
fab
size='tiny'
kind='plain-faint'
isDisabled={props.isDisabled}
title={getLocale('editButtonLabel')}
>
<Icon name='edit-pencil' />
Expand Down
3 changes: 3 additions & 0 deletions components/resources/ai_chat_ui_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@
<message name="IDS_CHAT_UI_EDIT_BUTTON_LABEL" desc="Button title to edit content">
Edit
</message>
<message name="IDS_CHAT_UI_EDIT_ANSWER_LABEL" desc="Button title to edit AI agent answer">
Edit answer
</message>
<message name="IDS_CHAT_UI_OPTION_NOT_HELPFUL" desc="Select option for feedback form if the answer is not helpful">
Not helpful
</message>
Expand Down

0 comments on commit dabb50e

Please sign in to comment.