Skip to content

Commit

Permalink
feat: implemented feature flag support (#2180)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickytonline authored Nov 18, 2023
2 parents e595ae9 + 06fbd4a commit a53dfb6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
14 changes: 14 additions & 0 deletions components/shared/feature-flagged.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FeatureFlag } from "lib/utils/server/feature-flags";

interface FeatureFlaggedProps {
flag: FeatureFlag;
children: React.ReactElement;
featureFlags: Record<FeatureFlag, boolean>;
}
export const FeatureFlagged = ({ flag, featureFlags, children }: FeatureFlaggedProps) => {
if (featureFlags[flag]) {
return children;
}

return null;
};
17 changes: 17 additions & 0 deletions lib/utils/server/feature-flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PostHog } from "posthog-node";

export type FeatureFlag = "contributions_evolution_by_type";

export async function getAllFeatureFlags(userId: number) {
const client = new PostHog(
process.env.NEXT_PUBLIC_POSTHOG_ID as string,

{ host: "https://app.posthog.com" }
);

const featureFlags = await client.getAllFlags(`${userId}`);

await client.shutdownAsync();

return featureFlags;
}
34 changes: 22 additions & 12 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"octokit": "^2.0.14",
"path-to-regexp": "^6.2.1",
"posthog-js": "^1.83.0",
"posthog-node": "^3.1.3",
"react": "^18.2.0",
"react-csv": "^2.2.2",
"react-day-picker": "^8.7.1",
Expand Down

0 comments on commit a53dfb6

Please sign in to comment.