Skip to content

Commit aea64c9

Browse files
SaxonFjoshenlim
andauthored
Assistant refinements (supabase#30685)
* empty state refinements * specify js conversion prompt * placeholder state * update dot color * Lint * ADjust padding * Lint imports * adjust prompt * revert padding * wrap line prop in code block * fix margin * use sql icon * margin * add chart prompt * Add prevent default behaviour --------- Co-authored-by: Joshen Lim <[email protected]>
1 parent 62e2bcf commit aea64c9

File tree

8 files changed

+338
-237
lines changed

8 files changed

+338
-237
lines changed

apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ const ProjectLayout = forwardRef<HTMLDivElement, PropsWithChildren<ProjectLayout
114114

115115
useEffect(() => {
116116
const handler = (e: KeyboardEvent) => {
117-
if (e.metaKey && e.code === 'KeyI') setAiAssistantPanel({ open: !open })
117+
if (e.metaKey && e.code === 'KeyI') {
118+
setAiAssistantPanel({ open: !open })
119+
e.preventDefault()
120+
e.stopPropagation()
121+
}
118122
}
119123
if (isAssistantV2Enabled) window.addEventListener('keydown', handler)
120124
return () => window.removeEventListener('keydown', handler)

apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsx

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { PermissionAction } from '@supabase/shared-types/out/constants'
2-
import { motion } from 'framer-motion'
2+
import { AnimatePresence, motion } from 'framer-motion'
33
import { last } from 'lodash'
44
import { FileText } from 'lucide-react'
55
import { memo, useEffect, useMemo, useRef, useState } from 'react'
66
import { toast } from 'sonner'
77

88
import type { Message as MessageType } from 'ai/react'
99
import { useChat } from 'ai/react'
10+
import { useParams, useSearchParamsShallow } from 'common/hooks'
1011
import { subscriptionHasHipaaAddon } from 'components/interfaces/Billing/Subscription/Subscription.utils'
1112
import { Markdown } from 'components/interfaces/Markdown'
1213
import OptInToOpenAIToggle from 'components/interfaces/Organization/GeneralSettings/OptInToOpenAIToggle'
@@ -25,7 +26,9 @@ import { useFlag } from 'hooks/ui/useFlag'
2526
import { BASE_PATH, IS_PLATFORM, OPT_IN_TAGS } from 'lib/constants'
2627
import { TELEMETRY_EVENTS, TELEMETRY_VALUES } from 'lib/constants/telemetry'
2728
import uuidv4 from 'lib/uuid'
29+
import { useRouter } from 'next/router'
2830
import { useAppStateSnapshot } from 'state/app-state'
31+
import { useSqlEditorV2StateSnapshot } from 'state/sql-editor-v2'
2932
import {
3033
AiIconAnimation,
3134
Button,
@@ -40,10 +43,6 @@ import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
4043
import AIOnboarding from './AIOnboarding'
4144
import CollapsibleCodeBlock from './CollapsibleCodeBlock'
4245
import { Message } from './Message'
43-
import { useParams } from 'common/hooks'
44-
import { useSearchParamsShallow } from 'common/hooks'
45-
import { useSqlEditorV2StateSnapshot } from 'state/sql-editor-v2'
46-
import { useRouter } from 'next/router'
4746

4847
const MemoizedMessage = memo(
4948
({ message, isLoading }: { message: MessageType; isLoading: boolean }) => {
@@ -235,14 +234,18 @@ export const AIAssistant = ({
235234

236235
// Add useEffect to set up scroll listener
237236
useEffect(() => {
238-
const container = scrollContainerRef.current
239-
if (container) {
240-
container.addEventListener('scroll', handleScroll)
241-
// Initial check
242-
handleScroll()
243-
}
237+
// Use a small delay to ensure container is mounted and has content
238+
const timeoutId = setTimeout(() => {
239+
const container = scrollContainerRef.current
240+
if (container) {
241+
container.addEventListener('scroll', handleScroll)
242+
handleScroll()
243+
}
244+
}, 100)
244245

245246
return () => {
247+
clearTimeout(timeoutId)
248+
const container = scrollContainerRef.current
246249
if (container) {
247250
container.removeEventListener('scroll', handleScroll)
248251
}
@@ -507,12 +510,18 @@ export const AIAssistant = ({
507510
</div>
508511
)}
509512
</div>
510-
511-
{showFade && (
512-
<div className="pointer-events-none z-10 -mt-24">
513-
<div className="h-24 w-full bg-gradient-to-t from-background muted to-transparent" />
514-
</div>
515-
)}
513+
<AnimatePresence>
514+
{showFade && (
515+
<motion.div
516+
initial={{ opacity: 0 }}
517+
animate={{ opacity: 1 }}
518+
exit={{ opacity: 0 }}
519+
className="pointer-events-none z-10 -mt-24"
520+
>
521+
<div className="h-24 w-full bg-gradient-to-t from-background muted to-transparent" />
522+
</motion.div>
523+
)}
524+
</AnimatePresence>
516525

517526
<div className="p-5 pt-0 z-20 relative">
518527
{sqlSnippets && sqlSnippets.length > 0 && (
@@ -565,7 +574,7 @@ export const AIAssistant = ({
565574
? 'Reply to the assistant...'
566575
: (sqlSnippets ?? [])?.length > 0
567576
? 'Ask a question or make a change...'
568-
: 'How can we help you today?'
577+
: 'Chat to Postgres...'
569578
}
570579
value={value}
571580
onValueChange={(e) => setValue(e.target.value)}

0 commit comments

Comments
 (0)