From b8d9c481dcbf00a83820790e24ecafbe3d5e53e0 Mon Sep 17 00:00:00 2001 From: wwayne Date: Wed, 5 Jun 2024 17:21:00 +0800 Subject: [PATCH] experiment flag & textare height --- .../experiments/components/feature-list.tsx | 17 ++++++++++++- .../app/search/components/search-gate.tsx | 14 +++++++++++ ee/tabby-ui/app/search/components/search.tsx | 25 ++++++++----------- ee/tabby-ui/app/search/page.tsx | 4 +-- ee/tabby-ui/lib/experiment-flags.ts | 10 +++++++- pnpm-lock.yaml | 6 ++--- 6 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 ee/tabby-ui/app/search/components/search-gate.tsx diff --git a/ee/tabby-ui/app/(dashboard)/experiments/components/feature-list.tsx b/ee/tabby-ui/app/(dashboard)/experiments/components/feature-list.tsx index 1d0ac663f672..5c9b89a4fa11 100644 --- a/ee/tabby-ui/app/(dashboard)/experiments/components/feature-list.tsx +++ b/ee/tabby-ui/app/(dashboard)/experiments/components/feature-list.tsx @@ -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 && ( @@ -24,6 +28,17 @@ export default function FeatureList() { /> )} + {!search.loading && ( +
+
+

{search.title}

+

+ {search.description} +

+
+ +
+ )} ) } diff --git a/ee/tabby-ui/app/search/components/search-gate.tsx b/ee/tabby-ui/app/search/components/search-gate.tsx new file mode 100644 index 000000000000..0372c3afef25 --- /dev/null +++ b/ee/tabby-ui/app/search/components/search-gate.tsx @@ -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 +} diff --git a/ee/tabby-ui/app/search/components/search.tsx b/ee/tabby-ui/app/search/components/search.tsx index dc42917995b8..80bb1380f596 100644 --- a/ee/tabby-ui/app/search/components/search.tsx +++ b/ee/tabby-ui/app/search/components/search.tsx @@ -79,18 +79,8 @@ const tabbyFetcher = ((url: string, init?: RequestInit) => { }) }) as typeof fetch -export default function Search() { +export function Search() { const [conversation, setConversation] = useState([]) - // const [conversation, setConversation] = useState([{ - // id: nanoid(), // FIXME - // role: 'user', - // content: 'add function' - // }, { - // id: nanoid(), // FIXME - // role: 'assistant', - // content: "", - // isLoading: true - // }]) const contentContainerRef = useRef(null) const [container, setContainer] = useState(null) const [title, setTitle] = useState('') @@ -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 @@ -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) }, []) @@ -348,9 +338,14 @@ function SearchArea({ )} > setIsFocus(true)} diff --git a/ee/tabby-ui/app/search/page.tsx b/ee/tabby-ui/app/search/page.tsx index cc413ba8f96c..6e5218848850 100644 --- a/ee/tabby-ui/app/search/page.tsx +++ b/ee/tabby-ui/app/search/page.tsx @@ -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 + return } diff --git a/ee/tabby-ui/lib/experiment-flags.ts b/ee/tabby-ui/lib/experiment-flags.ts index 009c1e57e900..332048ab4b4b 100644 --- a/ee/tabby-ui/lib/experiment-flags.ts +++ b/ee/tabby-ui/lib/experiment-flags.ts @@ -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() diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f91ad73957b5..81a37b597b88 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -432,8 +432,8 @@ importers: specifier: ^1.0.3 version: 1.0.3(@types/react-dom@18.2.8)(@types/react@18.2.23)(react-dom@18.2.0(react@18.2.0))(react@18.2.0) '@radix-ui/react-dialog': - specifier: 1.0.4 - version: 1.0.4(@types/react-dom@18.2.8)(@types/react@18.2.23)(react-dom@18.2.0(react@18.2.0))(react@18.2.0) + specifier: ^1.0.5 + version: 1.0.5(@types/react-dom@18.2.8)(@types/react@18.2.23)(react-dom@18.2.0(react@18.2.0))(react@18.2.0) '@radix-ui/react-dropdown-menu': specifier: ^2.0.5 version: 2.0.6(@types/react-dom@18.2.8)(@types/react@18.2.23)(react-dom@18.2.0(react@18.2.0))(react@18.2.0) @@ -606,7 +606,7 @@ importers: specifier: ^15.5.0 version: 15.5.0(react@18.2.0) react-textarea-autosize: - specifier: ^8.4.1 + specifier: ^8.5.3 version: 8.5.3(@types/react@18.2.23)(react@18.2.0) react-topbar-progress-indicator: specifier: ^4.1.1