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 6 commits
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
4 changes: 4 additions & 0 deletions ee/tabby-ui/app/(dashboard)/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
IconLightingBolt,
IconNetwork,
IconScrollText,
IconSparkles,
IconUser
} from '@/components/ui/icons'

Expand Down Expand Up @@ -61,6 +62,9 @@ export default function Sidebar({ children, className }: SidebarProps) {
<SidebarButton href="/profile">
<IconUser /> Profile
</SidebarButton>
<SidebarButton href="/experiments">
<IconSparkles /> Experimental AI
</SidebarButton>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<SidebarButton href="/experiments">
<IconSparkles /> Experimental AI
</SidebarButton>

Don't display it in side bar, it's developer only page

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

{isAdmin && (
<>
<SidebarButton href="/cluster">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'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>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<p className="text-sm font-medium leading-none">Quick Action Bar</p>
<p className="text-sm font-medium leading-none">{}</p>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

use {quickActionBar.title}

<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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Enable Quick Action Bar to display a convenient toolbar when you
select code, offering options to explain the code, add unit tests,
and more.
{quickActionBar.description}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

</p>
</div>
<Switch
checked={quickActionBar.value}
onCheckedChange={toggleQuickActionBar}
/>
</div>
)}
</>
)
}
18 changes: 18 additions & 0 deletions ee/tabby-ui/app/(dashboard)/experiments/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Metadata } from 'next'

import FeatureList from './components/feature-list'

export const metadata: Metadata = {
title: 'Experimental AI'
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

}

export default function IndexPage() {
return (
<div className="mx-auto flex max-w-xl flex-col gap-3">
<h3 className="scroll-m-20 text-2xl font-semibold tracking-tight">
Experimental AI
</h3>
<FeatureList />
</div>
)
}
25 changes: 24 additions & 1 deletion ee/tabby-ui/components/ui/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,28 @@ function IconFolderGit({ className, ...props }: React.ComponentProps<'svg'>) {
)
}

function IconSparkles({ className, ...props }: React.ComponentProps<'svg'>) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className={cn('h-4 w-4', className)}
{...props}
>
<path d="m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z" />
<path d="M5 3v4" />
<path d="M19 17v4" />
<path d="M3 5h4" />
<path d="M17 19h4" />
</svg>
)
}

export {
IconEdit,
IconNextChat,
Expand Down Expand Up @@ -1248,5 +1270,6 @@ export {
IconCheckCircled,
IconCrossCircled,
IconInfoCircled,
IconFolderGit
IconFolderGit,
IconSparkles
}
2 changes: 1 addition & 1 deletion ee/tabby-ui/components/ui/switch.tsx
wsxiaoys marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Switch = React.forwardRef<
>(({ className, ...props }, ref) => (
<SwitchPrimitives.Root
className={cn(
'peer inline-flex h-[24px] w-[44px] shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input',
'peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input',
className
)}
{...props}
Expand Down
30 changes: 22 additions & 8 deletions ee/tabby-ui/lib/experiment-flags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import useLocalStorage from 'use-local-storage'
import { useEffect, useState } from 'react'

class ExperimentFlag {
constructor(
Expand Down Expand Up @@ -39,18 +39,32 @@ 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