:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { useActions, useValues } from 'kea'
import { useState } from 'react'
import { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'
import { TeamMembershipLevel } from 'lib/constants'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { LemonSwitch } from 'lib/lemon-ui/LemonSwitch'
import { teamLogic } from 'scenes/teamLogic'
export function PreAggregatedTablesSetting(): JSX.Element {
const { updateCurrentTeam } = useActions(teamLogic)
const { currentTeam } = useValues(teamLogic)
const restrictedReason = useRestrictedArea({
scope: RestrictionScope.Project,
minimumAccessLevel: TeamMembershipLevel.Admin,
})
const savedSetting = currentTeam?.modifiers?.useWebAnalyticsPreAggregatedTables
const [useWebAnalyticsPreAggregatedTables, setUseWebAnalyticsPreAggregatedTables] = useState<boolean>(
savedSetting ?? false
)
const handleChange = (mode: boolean): void => {
updateCurrentTeam({ modifiers: { ...currentTeam?.modifiers, useWebAnalyticsPreAggregatedTables: mode } })
}
return (
<>
<LemonSwitch
checked={useWebAnalyticsPreAggregatedTables}
onChange={(newValue) => setUseWebAnalyticsPreAggregatedTables(newValue)}
disabledReason={restrictedReason}
/>
<div className="mt-4">
<LemonButton
type="primary"
onClick={() => handleChange(useWebAnalyticsPreAggregatedTables)}
disabledReason={
useWebAnalyticsPreAggregatedTables === savedSetting ? 'No changes to save' : restrictedReason
}
>
Save
</LemonButton>
</div>
</>
)
}