From 555a05d3ec087356d7d4bf1385bb780fcc026864 Mon Sep 17 00:00:00 2001 From: Wasiq Bhamla Date: Sun, 1 Dec 2024 01:04:11 +0530 Subject: [PATCH] feat: :sparkles: added feature toggle support (#99) * feat: :sparkles: added feature toggle support * fix: :bug: fixed issue with client component use * fix: :bug: added missing env to workflow * fix: :bug: fixed failing test workflow --- .github/workflows/test.yml | 3 + README.md | 1 + apps/web/.env.example | 1 + apps/web/app/layout.tsx | 42 +- apps/web/package.json | 3 +- package.json | 8 +- packages/analytics/package.json | 2 +- packages/feature-toggle/package.json | 25 ++ packages/feature-toggle/src/client.ts | 14 + packages/feature-toggle/src/flag-list.ts | 1 + packages/feature-toggle/src/provider.tsx | 32 ++ packages/feature-toggle/tsconfig.json | 11 + packages/ui/package.json | 3 +- packages/ui/src/home/faq.tsx | 41 +- packages/ui/src/home/hero.tsx | 12 +- packages/utils/tsconfig.json | 4 +- pnpm-lock.yaml | 463 +++++++++++++---------- 17 files changed, 403 insertions(+), 263 deletions(-) create mode 100644 apps/web/.env.example create mode 100644 packages/feature-toggle/package.json create mode 100644 packages/feature-toggle/src/client.ts create mode 100644 packages/feature-toggle/src/flag-list.ts create mode 100644 packages/feature-toggle/src/provider.tsx create mode 100644 packages/feature-toggle/tsconfig.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 94469e4..d33707d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,6 +37,9 @@ jobs: build: runs-on: ubuntu-latest needs: lint + environment: Preview + env: + NEXT_PUBLIC_FLAGSMITH_ENVIRONMENT_ID: ${{ secrets.NEXT_PUBLIC_FLAGSMITH_ENVIRONMENT_ID }} steps: - name: Check out Git repository diff --git a/README.md b/README.md index dfe58ef..1a40067 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Ultra-Reporter leverages cutting-edge technologies to provide fast, efficient, a - **[Turborepo](https://turborepo.org/)**: Fast, efficient monorepo management. - **[ESLint](https://eslint.org/) & [Prettier](https://prettier.io/)**: Enforce consistent code style and automate code formatting. - **[Prettier](https://prettier.io/)**: Code formatter. +- **[Flagsmith](https://www.flagsmith.com/)**: Feature flag management. - **[Vercel](https://vercel.com/)**: Next.js is deployed on Vercel, a platform for static websites and serverless functions. ## ⏱️ What's Next? diff --git a/apps/web/.env.example b/apps/web/.env.example new file mode 100644 index 0000000..4c9a877 --- /dev/null +++ b/apps/web/.env.example @@ -0,0 +1 @@ +NEXT_PUBLIC_FLAGSMITH_ENVIRONMENT_ID= \ No newline at end of file diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsx index 5ce8503..62a282a 100644 --- a/apps/web/app/layout.tsx +++ b/apps/web/app/layout.tsx @@ -1,5 +1,7 @@ import { GoogleAnalytics } from '@next/third-parties/google'; import { Provider as AnalyticsProvider } from '@ultra-reporter/analytics/client'; +import { getFeatureState } from '@ultra-reporter/feature-toggle/client'; +import { FeatureProvider } from '@ultra-reporter/feature-toggle/provider'; import '@ultra-reporter/ui/global.css'; import { Footer } from '@ultra-reporter/ui/home/footer'; import { ScrollToTop } from '@ultra-reporter/ui/home/scroll-to-top'; @@ -63,33 +65,37 @@ export const metadata: Metadata = { }, }; -const RootLayout = ({ +const RootLayout = async ({ children, }: Readonly<{ children: React.ReactNode; -}>): DetailedHTMLProps< - HtmlHTMLAttributes, - HTMLHtmlElement +}>): Promise< + DetailedHTMLProps, HTMLHtmlElement> > => { + const featureState = await getFeatureState(); return ( - - - {children} - -