mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 05:39:11 +03:00
* start * added panels * remove stuff * fixes and refinements * clean up * remove old assistant panel * resizable assistant kinda * use icon * Add missing package * remove canvas * add suggestions * updated empty state if no tables exist * fix table condition * Implement diffing if using assistant in sql editor * Reinstate old assistant in SQL editor if feature preview is off * pane size adjustment * assistant button corners * Add SQL snippet content to assistant if opening assistant in sql editor * Add the necessary checks for opt in and hipaa * revert adding snippet to assistant when opening assistant in sql editor * Add cmd i shortcut * Add admonitions for when disablePrompt is toggled on, and if no api key is set. Add footer note RE rate limitation * Bump ai package in packages * some fixes for backwards compability depending on feature preview toggled * Rename feature preview property for new assistant * Smol fix * Prevent SQL snippet from running until message is finished * only loading last message * fix z-index * save chat state to global state * add debug to failed ai queries * Add basic contextual invalidation * Add explain code action to SQL editor * Add link to abort ongoing queries from SqlSnippet * Update feature preview content * Fix * Fix * Fix * Te4st * Fix tests * ONly show ai button within a project * Fix PH tracking * Beef up a bit more event tracking * Rough fix to padding when assistant is open * A bit more telemetry stuff * Update prompts * fix rls editing via assistant * Update generate-v3.ts prompt to get auth schema too * Add policy satement to assistant when editing * Address all comments * fixc * Fix SqlSnippet not taking full width on larger viewports * Adjust max width --------- Co-authored-by: Saxon Fletcher <saxonafletcher@gmail.com>
93 lines
2.6 KiB
TypeScript
93 lines
2.6 KiB
TypeScript
import { noop } from 'lodash'
|
|
import { PropsWithChildren, createContext, useContext, useEffect, useState } from 'react'
|
|
|
|
import { LOCAL_STORAGE_KEYS } from 'lib/constants'
|
|
import { EMPTY_OBJ } from 'lib/void'
|
|
import { APISidePanelPreview } from './APISidePanelPreview'
|
|
import { CLSPreview } from './CLSPreview'
|
|
import { AssistantV2Preview } from './AssistantV2Preview'
|
|
|
|
export const FEATURE_PREVIEWS = [
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_ASSISTANT_V2,
|
|
name: 'Supabase AI Assistant V2',
|
|
content: <AssistantV2Preview />,
|
|
discussionsUrl: undefined,
|
|
isNew: true,
|
|
},
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_API_SIDE_PANEL,
|
|
name: 'Project API documentation',
|
|
content: <APISidePanelPreview />,
|
|
discussionsUrl: 'https://github.com/orgs/supabase/discussions/18038',
|
|
isNew: false,
|
|
},
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS,
|
|
name: 'Column-level privileges',
|
|
content: <CLSPreview />,
|
|
discussionsUrl: 'https://github.com/orgs/supabase/discussions/20295',
|
|
isNew: false,
|
|
},
|
|
]
|
|
|
|
type FeaturePreviewContextType = {
|
|
flags: { [key: string]: boolean }
|
|
onUpdateFlag: (key: string, value: boolean) => void
|
|
}
|
|
|
|
const FeaturePreviewContext = createContext<FeaturePreviewContextType>({
|
|
flags: EMPTY_OBJ,
|
|
onUpdateFlag: noop,
|
|
})
|
|
|
|
export const useFeaturePreviewContext = () => useContext(FeaturePreviewContext)
|
|
|
|
export const FeaturePreviewContextProvider = ({ children }: PropsWithChildren<{}>) => {
|
|
const [flags, setFlags] = useState(() =>
|
|
FEATURE_PREVIEWS.reduce((a, b) => {
|
|
return { ...a, [b.key]: false }
|
|
}, {})
|
|
)
|
|
|
|
useEffect(() => {
|
|
if (typeof window !== 'undefined') {
|
|
setFlags(
|
|
FEATURE_PREVIEWS.reduce((a, b) => {
|
|
return { ...a, [b.key]: localStorage.getItem(b.key) === 'true' }
|
|
}, {})
|
|
)
|
|
}
|
|
}, [])
|
|
|
|
const value = {
|
|
flags,
|
|
onUpdateFlag: (key: string, value: boolean) => {
|
|
if (typeof window !== 'undefined') {
|
|
window.localStorage.setItem(key, value.toString())
|
|
}
|
|
const updatedFlags = { ...flags, [key]: value }
|
|
setFlags(updatedFlags)
|
|
},
|
|
}
|
|
|
|
return <FeaturePreviewContext.Provider value={value}>{children}</FeaturePreviewContext.Provider>
|
|
}
|
|
|
|
// Helpers
|
|
|
|
export const useIsAPIDocsSidePanelEnabled = () => {
|
|
const { flags } = useFeaturePreviewContext()
|
|
return flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_API_SIDE_PANEL]
|
|
}
|
|
|
|
export const useIsColumnLevelPrivilegesEnabled = () => {
|
|
const { flags } = useFeaturePreviewContext()
|
|
return flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS]
|
|
}
|
|
|
|
export const useIsAssistantV2Enabled = () => {
|
|
const { flags } = useFeaturePreviewContext()
|
|
return flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_ASSISTANT_V2]
|
|
}
|