-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue #2695] opportunity and search toggle with feature flag env vars (
#3115) * adds maintenance page * adds "kill switch" flags that can be used to direct the search and opportunity pages to * adds ability to set flags with environment variables
- Loading branch information
1 parent
b357de4
commit 7a7b8a8
Showing
19 changed files
with
377 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useTranslations } from "next-intl"; | ||
import { getTranslations, setRequestLocale } from "next-intl/server"; | ||
import { GridContainer } from "@trussworks/react-uswds"; | ||
|
||
export async function generateMetadata({ | ||
params: { locale }, | ||
}: { | ||
params: { locale: string }; | ||
}) { | ||
const t = await getTranslations({ locale }); | ||
return { | ||
title: t("Maintenance.pageTitle"), | ||
description: t("Maintenance.heading"), | ||
}; | ||
} | ||
|
||
export default function Maintenance({ | ||
params: { locale }, | ||
}: { | ||
params: { locale: string }; | ||
}) { | ||
setRequestLocale(locale); | ||
const t = useTranslations("Maintenance"); | ||
|
||
const body = t.rich("body", { | ||
LinkToGrants: (content) => <a href="https://www.grants.gov">{content}</a>, | ||
}); | ||
|
||
return ( | ||
<GridContainer className="padding-y-1 tablet:padding-y-3 desktop-lg:padding-y-6 padding-x-5 tablet:padding-x-7 desktop-lg:padding-x-10 text-center"> | ||
<h2 className="margin-bottom-0">{t("heading")}</h2> | ||
<p>{body}</p> | ||
<p>{t("signOff")}</p> | ||
</GridContainer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,48 @@ | ||
import { environment } from "src/constants/environments"; | ||
import { FeatureFlagsManager } from "src/services/FeatureFlagManager"; | ||
import { ServerSideSearchParams } from "src/types/searchRequestURLTypes"; | ||
import { WithFeatureFlagProps } from "src/types/uiTypes"; | ||
|
||
import { cookies } from "next/headers"; | ||
import { notFound } from "next/navigation"; | ||
import React, { ComponentType } from "react"; | ||
|
||
type WithFeatureFlagProps = { | ||
searchParams: ServerSideSearchParams; | ||
}; | ||
|
||
const withFeatureFlag = <P extends object>( | ||
// since this relies on search params coming in as a prop, it can only be used reliably on a top level page component | ||
// for other components we'll need a different implementation, likely one that delivers particular props to the wrapped component | ||
// that method is not easily implemented with top level page components, as their props are laregely dictated by the Next system | ||
const withFeatureFlag = <P, R>( | ||
WrappedComponent: ComponentType<P>, | ||
featureFlagName: string, | ||
onEnabled: () => R, | ||
) => { | ||
const ComponentWithFeatureFlag: React.FC<P & WithFeatureFlagProps> = ( | ||
props, | ||
// if we're in the middle of a build, that means this is an ssg rendering pass. | ||
// in that case we can skip this whole feature flag business and move on with our lives | ||
if (environment.NEXT_BUILD === "true") { | ||
return WrappedComponent; | ||
} | ||
|
||
// top level component to grab search params from the top level page props | ||
const ComponentWithFeatureFlagAndSearchParams = ( | ||
props: P & WithFeatureFlagProps, | ||
) => { | ||
const ffManager = new FeatureFlagsManager(cookies()); | ||
const { searchParams } = props; | ||
const searchParams = props.searchParams || {}; | ||
const ComponentWithFeatureFlag = (props: P & WithFeatureFlagProps) => { | ||
const featureFlagsManager = new FeatureFlagsManager(cookies()); | ||
|
||
if (ffManager.isFeatureDisabled(featureFlagName, searchParams)) { | ||
return notFound(); | ||
} | ||
if ( | ||
featureFlagsManager.isFeatureEnabled( | ||
featureFlagName, | ||
props.searchParams, | ||
) | ||
) { | ||
onEnabled(); | ||
return; | ||
} | ||
|
||
return <WrappedComponent {...(props as P)} />; | ||
return <WrappedComponent {...props} />; | ||
}; | ||
return <ComponentWithFeatureFlag {...props} searchParams={searchParams} />; | ||
}; | ||
|
||
return ComponentWithFeatureFlag; | ||
return ComponentWithFeatureFlagAndSearchParams; | ||
}; | ||
|
||
export default withFeatureFlag; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.