Skip to content

Commit

Permalink
chore(3000): setup feature flag for experiment (#19053)
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr authored Dec 5, 2023
1 parent fc0bd60 commit 421b2dd
Show file tree
Hide file tree
Showing 31 changed files with 62 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const sidePanelSettingsLogic = kea<sidePanelSettingsLogicType>([

listeners(({ actions, values }) => ({
openSettingsPanel: ({ settingsLogicProps }) => {
if (!values.featureFlags[FEATURE_FLAGS.POSTHOG_3000]) {
if (values.featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'control') {
LemonDialog.open({
title: 'Settings',
content: <Settings {...settingsLogicProps} hideSections logicKey="modal" />,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout/navigation-3000/themeLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const themeLogic = kea<themeLogicType>([
}
// Dark mode is a PostHog 3000 feature
// User-saved preference is used when set, oterwise we fall back to the system value
return featureFlags[FEATURE_FLAGS.POSTHOG_3000]
return featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test'
? user?.theme_mode
? user.theme_mode === 'dark'
: darkModeSystemPreference
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout/navigation/TopBar/NotebookButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { notebookPanelLogic } from 'scenes/notebooks/NotebookPanel/notebookPanel
export function NotebookButton(): JSX.Element {
const { visibility } = useValues(notebookPanelLogic)
const { toggleVisibility } = useActions(notebookPanelLogic)
const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')

const overrides3000: Partial<LemonButtonWithSideActionProps> = is3000
? {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout/navigation/TopBar/SitePopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export function SitePopoverOverlay(): JSX.Element {
</SitePopoverSection>
)}
<SitePopoverSection>
<FlaggedFeature flag={FEATURE_FLAGS.POSTHOG_3000}>
<FlaggedFeature flag={FEATURE_FLAGS.POSTHOG_3000} match="test">
<ThemeSwitcher />
</FlaggedFeature>
<LemonButton
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/components/CodeSnippet/CodeSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function CodeSnippet({
/>
</div>
<SyntaxHighlighter
style={featureFlags[FEATURE_FLAGS.POSTHOG_3000] ? synthwave84 : okaidia}
style={featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test' ? synthwave84 : okaidia}
language={language}
wrapLines={wrap}
lineProps={{ style: { whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' } }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CommandResults } from './CommandResults'
export function CommandPalette(): JSX.Element {
const { featureFlags } = useValues(featureFlagLogic)

const isUsingCmdKSearch = featureFlags[FEATURE_FLAGS.POSTHOG_3000]
const isUsingCmdKSearch = featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test'

if (isUsingCmdKSearch) {
return <CommandBar />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export const commandPaletteLogic = kea<commandPaletteLogicType>([
selectors({
isUsingCmdKSearch: [
(selectors) => [selectors.featureFlags],
(featureFlags) => featureFlags[FEATURE_FLAGS.POSTHOG_3000],
(featureFlags) => featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test',
],
isSqueak: [
(selectors) => [selectors.input],
Expand Down Expand Up @@ -1008,7 +1008,7 @@ export const commandPaletteLogic = kea<commandPaletteLogicType>([
actions.registerCommand(createDashboard)
actions.registerCommand(shareFeedback)
actions.registerCommand(debugCopySessionRecordingURL)
if (values.featureFlags[FEATURE_FLAGS.POSTHOG_3000]) {
if (values.featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test') {
actions.registerCommand(toggleTheme)
actions.registerCommand(toggleHedgehogMode)
actions.registerCommand(shortcuts)
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lib/components/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ export function PageHeader({
delimited,
notebookProps,
}: PageHeaderProps): JSX.Element | null {
const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')
const { actionsContainer } = useValues(breadcrumbsLogic)

return (
<>
{!is3000 && (
// eslint-disable-next-line react/forbid-dom-props
<div className="page-title-row flex justify-between" style={style}>
<div className="min-w-0">
{!is3000 &&
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/components/Support/supportLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export const supportLogic = kea<supportLogicType>([
actionToUrl(({ values }) => {
return {
closeSupportForm: () => {
if (values.featureFlags[FEATURE_FLAGS.POSTHOG_3000]) {
if (values.featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test') {
return
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/hooks/use3000Body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { themeLogic } from '~/layout/navigation-3000/themeLogic'
import { useFeatureFlag } from './useFeatureFlag'

export function use3000Body(): void {
const is3000 = !!useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')
const { isDarkModeOn } = useValues(themeLogic)

useEffect(() => {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib/hooks/useFeatureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { useValues } from 'kea'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'

export const useFeatureFlag = (flag: keyof typeof FEATURE_FLAGS): boolean => {
export const useFeatureFlag = (flag: keyof typeof FEATURE_FLAGS, match?: string): boolean => {
const { featureFlags } = useValues(featureFlagLogic)

if (match) {
return featureFlags[FEATURE_FLAGS[flag]] === match
}

return !!featureFlags[FEATURE_FLAGS[flag]]
}
2 changes: 1 addition & 1 deletion frontend/src/lib/lemon-ui/LemonMenu/LemonMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function LemonMenuOverlay({ items, tooltipPlacement, itemsRef }: LemonMen
const { featureFlags } = useValues(featureFlagLogic)
const sectionsOrItems = useMemo(() => normalizeItems(items), [items])

const buttonSize = featureFlags[FEATURE_FLAGS.POSTHOG_3000] ? 'small' : 'medium'
const buttonSize = featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test' ? 'small' : 'medium'

return sectionsOrItems.length > 0 && isLemonMenuSection(sectionsOrItems[0]) ? (
<LemonMenuSectionList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function LemonSegmentedButton<T extends React.Key>({
HTMLDivElement,
HTMLLIElement
>(value, 200)
const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')

let buttonProps = {}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/lemon-ui/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const Link: React.FC<LinkProps & React.RefAttributes<HTMLElement>> = Reac
href: typeof to === 'string' ? to : undefined,
})

const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')
const { openDocsPage } = useActions(sidePanelDocsLogic)

const onClick = (event: React.MouseEvent<HTMLElement>): void => {
Expand Down
20 changes: 19 additions & 1 deletion frontend/src/lib/logic/featureFlagLogic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { actions, afterMount, kea, path, reducers } from 'kea'
import { FEATURE_FLAGS } from 'lib/constants'
import { getAppContext } from 'lib/utils/getAppContext'
import posthog from 'posthog-js'

Expand All @@ -22,7 +23,24 @@ function notifyFlagIfNeeded(flag: string, flagState: string | boolean | undefine

function getPersistedFeatureFlags(appContext: AppContext | undefined = getAppContext()): FeatureFlagsSet {
const persistedFeatureFlags = appContext?.persisted_feature_flags || []
return Object.fromEntries(persistedFeatureFlags.map((f) => [f, true]))
/** :HACKY: Handle experiment (non-boolean) feature flag for 3000. */
let has3000Flag = false
const flags = Object.fromEntries(
persistedFeatureFlags.map((f) => {
if (f === FEATURE_FLAGS.POSTHOG_3000) {
has3000Flag = true
return [f, 'test']
} else {
return [f, true]
}
})
)

if (!has3000Flag) {
flags[FEATURE_FLAGS.POSTHOG_3000] = 'control'
}

return flags
}

function spyOnFeatureFlags(featureFlags: FeatureFlagsSet): FeatureFlagsSet {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function AppScene(): JSX.Element | null {
) : null
}

const Navigation = featureFlags[FEATURE_FLAGS.POSTHOG_3000] ? Navigation3000 : NavigationClassic
const Navigation = featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test' ? Navigation3000 : NavigationClassic

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/authentication/InviteSignup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function AuthenticatedAcceptInvite({ invite }: { invite: PrevalidatedInvite }):
function UnauthenticatedAcceptInvite({ invite }: { invite: PrevalidatedInvite }): JSX.Element {
const { signup, isSignupSubmitting } = useValues(inviteSignupLogic)
const { preflight } = useValues(preflightLogic)
const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')

return (
<BridgePage
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/authentication/useButtonStyles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'

export function useButtonStyle(): Record<string, any> {
const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')

return is3000
? {
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/scenes/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ function DashboardScene(): JSX.Element {
</div>
)}
</div>
{placement !== DashboardPlacement.Export && !featureFlags[FEATURE_FLAGS.POSTHOG_3000] && (
<LemonDivider className="my-4" />
)}
{placement !== DashboardPlacement.Export &&
featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'control' && <LemonDivider className="my-4" />}
<DashboardItems />
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/dashboard/EmptyDashboardComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { DASHBOARD_CANNOT_EDIT_MESSAGE } from './DashboardHeader'
import { dashboardLogic } from './dashboardLogic'

function SkeletonCard({ children, active }: { children: React.ReactNode; active: boolean }): JSX.Element {
const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')
const rounded = is3000 ? 'rounded-md' : 'rounded'

return (
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/notebooks/IconNotebook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { IconNotebook as IconNotebookLegacy, LemonIconProps } from 'lib/lemon-ui/icons'

export function IconNotebook(props: LemonIconProps): JSX.Element {
const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')

return is3000 ? <IconNotebook3000 {...props} /> : <IconNotebookLegacy {...props} />
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type NotebookListMiniProps = {
export function NotebookListMini({ selectedNotebookId }: NotebookListMiniProps): JSX.Element {
const { notebooks, notebookTemplates } = useValues(notebooksModel)

const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')

const selectedTitle =
selectedNotebookId === 'scratchpad'
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/notebooks/NotebookCanvasScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function NotebookCanvas(): JSX.Element {

const { duplicateNotebook } = useActions(notebookLogic(logicProps))

const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')

if (!is3000) {
return <NotFound object="canvas" caption={<>Canvas mode requires PostHog 3000</>} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const notebookPanelLogic = kea<notebookPanelLogicType>([
})),

selectors(({ cache, actions }) => ({
is3000: [(s) => [s.featureFlags], (featureFlags) => featureFlags[FEATURE_FLAGS.POSTHOG_3000]],
is3000: [(s) => [s.featureFlags], (featureFlags) => featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test'],

visibility: [
(s) => [s.selectedTab, s.sidePanelOpen, s.popoverVisibility, s.is3000],
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/notebooks/NotebookScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function NotebookScene(): JSX.Element {
const { selectedNotebook, visibility } = useValues(notebookPanelLogic)

const { featureFlags } = useValues(featureFlagLogic)
const buttonSize = featureFlags[FEATURE_FLAGS.POSTHOG_3000] ? 'small' : 'medium'
const buttonSize = featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test' ? 'small' : 'medium'

if (!notebook && !loading && !conflictWarningVisible) {
return <NotFound object="notebook" />
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/persons/personsLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const personsLogic = kea<personsLogicType>([
...(values.listFilters.properties || []),
...values.hiddenListProperties,
]
if (values.featureFlags[FEATURE_FLAGS.POSTHOG_3000]) {
if (values.featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test') {
newFilters.include_total = true // The total count is slow, but needed for infinite loading
}
if (props.cohort) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/project-homepage/ProjectHomepage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function ProjectHomepage(): JSX.Element {
sceneDashboardChoiceModalLogic({ scene: Scene.ProjectHomepage })
)

const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')

const headerButtons = (
<>
Expand Down
13 changes: 7 additions & 6 deletions frontend/src/scenes/saved-insights/SavedInsights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,13 @@ export function InsightIcon({ insight }: { insight: InsightModel }): JSX.Element
export function NewInsightButton({ dataAttr }: NewInsightButtonProps): JSX.Element {
const { featureFlags } = useValues(featureFlagLogic)

const overrides3000: Partial<LemonButtonWithSideActionProps> = featureFlags[FEATURE_FLAGS.POSTHOG_3000]
? {
size: 'small',
icon: <IconPlusMini />,
}
: {}
const overrides3000: Partial<LemonButtonWithSideActionProps> =
featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test'
? {
size: 'small',
icon: <IconPlusMini />,
}
: {}

return (
<LemonButtonWithSideAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function SessionsRecordings(): JSX.Element {
reportRecordingPlaylistCreated('filters')
})

const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')

return (
// Margin bottom hacks the fact that our wrapping container has an annoyingly large padding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function PlayerInspectorControls(): JSX.Element {
const { showOnlyMatching, timestampMode, miniFilters, syncScroll, searchQuery } = useValues(playerSettingsLogic)
const { setShowOnlyMatching, setTimestampMode, setMiniFilter, setSyncScroll, setSearchQuery } =
useActions(playerSettingsLogic)
const is3000 = useFeatureFlag('POSTHOG_3000')
const is3000 = useFeatureFlag('POSTHOG_3000', 'test')

const mode = logicProps.mode ?? SessionRecordingPlayerMode.Standard

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/web-analytics/WebDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Filters = (): JSX.Element => {
} = useValues(webAnalyticsLogic)
const { setWebAnalyticsFilters, setDates } = useActions(webAnalyticsLogic)
const { featureFlags } = useValues(featureFlagLogic)
const hasPosthog3000 = featureFlags[FEATURE_FLAGS.POSTHOG_3000]
const hasPosthog3000 = featureFlags[FEATURE_FLAGS.POSTHOG_3000] === 'test'

return (
<div
Expand Down

0 comments on commit 421b2dd

Please sign in to comment.