Files
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

100 lines
4.4 KiB
TypeScript

import { memo } from 'react'
import { useMDXComponents } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
export const MultivariateFlagSnippet = memo(({ language = 'javascript' }: { language?: string }): JSX.Element => {
const { CodeBlock, dedent } = useMDXComponents()
const snippets: Record<string, string> = {
javascript: dedent`
const matchedFlag = insights.getFeatureFlagResult('flag-key')
if (matchedFlag?.variant == 'variant-key') { // replace 'variant-key' with the key of your variant
// Do something differently for this user
// Optional: read the payload from the same result
const matchedFlagPayload = matchedFlag?.payload
}
`,
react: dedent`
import { useFeatureFlagVariantKey } from '@hanzo/react'
function App() {
const variantKey = useFeatureFlagVariantKey('show-welcome-message')
let welcomeMessage = ''
if (variantKey === 'variant-a') {
welcomeMessage = 'Welcome to the Alpha!'
} else if (variantKey === 'variant-b') {
welcomeMessage = 'Welcome to the Beta!'
}
return (
<div className="App">
{welcomeMessage ? (
<div>
<h1>{welcomeMessage}</h1>
<p>Thanks for trying out our feature flags.</p>
</div>
) : (
<div>
<h2>No welcome message</h2>
<p>Because the feature flag evaluated to false.</p>
</div>
)}
</div>
)
}
`,
'node.js': dedent`
const enabledVariant = await client.getFeatureFlag('flag-key', 'distinct_id_of_your_user')
if (enabledVariant === 'variant-key') { // replace 'variant-key' with the key of your variant
// Do something differently for this user
// Optional: fetch the payload
const matchedFlagPayload = await client.getFeatureFlagPayload('flag-key', 'distinct_id_of_your_user', enabledVariant)
}
`,
python: dedent`
enabled_variant = insights.get_feature_flag('flag-key', 'distinct_id_of_your_user')
if enabled_variant == 'variant-key': # replace 'variant-key' with the key of your variant
# Do something differently for this user
# Optional: fetch the payload
matched_flag_payload = insights.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
`,
php: dedent`
$enabledVariant = Insights::getFeatureFlag('flag-key', 'distinct_id_of_your_user')
if ($enabledVariant === 'variant-key') { # replace 'variant-key' with the key of your variant
# Do something differently for this user
}
`,
ruby: dedent`
enabled_variant = insights.get_feature_flag('flag-key', 'distinct_id_of_your_user')
if enabled_variant == 'variant-key' # replace 'variant-key' with the key of your variant
# Do something differently for this user
# Optional: fetch the payload
matched_flag_payload = insights.get_feature_flag_payload('flag-key', 'distinct_id_of_your_user')
end
`,
go: dedent`
enabledVariant, err := client.GetFeatureFlag(insights.FeatureFlagPayload{
Key: "flag-key",
DistinctId: "distinct_id_of_your_user",
})
if err != nil {
// Handle error (e.g. capture error and fallback to default behaviour)
}
if enabledVariant == "variant-key" { // replace 'variant-key' with the key of your variant
// Do something differently for this user
}
`,
}
const langMap: Record<string, string> = {
javascript: 'javascript',
react: 'jsx',
'node.js': 'javascript',
python: 'python',
php: 'php',
ruby: 'ruby',
go: 'go',
}
return <CodeBlock language={langMap[language] || 'javascript'} code={snippets[language] || snippets.javascript} />
})