-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: feature flags: Add feature flag config for Octuple (#875)
* feat: feature flags: Add feature flag config for Octuple Add option to lazy load panels by default * rename property * add jsdoc for the flag
- Loading branch information
1 parent
e652582
commit 9fc6b07
Showing
8 changed files
with
199 additions
and
27 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,54 @@ | ||
'use client'; | ||
|
||
import React, { createContext, FC, useContext, useMemo } from 'react'; | ||
|
||
export interface FeatureFlags { | ||
panelLazyLoadContent?: boolean; | ||
} | ||
|
||
export interface FeatureFlagContextProps { | ||
featureFlags?: FeatureFlags; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const FeatureFlagContext = createContext<FeatureFlags>(undefined); | ||
|
||
const defaultFeatureFlagValues: FeatureFlags = { | ||
/** | ||
* This feature flag configures panels to only render their content if they are currently visible. This feature deprecates the | ||
* `renderContentAlways` option and completely overrides its value when it is enabled. | ||
* it overrides the behvavior of `renderContentAlways` | ||
*/ | ||
panelLazyLoadContent: false, | ||
}; | ||
|
||
export const FeatureFlagContextProvider: FC<FeatureFlagContextProps> = ({ | ||
children, | ||
featureFlags, | ||
}) => { | ||
const ancestorFeatureFlags = useContext(FeatureFlagContext); | ||
|
||
const currentContext = useMemo( | ||
() => ({ | ||
...defaultFeatureFlagValues, | ||
...ancestorFeatureFlags, | ||
...featureFlags, | ||
}), | ||
[featureFlags, ancestorFeatureFlags] | ||
); | ||
|
||
return ( | ||
<FeatureFlagContext.Provider value={currentContext}> | ||
{children} | ||
</FeatureFlagContext.Provider> | ||
); | ||
}; | ||
|
||
/** | ||
* Hook to retreive a set of currently configured features flags | ||
* @returns The currently set feature flags. | ||
*/ | ||
export const useFeatureFlags = () => | ||
useContext(FeatureFlagContext) || { ...defaultFeatureFlagValues }; | ||
|
||
export default FeatureFlagContext; |
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