mirror of
https://github.com/supabase/supabase.git
synced 2026-07-07 05:24:36 +08:00
* Remove feature preview for the conversational AI for SQL editor. * Remove all code related to the previous implementation of editor ai. * Update the snapshots for the ai commands. * Remove unneeded code from the ai panel. * Show the diff bar when debugging. * Convert the updateEditor function into a callback. * Simplify the debugging functionality by using react state instead of react context. * Erase the AI disclaimer when formatting code as modification. * Add a button to clear the chat history.
72 lines
2.4 KiB
TypeScript
72 lines
2.4 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'
|
|
|
|
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({
|
|
[LOCAL_STORAGE_KEYS.UI_PREVIEW_NAVIGATION_LAYOUT]: false,
|
|
[LOCAL_STORAGE_KEYS.UI_PREVIEW_API_SIDE_PANEL]: false,
|
|
[LOCAL_STORAGE_KEYS.UI_PREVIEW_RLS_AI_ASSISTANT]: false,
|
|
[LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS]: false,
|
|
})
|
|
|
|
useEffect(() => {
|
|
if (typeof window !== 'undefined') {
|
|
setFlags({
|
|
[LOCAL_STORAGE_KEYS.UI_PREVIEW_NAVIGATION_LAYOUT]:
|
|
localStorage.getItem(LOCAL_STORAGE_KEYS.UI_PREVIEW_NAVIGATION_LAYOUT) === 'true',
|
|
[LOCAL_STORAGE_KEYS.UI_PREVIEW_API_SIDE_PANEL]:
|
|
localStorage.getItem(LOCAL_STORAGE_KEYS.UI_PREVIEW_API_SIDE_PANEL) === 'true',
|
|
[LOCAL_STORAGE_KEYS.UI_PREVIEW_RLS_AI_ASSISTANT]:
|
|
localStorage.getItem(LOCAL_STORAGE_KEYS.UI_PREVIEW_RLS_AI_ASSISTANT) === 'true',
|
|
[LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS]:
|
|
localStorage.getItem(LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS) === '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 useIsRLSAIAssistantEnabled = () => {
|
|
const { flags } = useFeaturePreviewContext()
|
|
return flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_RLS_AI_ASSISTANT]
|
|
}
|
|
|
|
export const useIsColumnLevelPrivilegesEnabled = () => {
|
|
const { flags } = useFeaturePreviewContext()
|
|
return flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS]
|
|
}
|