Skip to content

Commit 3e1c20c

Browse files
committed
include ai button in search
1 parent c0cbf40 commit 3e1c20c

File tree

7 files changed

+96
-51
lines changed

7 files changed

+96
-51
lines changed

app/not-found.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default function NotFound() {
2424

2525
<div className="max-w-md pt-8">
2626
<p className="pb-4">Let's give it another shot:</p>
27-
<Search autoFocus path={pathname} searchPlatforms={[]} showChatBot={false} />
27+
<Search autoFocus path={pathname} searchPlatforms={[]} />
2828
</div>
2929
<div className="pt-8 flex gap-4">
3030
<Button variant="solid" size="3" asChild>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export function MagicIcon({className}: {className?: string}) {
2+
return (
3+
<svg
4+
xmlns="http://www.w3.org/2000/svg"
5+
fill="none"
6+
viewBox="0 0 24 24"
7+
strokeWidth={1.5}
8+
stroke="currentColor"
9+
className={`size-5 ${className}`}
10+
>
11+
<path
12+
strokeLinecap="round"
13+
strokeLinejoin="round"
14+
d="M9.813 15.904 9 18.75l-.813-2.846a4.5 4.5 0 0 0-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 0 0 3.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 0 0 3.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 0 0-3.09 3.09ZM18.259 8.715 18 9.75l-.259-1.035a3.375 3.375 0 0 0-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 0 0 2.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 0 0 2.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 0 0-2.456 2.456ZM16.894 20.567 16.5 21.75l-.394-1.183a2.25 2.25 0 0 0-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 0 0 1.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 0 0 1.423 1.423l1.183.394-1.183.394a2.25 2.25 0 0 0-1.423 1.423Z"
15+
/>
16+
</svg>
17+
);
18+
}

src/components/header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function Header({pathname, searchPlatforms, noSearch}: Props) {
6262
</Link>
6363
{!noSearch && (
6464
<div className="hidden md:flex justify-center lg:justify-start w-full px-6">
65-
<Search path={pathname} searchPlatforms={searchPlatforms} showChatBot />
65+
<Search path={pathname} searchPlatforms={searchPlatforms} />
6666
</div>
6767
)}
6868
<div className="hidden lg-xl:flex justify-end flex-1 space-x-2 items-center min-w-fit">

src/components/mobileMenu/index.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,7 @@ export function MobileMenu({pathname, searchPlatforms}: Props) {
3838
<DropdownMenu.Content className={styles.DropdownMenuContent} sideOffset={5}>
3939
<Box display={{xs: 'block', sm: 'none'}}>
4040
<DropdownMenu.Item className={styles.DropdownMenuItem} asChild>
41-
<Search path={pathname} searchPlatforms={searchPlatforms} showChatBot />
42-
</DropdownMenu.Item>
43-
44-
<DropdownMenu.Item className={styles.DropdownMenuItem} asChild>
45-
<Link href="#" className="mt-2 kapa-ai-class md:hidden">
46-
Ask AI
47-
</Link>
41+
<Search path={pathname} searchPlatforms={searchPlatforms} />
4842
</DropdownMenu.Item>
4943
<DropdownMenu.Separator className={styles.DropdownMenuSeparator} />
5044
</Box>

src/components/search/index.tsx

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import {Fragment, useCallback, useEffect, useRef, useState} from 'react';
4-
import {Button} from '@radix-ui/themes';
4+
import {ArrowRightIcon} from '@radix-ui/react-icons';
55
import {captureException} from '@sentry/nextjs';
66
import {
77
Hit,
@@ -20,6 +20,7 @@ import {isDeveloperDocs} from 'sentry-docs/isDeveloperDocs';
2020

2121
import styles from './search.module.scss';
2222

23+
import {MagicIcon} from '../cutomIcons/magic';
2324
import {Logo} from '../logo';
2425

2526
// Initialize Algolia Insights
@@ -69,10 +70,9 @@ type Props = {
6970
autoFocus?: boolean;
7071
path?: string;
7172
searchPlatforms?: string[];
72-
showChatBot?: boolean;
7373
};
7474

75-
export function Search({path, autoFocus, searchPlatforms = [], showChatBot}: Props) {
75+
export function Search({path, autoFocus, searchPlatforms = []}: Props) {
7676
const ref = useRef<HTMLDivElement>(null);
7777
const [query, setQuery] = useState(``);
7878
const [results, setResults] = useState([] as Result[]);
@@ -268,40 +268,38 @@ export function Search({path, autoFocus, searchPlatforms = [], showChatBot}: Pro
268268
{inputFocus ? 'esc' : '⌘K'}
269269
</kbd>
270270
</div>
271-
{showChatBot && (
272-
<Fragment>
273-
<span className="text-[var(--desatPurple10)] hidden md:inline">or</span>
274-
<Button
275-
asChild
276-
variant="ghost"
277-
color="gray"
278-
size="3"
279-
radius="medium"
280-
className="font-medium text-[var(--foreground)] py-2 px-3 uppercase cursor-pointer kapa-ai-class hidden md:flex"
281-
>
282-
<div>
283-
<svg
284-
xmlns="http://www.w3.org/2000/svg"
285-
fill="none"
286-
viewBox="0 0 24 24"
287-
strokeWidth={1.5}
288-
stroke="currentColor"
289-
className="size-5"
290-
>
291-
<path
292-
strokeLinecap="round"
293-
strokeLinejoin="round"
294-
d="M9.813 15.904 9 18.75l-.813-2.846a4.5 4.5 0 0 0-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 0 0 3.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 0 0 3.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 0 0-3.09 3.09ZM18.259 8.715 18 9.75l-.259-1.035a3.375 3.375 0 0 0-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 0 0 2.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 0 0 2.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 0 0-2.456 2.456ZM16.894 20.567 16.5 21.75l-.394-1.183a2.25 2.25 0 0 0-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 0 0 1.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 0 0 1.423 1.423l1.183.394-1.183.394a2.25 2.25 0 0 0-1.423 1.423Z"
295-
/>
296-
</svg>
297-
<span>Ask AI</span>
298-
</div>
299-
</Button>
300-
</Fragment>
301-
)}
302271
</div>
303272
{query.length >= 2 && inputFocus && (
304273
<div className={styles['sgs-search-results']}>
274+
<div className={styles['sgs-ai']}>
275+
<button
276+
id="ai-list-entry"
277+
className={`${styles['sgs-ai-button']} ${
278+
focused?.id === 'ai-list-entry' ? styles['sgs-ai-focused'] : ''
279+
}`}
280+
onClick={() => {
281+
if (window.Kapa?.open) {
282+
// close search results
283+
setInputFocus(false);
284+
// open kapa modal
285+
window.Kapa.open({query: `Explain ${query}`, submit: true});
286+
}
287+
}}
288+
>
289+
<MagicIcon className="size-6 text-[var(--sgs-color-hit-highlight)] flex-shrink-0" />
290+
<div className={styles['sgs-ai-button-content']}>
291+
<h6>
292+
Ask Sentry about{' '}
293+
<span>{query.length > 30 ? query.slice(0, 30) + '...' : query}</span>
294+
</h6>
295+
<div className={styles['sgs-ai-hint']}>
296+
Get an AI-powered answer to your question
297+
</div>
298+
</div>
299+
<ArrowRightIcon className="size-5 text-[var(--sgs-color-hit-highlight)] ml-auto flex-shrink-0" />
300+
</button>
301+
</div>
302+
305303
{loading && <Logo loading />}
306304

307305
{!loading && totalHits > 0 && (
@@ -378,14 +376,6 @@ export function Search({path, autoFocus, searchPlatforms = [], showChatBot}: Pro
378376
</div>
379377
)}
380378

381-
{!loading && totalHits === 0 && (
382-
<div className={styles['sgs-hit-empty-state']}>
383-
<button className="kapa-ai-class font-bold">
384-
Can't find what you're looking for? Ask our AI!
385-
</button>
386-
</div>
387-
)}
388-
389379
{!loading && !showOffsiteResults && (
390380
<div className={styles['sgs-expand-results']}>
391381
<button

src/components/search/search.module.scss

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,46 @@
192192
}
193193
}
194194

195+
.sgs-ai {
196+
color: var(--sgs-color-hit-text);
197+
padding: 0.25rem;
198+
199+
&-button {
200+
padding: 0.75rem;
201+
display: flex;
202+
width: 100%;
203+
align-items: center;
204+
gap: 0.75rem;
205+
color: inherit;
206+
207+
&:hover,
208+
.sgs-ai-focused & {
209+
background-color: var(--sgs-color-hit-hover-background);
210+
}
211+
212+
&-content {
213+
display: flex;
214+
flex-direction: column;
215+
align-items: flex-start;
216+
flex: 1;
217+
218+
h6 {
219+
font-size: 0.875rem;
220+
line-height: 1.25rem;
221+
margin: 0;
222+
223+
span {
224+
color: var(--sgs-color-hit-highlight);
225+
}
226+
}
227+
}
228+
}
229+
230+
&-hint {
231+
color: var(--sgs-color-hit-context);
232+
}
233+
}
234+
195235
.sgs-hit-empty-state {
196236
display: block;
197237
text-decoration: none;

src/globals.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ import type * as Sentry from '@sentry/browser';
33
declare global {
44
interface Window {
55
Sentry: typeof Sentry;
6+
Kapa?: {
7+
open: (options: {mode?: string; query?: string; submit?: boolean}) => void;
8+
};
69
}
710
}

0 commit comments

Comments
 (0)