Skip to content

Commit 852a4e0

Browse files
committed
[v11.x.x] Fix Storybook AppProviderDecorator (#9233)
### WHY are these changes introduced? Fix `feature` -> `features` [typo](#9227) in the storybook AppProviderDecorator so the toggle works on all stories. Also removed the button toggle from the AppProvider summer editions story to avoid confusion between two toggle mechanisms ### How to 🎩 Toggle feature in control panel https://5d559397bae39100201eedc1-zlfuvdfzep.chromatic.com/?path=/story/all-components-appprovider--with-summer-editions-feature
1 parent 3912e4f commit 852a4e0

File tree

5 files changed

+61
-44
lines changed

5 files changed

+61
-44
lines changed

polaris-react/.storybook/preview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ function AppProviderDecorator(Story, context) {
2323
if (context.args.omitAppProvider) return <Story {...context} />;
2424
return (
2525
<AppProvider
26-
feature={{
27-
polarisSummerEditions2023,
26+
features={{
27+
polarisSummerEditions2023,
2828
}}
2929
i18n={enTranslations}
3030
>

polaris-react/src/components/AppProvider/AppProvider.stories.tsx

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {useState} from 'react';
2-
import type {ComponentMeta} from '@storybook/react';
2+
import type {Args, ComponentMeta} from '@storybook/react';
33
import {
44
AppProvider,
55
Avatar,
@@ -166,40 +166,30 @@ export function WithLinkComponent() {
166166
);
167167
}
168168

169-
export function WithSummerEditionsFeature() {
170-
const [flagStatus, setFlagStatus] = useState(false);
171-
const CheckFeature = ({children}: {children: React.ReactNode}) => {
172-
const {polarisSummerEditions2023} = useFeatures();
169+
export const WithSummerEditionsFeature = {
170+
render: (_args: Args, {globals: {polarisSummerEditions2023}}) => {
171+
const CheckFeature = () => {
172+
const {polarisSummerEditions2023} = useFeatures();
173+
return (
174+
<AlphaCard>
175+
<VerticalStack gap="4">
176+
<Text
177+
as="h2"
178+
variant={polarisSummerEditions2023 ? 'headingXl' : 'bodyMd'}
179+
color={polarisSummerEditions2023 ? 'critical' : undefined}
180+
>
181+
{`Polaris Summer Editions flag is turned ${
182+
polarisSummerEditions2023 ? 'ON' : 'OFF'
183+
}`}
184+
</Text>
185+
</VerticalStack>
186+
</AlphaCard>
187+
);
188+
};
173189
return (
174-
<AlphaCard>
175-
<VerticalStack gap="4">
176-
<Text
177-
as="h2"
178-
variant={polarisSummerEditions2023 ? 'headingXl' : 'bodyMd'}
179-
color={polarisSummerEditions2023 ? 'critical' : undefined}
180-
>
181-
{`Polaris Summer Editions flag is turned ${
182-
polarisSummerEditions2023 ? 'ON' : 'OFF'
183-
}`}
184-
</Text>
185-
186-
{children}
187-
</VerticalStack>
188-
</AlphaCard>
190+
<AppProvider features={{polarisSummerEditions2023}} i18n={{}}>
191+
<CheckFeature />
192+
</AppProvider>
189193
);
190-
};
191-
return (
192-
<AppProvider features={{polarisSummerEditions2023: flagStatus}} i18n={{}}>
193-
<CheckFeature>
194-
<Box>
195-
<Button
196-
primary
197-
onClick={() => setFlagStatus((flagStatus) => !flagStatus)}
198-
>
199-
Toggle flag
200-
</Button>
201-
</Box>
202-
</CheckFeature>
203-
</AppProvider>
204-
);
205-
}
194+
},
195+
};

polaris-react/src/components/Frame/Frame.stories.tsx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {useCallback, useRef, useState} from 'react';
2-
import type {ComponentMeta} from '@storybook/react';
2+
import type {Args, ComponentMeta} from '@storybook/react';
33
import {
44
ActionList,
55
AppProvider,
@@ -34,7 +34,19 @@ export default {
3434
parameters: {layout: 'fullscreen'},
3535
} as ComponentMeta<typeof Frame>;
3636

37-
export function InAnApplication() {
37+
export const InAnApplication = {
38+
render: (_args: Args, {globals: {polarisSummerEditions2023}}) => (
39+
<InAnApplicationComponent
40+
polarisSummerEditions2023={polarisSummerEditions2023}
41+
/>
42+
),
43+
};
44+
45+
function InAnApplicationComponent({
46+
polarisSummerEditions2023,
47+
}: {
48+
polarisSummerEditions2023: boolean;
49+
}) {
3850
const defaultState = useRef({
3951
emailFieldValue: 'dharma@jadedpixel.com',
4052
nameFieldValue: 'Jaded Pixel',
@@ -353,6 +365,7 @@ export function InAnApplication() {
353365
},
354366
},
355367
}}
368+
features={{polarisSummerEditions2023}}
356369
>
357370
<Frame
358371
logo={logo}
@@ -373,7 +386,19 @@ export function InAnApplication() {
373386
);
374387
}
375388

376-
export function WithAnOffset() {
389+
export const WithAnOffset = {
390+
render: (_args: Args, {globals: {polarisSummerEditions2023}}) => (
391+
<WithAnOffsetComponent
392+
polarisSummerEditions2023={polarisSummerEditions2023}
393+
/>
394+
),
395+
};
396+
397+
function WithAnOffsetComponent({
398+
polarisSummerEditions2023,
399+
}: {
400+
polarisSummerEditions2023: boolean;
401+
}) {
377402
const defaultState = useRef({
378403
emailFieldValue: 'dharma@jadedpixel.com',
379404
nameFieldValue: 'Jaded Pixel',
@@ -692,6 +717,7 @@ export function WithAnOffset() {
692717
},
693718
},
694719
}}
720+
features={{polarisSummerEditions2023}}
695721
>
696722
<Frame
697723
logo={logo}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {createContext} from 'react';
22

3-
import type {Features} from './types';
3+
import type {FeaturesConfig} from './types';
44

5-
export const FeaturesContext = createContext<Features | undefined>(undefined);
5+
export const FeaturesContext = createContext<FeaturesConfig | undefined>(
6+
undefined,
7+
);

polaris-react/src/utilities/features/tests/hooks.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {useFeatures} from '../hooks';
55

66
function Component() {
77
const features = useFeatures();
8-
// @ts-expect-error There are currently no valid features, so use a fake one for testing
98
return features.foo ? <div /> : null;
109
}
1110

0 commit comments

Comments
 (0)