mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
* Remove assistant V2 from feature preview * Hide fix with assistant button in rls editor
80 lines
2.2 KiB
TypeScript
80 lines
2.2 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'
|
|
|
|
export const FEATURE_PREVIEWS = [
|
|
{
|
|
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]
|
|
}
|