-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support feature flags in Custom Views (#3421)
* refactor: support feature flags inside custom views * chore: add changeset * fix(application-shell): fix types issue * refactor(application-shell): clean custom view flop-flip provider * chore: update changeset Co-authored-by: Nicola Molinari <nicola.molinari@commercetools.com> --------- Co-authored-by: Nicola Molinari <nicola.molinari@commercetools.com>
- Loading branch information
1 parent
d1f1103
commit 325224e
Showing
13 changed files
with
327 additions
and
237 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@commercetools-frontend/application-components': minor | ||
'@commercetools-frontend/application-shell': minor | ||
'@commercetools-frontend/constants': minor | ||
--- | ||
|
||
Custom Views can consume feature flags (internal usage only). |
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
34 changes: 34 additions & 0 deletions
34
...on-shell/src/components/custom-view-flop-flip-provider/custom-view-flop-flip-provider.tsx
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,34 @@ | ||
import { ReactNode, useMemo } from 'react'; | ||
import memoryAdapter from '@flopflip/memory-adapter'; | ||
import { ConfigureFlopFlip } from '@flopflip/react-broadcast'; | ||
import { TFlags } from '@flopflip/types'; | ||
import { TFetchLoggedInUserQuery } from '../../types/generated/mc'; | ||
|
||
type TCustomViewFlopFlipProviderProps = { | ||
user?: TFetchLoggedInUserQuery['user']; | ||
flags?: TFlags; | ||
children: ReactNode; | ||
}; | ||
|
||
function CustomViewFlopFlipProvider(props: TCustomViewFlopFlipProviderProps) { | ||
const adapterArgs = useMemo( | ||
() => ({ | ||
user: { | ||
key: props.user?.id, | ||
}, | ||
}), | ||
[props.user?.id] | ||
); | ||
|
||
return ( | ||
<ConfigureFlopFlip | ||
adapter={memoryAdapter} | ||
defaultFlags={props.flags} | ||
adapterArgs={adapterArgs} | ||
> | ||
{props.children} | ||
</ConfigureFlopFlip> | ||
); | ||
} | ||
|
||
export default CustomViewFlopFlipProvider; |
1 change: 1 addition & 0 deletions
1
packages/application-shell/src/components/custom-view-flop-flip-provider/index.ts
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 @@ | ||
export { default } from './custom-view-flop-flip-provider'; |
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
Oops, something went wrong.
325224e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for application-kit-custom-views ready!
✅ Preview
https://application-kit-custom-views-32sjst3h6-commercetools.vercel.app
Built with commit 325224e.
This pull request is being automatically deployed with vercel-action