Skip to content

Commit 5972196

Browse files
authored
add back button to ask AI search state (#55072)
1 parent 9536a3b commit 5972196

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

data/ui.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ search:
5555
thumbs_up: This answer was helpful
5656
thumbs_down: This answer was not helpful
5757
thumbs_announcement: Thank you for your feedback!
58+
back_to_search: Back to search
5859
failure:
5960
general_title: There was an error loading search results.
6061
ai_title: There was an error loading Copilot.

src/fixtures/fixtures/data/ui.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ search:
5555
thumbs_up: This answer was helpful
5656
thumbs_down: This answer was not helpful
5757
thumbs_announcement: Thank you for your feedback!
58+
back_to_search: Back to search
5859
failure:
5960
general_title: There was an error loading search results.
6061
ai_title: There was an error loading Copilot.

src/search/components/input/SearchOverlay.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
ActionList,
66
Box,
77
Header,
8+
IconButton,
89
Link,
910
Overlay,
1011
Spinner,
@@ -20,6 +21,7 @@ import {
2021
CopilotIcon,
2122
FileIcon,
2223
ArrowRightIcon,
24+
ArrowLeftIcon,
2325
} from '@primer/octicons-react'
2426

2527
import { useTranslation } from 'src/languages/components/useTranslation'
@@ -483,6 +485,15 @@ export function SearchOverlay({
483485
}
484486
}
485487

488+
const onBackButton = () => {
489+
// Leave the Ask AI state when the user clicks the back button
490+
setSelectedIndex(-1)
491+
updateParams({
492+
'search-overlay-ask-ai': '',
493+
'search-overlay-input': urlSearchInputQuery,
494+
})
495+
}
496+
486497
// We render the AI Result in the searchGroups call, so we pass the props down via an object
487498
// TODO: Move stateful logic to Context since we now have so many props:
488499
const askAIState = {
@@ -626,6 +637,20 @@ export function SearchOverlay({
626637
ref={overlayRef}
627638
>
628639
<Header className={styles.header}>
640+
<Box
641+
sx={{
642+
display: isAskAIState ? 'flex' : 'none',
643+
marginRight: '8px',
644+
fontWeight: 'bolder',
645+
}}
646+
>
647+
<IconButton
648+
aria-label={t('search.ai.back_to_search')}
649+
icon={ArrowLeftIcon}
650+
onClick={onBackButton}
651+
variant="invisible"
652+
></IconButton>
653+
</Box>
629654
<TextInput
630655
className="width-full"
631656
data-testid="overlay-search-input"

0 commit comments

Comments
 (0)