mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 19:05:06 +03:00
* add edge function knowledge * deploy edge function mutaton * add edge function block with deploy * update function url * update tools * editor sql * add templates * use monaco editor * hook up templates * fixes * add behind feature flag * preview docs * move editor * initialPrompt * consolidate widgets * remove generic editor * move logic * fix ts * include schema metadata * Fix width of save snippet button * Set tooltip position * Use inlineLink component * Remove unnecessary z index * Lint * Lint import statements in EditorPanel * fixes * fix keyboard shortcut * show/hide results and invalidation * fix focus issues in widget * fixes * fix ts * Support cmd enter shortcut to run query in InlineEditor * Update InlineEditorPreview to use admonition * prompt updates * add discussion url to preview * schemas array * One last clean up --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
93 lines
2.7 KiB
TypeScript
93 lines
2.7 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 InlineEditorPreview from './InlineEditorPreview'
|
|
|
|
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,
|
|
},
|
|
{
|
|
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_INLINE_EDITOR,
|
|
name: 'Inline SQL Editor',
|
|
content: <InlineEditorPreview />,
|
|
discussionsUrl: 'https://github.com/orgs/supabase/discussions/33690',
|
|
isNew: true,
|
|
},
|
|
]
|
|
|
|
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 useIsInlineEditorEnabled = () => {
|
|
const { flags } = useFeaturePreviewContext()
|
|
return flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_INLINE_EDITOR]
|
|
}
|