2023-10-26 13:27:17 +02:00
|
|
|
import { setFeatureFlags } from '~/mocks/browser'
|
|
|
|
import type { Decorator } from '@storybook/react'
|
2023-06-08 23:02:46 +02:00
|
|
|
|
2023-10-27 22:47:36 +02:00
|
|
|
declare module '@storybook/types' {
|
|
|
|
interface Parameters {
|
|
|
|
featureFlags?: string[]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-08 23:02:46 +02:00
|
|
|
/** Global story decorator that allows setting feature flags.
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* export default {
|
|
|
|
* title: 'My story',
|
|
|
|
* component: MyComponent,
|
|
|
|
* parameters: {
|
|
|
|
* featureFlags: ['hogql'], // add flags here
|
|
|
|
* },
|
|
|
|
* } as ComponentMeta<typeof MyComponent>
|
|
|
|
* ```
|
|
|
|
*/
|
2023-10-26 13:27:17 +02:00
|
|
|
export const withFeatureFlags: Decorator = (Story, { parameters }) => {
|
2023-06-08 23:02:46 +02:00
|
|
|
if (parameters.featureFlags) {
|
2023-10-26 13:27:17 +02:00
|
|
|
setFeatureFlags(parameters.featureFlags)
|
2023-06-08 23:02:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return <Story />
|
|
|
|
}
|