Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Enable Android/RN/iOS code snippets for feature flags #19482

Merged
merged 16 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion frontend/src/scenes/feature-flags/FeatureFlagCodeOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,16 @@ export const OPTIONS: InstructionOption[] = [

export const LOCAL_EVALUATION_LIBRARIES: string[] = [SDKKey.NODE_JS, SDKKey.PYTHON, SDKKey.RUBY, SDKKey.PHP, SDKKey.GO]

export const PAYLOAD_LIBRARIES: string[] = [SDKKey.JS_WEB, SDKKey.NODE_JS, SDKKey.PYTHON, SDKKey.RUBY, SDKKey.REACT]
export const PAYLOAD_LIBRARIES: string[] = [
SDKKey.JS_WEB,
SDKKey.NODE_JS,
SDKKey.PYTHON,
SDKKey.RUBY,
SDKKey.REACT,
SDKKey.ANDROID,
SDKKey.REACT_NATIVE,
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
SDKKey.IOS,
]

export const BOOTSTRAPPING_OPTIONS: InstructionOption[] = [
{
Expand Down
33 changes: 30 additions & 3 deletions frontend/src/scenes/feature-flags/FeatureFlagSnippets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,17 @@ if ${conditional}:
)
}

export function AndroidSnippet({ flagKey, multivariant }: FeatureFlagSnippet): JSX.Element {
export function AndroidSnippet({ flagKey, multivariant, payload }: FeatureFlagSnippet): JSX.Element {
const clientSuffix = 'PostHog.'

if (payload) {
return (
<CodeSnippet language={Language.Kotlin} wrap>
{`${clientSuffix}getFeatureFlagPayload("${flagKey}")`}
</CodeSnippet>
)
}

const flagFunction = multivariant ? 'getFeatureFlag' : 'isFeatureEnabled'

const variantSuffix = multivariant ? ` == "example-variant"` : ''
Expand All @@ -327,8 +336,17 @@ export function AndroidSnippet({ flagKey, multivariant }: FeatureFlagSnippet): J
)
}

export function iOSSnippet({ flagKey, multivariant }: FeatureFlagSnippet): JSX.Element {
export function iOSSnippet({ flagKey, multivariant, payload }: FeatureFlagSnippet): JSX.Element {
const clientSuffix = 'posthog.'

if (payload) {
return (
<CodeSnippet language={Language.Swift} wrap>
{`${clientSuffix}getFeatureFlagStringPayload("${flagKey}", defaultValue: "myDefaultValue")`}
</CodeSnippet>
)
}

const flagFunction = multivariant ? 'getFeatureFlag' : 'isFeatureEnabled'

const variantSuffix = multivariant ? ` == 'example-variant'` : ''
Expand All @@ -344,8 +362,17 @@ if (${clientSuffix}${flagFunction}('${flagKey}') ${variantSuffix}) {
)
}

export function ReactNativeSnippet({ flagKey, multivariant }: FeatureFlagSnippet): JSX.Element {
export function ReactNativeSnippet({ flagKey, multivariant, payload }: FeatureFlagSnippet): JSX.Element {
const clientSuffix = 'posthog.'

if (payload) {
return (
<CodeSnippet language={Language.JSX} wrap>
{`${clientSuffix}getFeatureFlagPayload('${flagKey}'`}
</CodeSnippet>
)
}

const flagFunction = multivariant ? 'getFeatureFlag' : 'isFeatureEnabled'

const variantSuffix = multivariant ? ` == 'example-variant'` : ''
Expand Down
Loading