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: Add Flutter feature flags snippets #19563

Merged
merged 4 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion cypress/e2e/featureFlags.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Feature Flags', () => {
cy.get('[data-attr=feature-flag-doc-link]').should(
'have.attr',
'href',
'https://posthog.com/docs/integrations/php-integration?utm_medium=in-product&utm_campaign=feature-flag#feature-flags'
'https://posthog.com/docs/libraries/php?utm_medium=in-product&utm_campaign=feature-flag#feature-flags'
)

// select "add filter" and "property"
Expand Down
26 changes: 17 additions & 9 deletions frontend/src/scenes/feature-flags/FeatureFlagCodeOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
AndroidSnippet,
APISnippet,
FeatureFlagSnippet,
FlutterSnippet,
GolangSnippet,
iOSSnippet,
JSBootstrappingSnippet,
Expand Down Expand Up @@ -39,28 +40,28 @@ export enum LibraryType {
export const OPTIONS: InstructionOption[] = [
{
value: 'JavaScript',
documentationLink: `${DOC_BASE_URL}integrations/js-integration${UTM_TAGS}`,
documentationLink: `${DOC_BASE_URL}libraries/js${UTM_TAGS}`,
Snippet: JSSnippet,
type: LibraryType.Client,
key: SDKKey.JS_WEB,
},
{
value: 'Android',
documentationLink: `${DOC_BASE_URL}integrate/client/android${UTM_TAGS}`,
documentationLink: `${DOC_BASE_URL}libraries/android${UTM_TAGS}`,
Snippet: AndroidSnippet,
type: LibraryType.Client,
key: SDKKey.ANDROID,
},
{
value: 'iOS',
documentationLink: `${DOC_BASE_URL}integrate/client/ios${UTM_TAGS}`,
documentationLink: `${DOC_BASE_URL}libraries/ios${UTM_TAGS}`,
Snippet: iOSSnippet,
type: LibraryType.Client,
key: SDKKey.IOS,
},
{
value: 'React Native',
documentationLink: `${DOC_BASE_URL}integrate/client/react-native${UTM_TAGS}`,
documentationLink: `${DOC_BASE_URL}libraries/react-native${UTM_TAGS}`,
Snippet: ReactNativeSnippet,
type: LibraryType.Client,
key: SDKKey.REACT_NATIVE,
Expand All @@ -74,21 +75,21 @@ export const OPTIONS: InstructionOption[] = [
},
{
value: 'Node.js',
documentationLink: `${DOC_BASE_URL}integrations/node-integration${UTM_TAGS}`,
documentationLink: `${DOC_BASE_URL}libraries/node${UTM_TAGS}`,
Snippet: NodeJSSnippet,
type: LibraryType.Server,
key: SDKKey.NODE_JS,
},
{
value: 'Python',
documentationLink: `${DOC_BASE_URL}integrations/python-integration${UTM_TAGS}`,
documentationLink: `${DOC_BASE_URL}libraries/python${UTM_TAGS}`,
Snippet: PythonSnippet,
type: LibraryType.Server,
key: SDKKey.PYTHON,
},
{
value: 'Ruby',
documentationLink: `${DOC_BASE_URL}integrations/ruby-integration${UTM_TAGS}`,
documentationLink: `${DOC_BASE_URL}libraries/ruby${UTM_TAGS}`,
Snippet: RubySnippet,
type: LibraryType.Server,
key: SDKKey.RUBY,
Expand All @@ -102,18 +103,25 @@ export const OPTIONS: InstructionOption[] = [
},
{
value: 'PHP',
documentationLink: `${DOC_BASE_URL}integrations/php-integration${UTM_TAGS}`,
documentationLink: `${DOC_BASE_URL}libraries/php${UTM_TAGS}`,
Snippet: PHPSnippet,
type: LibraryType.Server,
key: SDKKey.PHP,
},
{
value: 'Go',
documentationLink: `${DOC_BASE_URL}integrations/go-integration${UTM_TAGS}`,
documentationLink: `${DOC_BASE_URL}libraries/go${UTM_TAGS}`,
Snippet: GolangSnippet,
type: LibraryType.Server,
key: SDKKey.GO,
},
{
value: 'Flutter',
documentationLink: `${DOC_BASE_URL}libraries/flutter${UTM_TAGS}`,
Snippet: FlutterSnippet,
type: LibraryType.Client,
key: SDKKey.FLUTTER,
},
]

export const LOCAL_EVALUATION_LIBRARIES: string[] = [SDKKey.NODE_JS, SDKKey.PYTHON, SDKKey.RUBY, SDKKey.PHP, SDKKey.GO]
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/scenes/feature-flags/FeatureFlagSnippets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,17 @@ export function AndroidSnippet({ flagKey, multivariant, payload }: FeatureFlagSn
)
}

export function FlutterSnippet({ flagKey }: FeatureFlagSnippet): JSX.Element {
return (
<CodeSnippet language={Language.Dart} wrap>
{`if (await Posthog().isFeatureEnabled('${flagKey}') ?? false) {
// do something
}
`}
</CodeSnippet>
)
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SDKInstructionsMap, SDKKey } from '~/types'
import {
FeatureFlagsAndroidInstructions,
FeatureFlagsAPIInstructions,
FeatureFlagsFlutterInstructions,
FeatureFlagsGoInstructions,
FeatureFlagsIOSInstructions,
FeatureFlagsJSWebInstructions,
Expand All @@ -22,11 +23,12 @@ export const FeatureFlagsSDKInstructions: SDKInstructionsMap = {
[SDKKey.IOS]: FeatureFlagsIOSInstructions,
[SDKKey.REACT_NATIVE]: FeatureFlagsRNInstructions,
[SDKKey.ANDROID]: FeatureFlagsAndroidInstructions,
[SDKKey.FLUTTER]: FeatureFlagsFlutterInstructions,
[SDKKey.NODE_JS]: FeatureFlagsNodeInstructions,
[SDKKey.PYTHON]: FeatureFlagsPythonInstructions,
[SDKKey.RUBY]: FeatureFlagsRubyInstructions,
[SDKKey.PHP]: FeatureFlagsPHPInstructions,
[SDKKey.GO]: FeatureFlagsGoInstructions,
[SDKKey.API]: FeatureFlagsAPIInstructions,
// add flutter, rust, gatsby, nuxt, vue, svelte, and others here
// add rust, gatsby, nuxt, vue, svelte, and others here
}
13 changes: 13 additions & 0 deletions frontend/src/scenes/onboarding/sdks/feature-flags/flutter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SDKKey } from '~/types'

import { SDKInstallFlutterInstructions } from '../sdk-install-instructions'
import { FlagImplementationSnippet } from './flagImplementationSnippet'

export function FeatureFlagsFlutterInstructions(): JSX.Element {
return (
<>
<SDKInstallFlutterInstructions />
<FlagImplementationSnippet sdkKey={SDKKey.FLUTTER} />
</>
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './android'
export * from './api'
export * from './flutter'
export * from './go'
export * from './ios'
export * from './js-web'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function FlutterIOSSetupSnippet(): JSX.Element {
currentTeam?.api_token +
'</string>\n\t<key>com.posthog.posthog.POSTHOG_HOST</key>\n\t<string>' +
url +
'</string>\n\t<key>com.posthog.posthog.TRACK_APPLICATION_LIFECYCLE_EVENTS</key>\n\t<false/>\n\t[...]\n</dict>'}
'</string>\n\t<key>com.posthog.posthog.CAPTURE_APPLICATION_LIFECYCLE_EVENTS</key>\n\t<false/>\n\t[...]\n</dict>'}
</CodeSnippet>
)
}
Expand Down
Loading