-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
load the new featureFlags into global state and allow updating via qu…
…ery params (prefix: `pinboardFeatureFlag_`)
- Loading branch information
1 parent
a4c4519
commit 6657969
Showing
4 changed files
with
77 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { readAndThenSilentlyDropQueryParamFromURL } from "./util"; | ||
import { ApolloClient } from "@apollo/client"; | ||
import { MyUser } from "shared/graphql/graphql"; | ||
import { gqlChangeFeatureFlag } from "../gql"; | ||
|
||
export const ALLOWED_FEATURE_FLAGS = ["test"] as const; | ||
export type AllowedFeatureFlags = (typeof ALLOWED_FEATURE_FLAGS)[number]; | ||
|
||
export type FeatureFlags = Partial<Record<AllowedFeatureFlags, boolean>>; | ||
|
||
export const extractFeatureFlags = ( | ||
featureFlagsStr: string | null | undefined | ||
): FeatureFlags => | ||
featureFlagsStr ? (JSON.parse(featureFlagsStr) as FeatureFlags) : {}; | ||
|
||
export const consumeFeatureFlagQueryParamsAndUpdateAccordingly = async ( | ||
apolloClient: ApolloClient<unknown>, | ||
updateMyUserFunc: (mapFn: () => { getMyUser: MyUser }) => void | ||
) => { | ||
for (const flagId in ALLOWED_FEATURE_FLAGS) { | ||
//need to process sequentially | ||
const flagStringValue = readAndThenSilentlyDropQueryParamFromURL( | ||
`pinboardFeatureFlag_${flagId}` | ||
); | ||
if (flagStringValue !== null) { | ||
const updatedUserResult = await apolloClient.mutate({ | ||
mutation: gqlChangeFeatureFlag, | ||
variables: { | ||
flagId, | ||
newValue: flagStringValue === "true", | ||
}, | ||
}); | ||
updateMyUserFunc(() => ({ | ||
getMyUser: updatedUserResult.data?.changeFeatureFlag, | ||
})); | ||
} | ||
} | ||
}; |
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