Skip to content

Commit

Permalink
experiment flag & textare height
Browse files Browse the repository at this point in the history
  • Loading branch information
wwayne committed Jun 5, 2024
1 parent 0eb4c3f commit b8d9c48
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
'use client'

import { useEnableCodeBrowserQuickActionBar } from '@/lib/experiment-flags'
import {
useEnableCodeBrowserQuickActionBar,
useEnableSearch
} from '@/lib/experiment-flags'
import { Switch } from '@/components/ui/switch'

export default function FeatureList() {
const [quickActionBar, toggleQuickActionBar] =
useEnableCodeBrowserQuickActionBar()
const [search, toggleSearch] = useEnableSearch()
return (
<>
{!quickActionBar.loading && (
Expand All @@ -24,6 +28,17 @@ export default function FeatureList() {
/>
</div>
)}
{!search.loading && (
<div className="flex items-center space-x-4 rounded-md border p-4">
<div className="flex-1 space-y-1">
<p className="text-sm font-medium leading-none">{search.title}</p>
<p className="text-sm text-muted-foreground">
{search.description}
</p>
</div>
<Switch checked={search.value} onCheckedChange={toggleSearch} />
</div>
)}
</>
)
}
14 changes: 14 additions & 0 deletions ee/tabby-ui/app/search/components/search-gate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client'

import { useEnableSearch } from '@/lib/experiment-flags'

import { Search } from './search'

export default function SearchGate() {
const [searchFlag] = useEnableSearch()
if (!searchFlag.value) {
return <></>
}

return <Search />
}
25 changes: 10 additions & 15 deletions ee/tabby-ui/app/search/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,8 @@ const tabbyFetcher = ((url: string, init?: RequestInit) => {
})
}) as typeof fetch

export default function Search() {
export function Search() {
const [conversation, setConversation] = useState<ConversationMessage[]>([])
// const [conversation, setConversation] = useState<ConversationMessage[]>([{
// id: nanoid(), // FIXME
// role: 'user',
// content: 'add function'
// }, {
// id: nanoid(), // FIXME
// role: 'assistant',
// content: "",
// isLoading: true
// }])
const contentContainerRef = useRef<HTMLDivElement>(null)
const [container, setContainer] = useState<HTMLDivElement | null>(null)
const [title, setTitle] = useState('')
Expand Down Expand Up @@ -120,7 +110,7 @@ export default function Search() {
item => item.id === currentLoadindId
)
if (!currentAnswer) return
currentAnswer.content = answer.answer_delta
currentAnswer.content = answer.answer_delta || ""
currentAnswer.relevant_documents = answer.relevant_documents
currentAnswer.relevant_questions = answer.relevant_questions
currentAnswer.isLoading = isLoading
Expand Down Expand Up @@ -313,12 +303,12 @@ function SearchArea({
}: {
onSubmitSearch: (question: string) => void
}) {
// FIXME: the textarea has unexpected flash when it's mounted, maybe it can be fixed after adding loader
const [isShow, setIsShow] = useState(false)
const [isFocus, setIsFocus] = useState(false)
const [value, setValue] = useState('')

useEffect(() => {
// Ensure the textarea height remains consistent during rendering
setIsShow(true)
}, [])

Expand Down Expand Up @@ -348,9 +338,14 @@ function SearchArea({
)}
>
<TextareaAutosize
className="flex-1 resize-none rounded-lg !border-none bg-transparent px-4 py-3 !shadow-none !outline-none !ring-0 !ring-offset-0"
className={cn(
'flex-1 resize-none rounded-lg !border-none bg-transparent px-4 py-3 !shadow-none !outline-none !ring-0 !ring-offset-0',
{
'!h-[48px]': !isShow
}
)}
placeholder="Ask anything"
maxRows={15}
maxRows={5}
onKeyDown={onSearchKeyDown}
onKeyUp={onSearchKeyUp}
onFocus={() => setIsFocus(true)}
Expand Down
4 changes: 2 additions & 2 deletions ee/tabby-ui/app/search/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Metadata } from 'next'

import Search from './components/search'
import SearchGate from './components/search-gate'

export const metadata: Metadata = {
title: 'Search'
}

export default function SearchPage() {
return <Search />
return <SearchGate />
}
10 changes: 9 additions & 1 deletion ee/tabby-ui/lib/experiment-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,16 @@ const enableCodeBrowserQuickActionBarFactory = new ExperimentFlagFactory(
'Enable Quick Action Bar to display a convenient toolbar when you select code, offering options to explain the code, add unit tests, and more.',
true
)

export const EXP_enable_code_browser_quick_action_bar =
enableCodeBrowserQuickActionBarFactory.defineGlobalVar()
export const useEnableCodeBrowserQuickActionBar =
enableCodeBrowserQuickActionBarFactory.defineHook()

const enableSearchFactory = new ExperimentFlagFactory(
'enable_search',
'Search',
'Enable the search on the home page to search for anything you want to know using the local chat model.',
false
)
export const EXP_enable_search = enableSearchFactory.defineGlobalVar()
export const useEnableSearch = enableSearchFactory.defineHook()
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b8d9c48

Please sign in to comment.