Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): interface for the experiment flags #1724

Merged
merged 8 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please follow the naming practices:

experiments/components/flag-list.tsx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use client'

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

import { Switch } from '@/components/ui/switch'

export default function FeatureList () {
const [quickActionBar, toggleQuickActionBar] = useEnableCodeBrowserQuickActionBar()

return (
<>
{!quickActionBar.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">Quick Action Bar</p>
<p className="text-sm text-muted-foreground">Enable Quick Action Bar to display a convenient toolbar when you select code, offering options to explain the code, add unit tests, and more.</p>
</div>
<Switch checked={quickActionBar.value} onCheckedChange={toggleQuickActionBar} />
</div>
}
</>
)
}
21 changes: 0 additions & 21 deletions ee/tabby-ui/app/(dashboard)/experimentalAI/components/Option.tsx

This file was deleted.

8 changes: 2 additions & 6 deletions ee/tabby-ui/app/(dashboard)/experimentalAI/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Metadata } from 'next'

import ExperimentalAIOption from './components/Option'
import FeatureList from './components/FeatureList'

export const metadata: Metadata = {
title: 'Experimental AI'
Expand All @@ -12,11 +12,7 @@ export default function IndexPage() {
<h3 className="scroll-m-20 text-2xl font-semibold tracking-tight">
Experimental AI
</h3>

<ExperimentalAIOption
title="Quick Action Bar"
description="Enable Quick Action Bar to display a convenient toolbar when you select code, offering options to explain the code, add unit tests, and more."
/>
<FeatureList />
</div>
)
}
28 changes: 20 additions & 8 deletions ee/tabby-ui/lib/experiment-flags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import useLocalStorage from 'use-local-storage'
import { useState, useEffect } from 'react'


class ExperimentFlag {
constructor(
Expand Down Expand Up @@ -39,18 +40,29 @@ class ExperimentFlagFactory {
}

defineHook() {
return (): [{ value: boolean; description: string }, () => void] => {
wwayne marked this conversation as resolved.
Show resolved Hide resolved
const [storageValue, setStorageValue] = useLocalStorage(
this.storageKey,
this.defaultValue
)
return (): [{ value: boolean; description: string, loading: boolean }, () => void] => {
const [storageValue, setStorageValue] = useState(this.defaultValue)
const [loading, setLoading] = useState(true)

useEffect(() => {
const value = localStorage.getItem(this.storageKey)
if (value) {
setStorageValue(value === 'true')
}
setLoading(false)
}, [])

const toggleFlag = () => {
setStorageValue(!storageValue)
const newStorageValue = !storageValue
setStorageValue(newStorageValue)
localStorage.setItem(this.storageKey, String(newStorageValue))
}

return [
{
value: storageValue,
description: this.description
description: this.description,
loading
},
toggleFlag
]
Expand Down
Loading