mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 12:25:05 +03:00
Allow to use the `pg-delta` capability for merge requests diffing. Feature flag it behind an auto opt-in flag. Must be merged after: https://github.com/supabase/platform/pull/29776 <img width="921" height="623" alt="Screenshot 2026-02-17 at 16 50 38" src="https://github.com/user-attachments/assets/bfe704e9-4137-45e1-b0b5-1cecce284d6e" /> Also updated the loading + final state of the diff view to: 1. Take all the height available - From: <img width="1894" height="893" alt="Screenshot 2026-02-16 at 20 46 15" src="https://github.com/user-attachments/assets/22ed8c72-2d9d-4b68-b315-6d40aefc0b3c" /> - To: <img width="1629" height="1396" alt="Screenshot 2026-02-16 at 20 57 26" src="https://github.com/user-attachments/assets/6e83c8e9-607d-4077-977e-046058ce3e44" /> 2. Show a proper loading state rather than just a plain grey skeleton - From: <img width="2232" height="1137" alt="Screenshot 2026-02-20 at 15 02 51" src="https://github.com/user-attachments/assets/0c924b04-d60f-49b5-a5a0-3bf1942bfdef" /> - To: <img width="2231" height="1129" alt="Screenshot 2026-02-20 at 15 05 46" src="https://github.com/user-attachments/assets/49751001-1818-4842-a0c8-b74683c2e9bc" />
161 lines
4.8 KiB
TypeScript
161 lines
4.8 KiB
TypeScript
import { FeatureFlagContext, LOCAL_STORAGE_KEYS, useFlag } from 'common'
|
|
import { EMPTY_OBJ } from 'lib/void'
|
|
import { noop } from 'lodash'
|
|
import { useQueryState } from 'nuqs'
|
|
import {
|
|
createContext,
|
|
useCallback,
|
|
useContext,
|
|
useEffect,
|
|
useMemo,
|
|
useState,
|
|
type PropsWithChildren,
|
|
} from 'react'
|
|
|
|
import { useFeaturePreviews } from './useFeaturePreviews'
|
|
import { useStaticEffectEvent } from '@/hooks/useStaticEffectEvent'
|
|
|
|
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 { hasLoaded } = useContext(FeatureFlagContext)
|
|
const featurePreviews = useFeaturePreviews()
|
|
|
|
const [flags, setFlags] = useState(() =>
|
|
featurePreviews.reduce((a, b) => ({ ...a, [b.key]: false }), {})
|
|
)
|
|
|
|
const initializeFlags = useStaticEffectEvent(() => {
|
|
setFlags(
|
|
featurePreviews.reduce((a, b) => {
|
|
const defaultOptIn = b.isDefaultOptIn
|
|
const localStorageValue = localStorage.getItem(b.key)
|
|
return {
|
|
...a,
|
|
[b.key]: !localStorageValue ? defaultOptIn : localStorageValue === 'true',
|
|
}
|
|
}, {})
|
|
)
|
|
})
|
|
|
|
useEffect(() => {
|
|
if (typeof window !== 'undefined') {
|
|
initializeFlags()
|
|
}
|
|
}, [hasLoaded, initializeFlags])
|
|
|
|
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 useUnifiedLogsPreview = () => {
|
|
const { flags, onUpdateFlag } = useFeaturePreviewContext()
|
|
|
|
const isEnabled = flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_UNIFIED_LOGS]
|
|
|
|
const enable = () => onUpdateFlag(LOCAL_STORAGE_KEYS.UI_PREVIEW_UNIFIED_LOGS, true)
|
|
const disable = () => onUpdateFlag(LOCAL_STORAGE_KEYS.UI_PREVIEW_UNIFIED_LOGS, false)
|
|
|
|
return { isEnabled, enable, disable }
|
|
}
|
|
|
|
export const useIsBranching2Enabled = () => {
|
|
const { flags } = useFeaturePreviewContext()
|
|
const gitlessBranchingEnabled = useFlag('gitlessBranching')
|
|
return gitlessBranchingEnabled && flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_BRANCHING_2_0]
|
|
}
|
|
|
|
export const useIsPgDeltaDiffEnabled = () => {
|
|
const { flags } = useFeaturePreviewContext()
|
|
const pgDeltaDiffEnabled = useFlag('pgdeltaDiff')
|
|
return pgDeltaDiffEnabled && flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_PG_DELTA_DIFF]
|
|
}
|
|
|
|
export const useIsAdvisorRulesEnabled = () => {
|
|
const { flags } = useFeaturePreviewContext()
|
|
const advisorRulesEnabled = useFlag('advisorRules')
|
|
return advisorRulesEnabled && flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_ADVISOR_RULES]
|
|
}
|
|
|
|
export const useIsQueueOperationsEnabled = () => {
|
|
const { flags } = useFeaturePreviewContext()
|
|
return flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_QUEUE_OPERATIONS]
|
|
}
|
|
|
|
export const useIsTableFilterBarEnabled = () => {
|
|
const { flags } = useFeaturePreviewContext()
|
|
return flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_TABLE_FILTER_BAR]
|
|
}
|
|
|
|
export const useFeaturePreviewModal = () => {
|
|
const featurePreviews = useFeaturePreviews()
|
|
const [featurePreviewModal, setFeaturePreviewModal] = useQueryState('featurePreviewModal')
|
|
|
|
const selectedFeatureKeyFromQuery = featurePreviewModal?.trim() ?? null
|
|
const showFeaturePreviewModal = selectedFeatureKeyFromQuery !== null
|
|
|
|
const selectedFeatureKey = (
|
|
!selectedFeatureKeyFromQuery ? featurePreviews[0].key : selectedFeatureKeyFromQuery
|
|
) as (typeof featurePreviews)[number]['key']
|
|
|
|
const selectFeaturePreview = useCallback(
|
|
(featureKey: (typeof featurePreviews)[number]['key']) => {
|
|
setFeaturePreviewModal(featureKey)
|
|
},
|
|
[setFeaturePreviewModal]
|
|
)
|
|
|
|
const toggleFeaturePreviewModal = useCallback(
|
|
(value: boolean) => {
|
|
if (!value) {
|
|
setFeaturePreviewModal(null)
|
|
} else {
|
|
selectFeaturePreview(selectedFeatureKey)
|
|
}
|
|
},
|
|
[selectFeaturePreview, setFeaturePreviewModal, selectedFeatureKey]
|
|
)
|
|
|
|
return useMemo(
|
|
() => ({
|
|
showFeaturePreviewModal,
|
|
selectedFeatureKey,
|
|
selectFeaturePreview,
|
|
toggleFeaturePreviewModal,
|
|
}),
|
|
[showFeaturePreviewModal, selectedFeatureKey, selectFeaturePreview, toggleFeaturePreviewModal]
|
|
)
|
|
}
|