Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render the script switch button on the header container on storybook #11984

Open
wants to merge 38 commits into
base: latest
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
01c8632
Allow correct service to be selected from the Text Variants list
karinathomasbbc Sep 17, 2024
92ffb76
Deleting scriptlink story as it is not required
karinathomasbbc Sep 17, 2024
4de9f6e
Add toggle + browser router to the header container story
karinathomasbbc Sep 17, 2024
6ed29a1
Prettier
karinathomasbbc Sep 17, 2024
9a0a9e4
Merge branch 'latest' into storybook-script-link
karinathomasbbc Sep 17, 2024
5d74e3f
Simplify service/variant lookup
karinathomasbbc Sep 18, 2024
73ac58a
Merge branch 'storybook-script-link' of github.com:bbc/simorgh into s…
karinathomasbbc Sep 18, 2024
00df736
FIX: linting
eagerterrier Sep 18, 2024
41f2e77
Merge branch 'latest' into storybook-script-link
eagerterrier Sep 18, 2024
f1ff4f4
Merge branch 'latest' into storybook-script-link
eagerterrier Sep 20, 2024
7b13e2f
Merge branch 'latest' into storybook-script-link
karinathomasbbc Sep 23, 2024
db37b7a
Merge branch 'latest' into storybook-script-link
karinathomasbbc Sep 23, 2024
6e2610f
Merge branch 'latest' into storybook-script-link
karinathomasbbc Sep 23, 2024
025ca74
Reinstate service to use
karinathomasbbc Sep 23, 2024
ef82cc9
Merge branch 'latest' into storybook-script-link
karinathomasbbc Sep 25, 2024
fb892ac
Merge branch 'latest' into storybook-script-link
karinathomasbbc Sep 27, 2024
6882837
WIP
karinathomasbbc Sep 27, 2024
34cef5e
Merge branch 'latest' of github.com:bbc/simorgh into storybook-script…
karinathomasbbc Sep 30, 2024
f8e90d1
Merge branch 'latest' of github.com:bbc/simorgh into storybook-script…
karinathomasbbc Sep 30, 2024
5d5cc1e
Remove default service & fix stories which used this functionality
karinathomasbbc Sep 30, 2024
37b28be
Use destructuring
karinathomasbbc Oct 1, 2024
e0349a7
Prettier
karinathomasbbc Oct 1, 2024
b27c652
Remove docs on overriding the default service
karinathomasbbc Oct 1, 2024
af18b5b
Fix Recent Episode stories
karinathomasbbc Oct 1, 2024
2362a2a
Keep type with text variants logic
karinathomasbbc Oct 1, 2024
4c539c5
Error handling for services without text variants
karinathomasbbc Oct 1, 2024
8affaed
Cleanup stories with defaulted services
karinathomasbbc Oct 1, 2024
77aa5b3
Prettier
karinathomasbbc Oct 1, 2024
13016b9
Merge branch 'latest' into storybook-script-link
karinathomasbbc Oct 1, 2024
7d93c24
Linting
karinathomasbbc Oct 2, 2024
c3ed76d
Merge branch 'storybook-script-link' of github.com:bbc/simorgh into s…
karinathomasbbc Oct 2, 2024
2c605db
Merge branch 'latest' into storybook-script-link
karinathomasbbc Oct 2, 2024
361479c
Merge branch 'latest' of github.com:bbc/simorgh into storybook-script…
karinathomasbbc Oct 2, 2024
2141705
Fix snapshots
karinathomasbbc Oct 2, 2024
9cc3c15
Merge branch 'storybook-script-link' of github.com:bbc/simorgh into s…
karinathomasbbc Oct 2, 2024
328ea62
Merge branch 'latest' into storybook-script-link
karinathomasbbc Oct 2, 2024
ab128b4
Remove additional tests (which are used for chromatic testing purpose…
karinathomasbbc Oct 2, 2024
611e425
Merge branch 'storybook-script-link' of github.com:bbc/simorgh into s…
karinathomasbbc Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,12 @@ const preview: Preview = {
},
},
},
initialGlobals: {
service: {
service: 'news',
variant: 'default',
},
},
parameters: {
passArgsFirst: false,
options: {
Expand Down
45 changes: 23 additions & 22 deletions .storybook/withServicesDecorator/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import path from 'ramda/src/path';
import { Helmet } from 'react-helmet';
import { StoryProps } from '#app/models/types/storybook';
import { Services, Variants } from '#app/models/types/global';
import TEXT_VARIANTS from './text-variants';
import arabic from '../../src/app/components/ThemeProvider/fontScripts/arabic';
import bengali from '../../src/app/components/ThemeProvider/fontScripts/bengali';
Expand All @@ -13,13 +14,8 @@ import noAscendersOrDescenders from '../../src/app/components/ThemeProvider/font
import sinhalese from '../../src/app/components/ThemeProvider/fontScripts/sinhalese';
import tamil from '../../src/app/components/ThemeProvider/fontScripts/tamil';
import thai from '../../src/app/components/ThemeProvider/fontScripts/thai';
import { Services } from '../../src/app/models/types/global';

const DEFAULT_SERVICE = 'news';
const getVariant = (selectedService: Services) =>
path([selectedService, 'variant']);
const getService = (selectedService: Services) =>
path([selectedService, 'service']);
const DEFAULT_VARIANT = 'default';

const scripts = {
arabic,
Expand All @@ -41,25 +37,31 @@ const scripts = {
thai,
};

export default (overrideProps?: { defaultService?: Services }) =>
export default () =>
(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
story: (storyProps: any) => JSX.Element,
story: (storyProps: StoryProps) => JSX.Element,
{
globals: {
service: { service: selectedService },
service: { service: globalService, variant: globalVariant },
isLite,
},
} = { globals: { service: { service: DEFAULT_SERVICE }, isLite: false } },
}: {
globals: {
service: {
service: Services;
variant: Variants;
};
isLite: boolean;
};
},
) => {
const defaultServiceOverride = overrideProps?.defaultService;
const serviceToUse = defaultServiceOverride || selectedService;
let serviceLookup: string = globalService;

const variant = getVariant(serviceToUse as Services)(TEXT_VARIANTS);
if (globalVariant !== DEFAULT_VARIANT) {
serviceLookup = `${globalService}-${globalVariant}`;
}

const service = variant
? getService(serviceToUse as Services)(TEXT_VARIANTS)
: serviceToUse;
const textOverrides = TEXT_VARIANTS[serviceLookup];

const {
text,
Expand All @@ -69,7 +71,7 @@ export default (overrideProps?: { defaultService?: Services }) =>
locale,
dir = 'ltr',
timezone = 'GMT',
} = TEXT_VARIANTS[serviceToUse];
} = textOverrides || {};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const storyProps: any = {
Expand All @@ -79,9 +81,8 @@ export default (overrideProps?: { defaultService?: Services }) =>
script: scripts[script as keyof typeof scripts],
locale,
dir,
service,
variant: variant || 'default',
selectedService: serviceToUse,
service: textOverrides?.service || globalService,
variant: textOverrides?.variant || globalVariant,
timezone,
isLite,
};
Expand Down
12 changes: 6 additions & 6 deletions .storybook/withServicesDecorator/text-variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ const TEXT_VARIANTS: Record<string, TextVariant> = {
timezone: 'GMT',
articlePath: '/russian/articles/ck7pz7re3zgo',
},
serbianCyr: {
'serbian-cyr': {
service: 'serbian',
variant: 'cyr',
text: 'Караџић се годинама крио пре него што је ухапшен 2008. године',
Expand All @@ -297,7 +297,7 @@ const TEXT_VARIANTS: Record<string, TextVariant> = {
timezone: 'GMT',
articlePath: '/serbian/articles/c805k05kr73o/cyr',
},
serbianLat: {
'serbian-lat': {
service: 'serbian',
variant: 'lat',
text: 'Karadžić se godinama krio pre nego što je uhapšen 2008. godine',
Expand Down Expand Up @@ -389,7 +389,7 @@ const TEXT_VARIANTS: Record<string, TextVariant> = {
timezone: 'Asia/Istanbul',
articlePath: '/turkce/articles/c8q1ze59n25o',
},
ukchinaSimp: {
'ukchina-simp': {
service: 'ukchina',
variant: 'simp',
text: '该计划的批评者说,这个政策不能解决住房短缺的问题',
Expand All @@ -400,7 +400,7 @@ const TEXT_VARIANTS: Record<string, TextVariant> = {
timezone: 'GMT',
articlePath: '/ukchina/articles/c0e8weny66ko/simp',
},
ukchinaTrad: {
'ukchina-trad': {
service: 'ukchina',
variant: 'trad',
text: '該計劃的批評者說,這個政策不能解決住房短缺的問題',
Expand Down Expand Up @@ -457,7 +457,7 @@ const TEXT_VARIANTS: Record<string, TextVariant> = {
timezone: 'Africa/Lagos',
articlePath: '/yoruba/articles/clw06m0nj8qo',
},
zhongwenSimp: {
'zhongwen-simp': {
service: 'zhongwen',
variant: 'simp',
text: '郑文杰:中国警方公布“嫖娼证据” 引发中港网友论战',
Expand All @@ -468,7 +468,7 @@ const TEXT_VARIANTS: Record<string, TextVariant> = {
timezone: 'GMT',
articlePath: '/zhongwen/articles/c3xd4x9prgyo/simp',
},
zhongwenTrad: {
'zhongwen-trad': {
service: 'zhongwen',
variant: 'trad',
text: '鄭文傑:中國警方公布「嫖娼證據」 引發中港網友論戰',
Expand Down
13 changes: 0 additions & 13 deletions docs/Writing-Storybook-Stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,3 @@ const Component = () => (

This will ensure that the service being rendered is `mundo`, in this example. This is useful for creating stories to demonstrate layout for left-to-right and right-to-left languages.

## Overriding the default service

You can automatically set the `service` for a story by using the `withServicesDecorator` function. To do this, import the function and add it to the `decorators` array in the default export for the story. For example:

```tsx
import { withServicesDecorator } from '#storybook/withServicesDecorator';

export default {
title: 'MyFirstStory',
component: Component,
decorators: [withServicesDecorator({ defaultService: 'mundo' })],
};
```
24 changes: 0 additions & 24 deletions src/app/components/Header/ScriptLink/index.stories.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import { RequestContextProvider } from '#contexts/RequestContext';
import { ToggleContextProvider } from '#contexts/ToggleContext';
import { ServiceContextProvider } from '#contexts/ServiceContext';
import withServicesDecorator from '#storybook/withServicesDecorator';
import { indonesian, arabic } from './fixtures';
import RecentAudioEpisodes from './index';

Expand Down Expand Up @@ -41,26 +40,42 @@ const masterBrands = {
export default {
title: 'Containers/Episode List/Audio',
Component,
decorators: [withServicesDecorator({ defaultService: 'indonesia' })],
};

export const MultipleItems = (_, { service }) => (
<Component
episodes={fixtures?.[service] ?? fixtures.indonesia}
pageType="Podcast"
masterBrand={masterBrands?.[service] ?? masterBrands.indonesia}
service={service}
/>
);
export const MultipleItems = {
render: (_, { service }) => (
<Component
episodes={fixtures?.[service] ?? fixtures.indonesia}
pageType="Podcast"
masterBrand={masterBrands?.[service] ?? masterBrands.indonesia}
service={service}
/>
),
parameters: {
chromatic: { disableSnapshot: true },
},
};

export const SingleItem = (_, { service }) => {
const fixture = fixtures?.[service]?.[0] ?? fixtures.indonesia[0];
return (
export const SingleItem = {
render: (_, { service }) => (
<Component
episodes={[fixture]}
episodes={[fixtures?.[service]?.[0] ?? fixtures.indonesia[0]]}
pageType="Podcast"
masterBrand={masterBrands?.[service] ?? masterBrands.indonesia}
service={service}
/>
);
),
parameters: {
chromatic: { disableSnapshot: true },
},
};

// This story is for chromatic testing purposes only
export const TestMultipleItems = storyArgs =>
MultipleItems.render(storyArgs, { service: 'indonesia' });
TestMultipleItems.tags = ['!dev'];

// This story is for chromatic testing purposes only
export const TestSingleItem = storyArgs =>
SingleItem.render(storyArgs, { service: 'indonesia' });
TestSingleItem.tags = ['!dev'];
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { RequestContextProvider } from '#contexts/RequestContext';
import { ServiceContextProvider } from '#contexts/ServiceContext';
import withServicesDecorator from '#storybook/withServicesDecorator';
import { afrique, pashto } from './fixtures';
import RecentVideoEpisodes from '.';

Expand All @@ -24,7 +23,6 @@ const fixtures = { afrique, pashto };
export default {
title: 'Containers/Episode List/Video',
Component,
decorators: [withServicesDecorator({ defaultService: 'afrique' })],
parameters: {
backgrounds: {
default: 'Dark',
Expand All @@ -33,21 +31,42 @@ export default {
},
};

export const MultipleItems = (_, { service }) => (
<Component
episodes={fixtures?.[service] ?? fixtures.afrique}
masterBrand={`bbc_${service}_tv`}
service={service}
/>
);
export const MultipleItems = {
render: (_, { service }) => (
<Component
episodes={fixtures?.[service] ?? fixtures.afrique}
masterBrand={`bbc_${service}_tv`}
service={service}
/>
),
parameters: {
chromatic: {
disableSnapshot: true,
},
},
};

export const SingleItem = (_, { service }) => {
const fixture = fixtures?.[service]?.[0] ?? fixtures.afrique[0];
return (
export const SingleItem = {
render: (_, { service }) => (
<Component
episodes={[fixture]}
episodes={[fixtures?.[service]?.[0] ?? fixtures.afrique[0]]}
masterBrand={`bbc_${service}_tv`}
service={service}
/>
);
),
parameters: {
chromatic: {
disableSnapshot: true,
},
},
};

// This story is for chromatic testing purposes only
export const TestMultipleItems = storyArgs =>
MultipleItems.render(storyArgs, { service: 'afrique' });
TestMultipleItems.tags = ['!dev'];

// This story is for chromatic testing purposes only
export const TestSingleItem = storyArgs =>
SingleItem.render(storyArgs, { service: 'afrique' });
TestSingleItem.tags = ['!dev'];
16 changes: 15 additions & 1 deletion src/app/legacy/containers/Header/index.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import React from 'react';
import HeaderContainer from '.';
import { ToggleContextProvider } from '../../../contexts/ToggleContext';
import { BrowserRouter } from 'react-router-dom';

const Component = () => <HeaderContainer />;
const Component = () => (
<ToggleContextProvider
toggles={{
scriptLink: {
enabled: true,
},
}}
>
<BrowserRouter>
<HeaderContainer />
</BrowserRouter>
</ToggleContextProvider>
);

export default {
title: 'Containers/Header',
Expand Down
19 changes: 14 additions & 5 deletions src/app/pages/HomePage/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { HOME_PAGE } from '#app/routes/utils/pageTypes';
import fetch from 'node-fetch';
import { Curation } from '#app/models/types/curationData';
import { Services } from '#app/models/types/global';
import withServicesDecorator from '#storybook/withServicesDecorator';
import { StoryArgs, StoryProps } from '../../models/types/storybook';
import HomePage from '.';

Expand Down Expand Up @@ -76,9 +75,19 @@ const Component = ({ service, variant }: StoryProps) => {
export default {
Component,
title: 'Pages/Home Page',
decorators: [withServicesDecorator({ defaultService: 'kyrgyz' })],
};

export const Example = (_: StoryArgs, { service, variant }: StoryProps) => (
<Component service={service} variant={variant} />
);
export const Example = {
render: (_: StoryArgs, { service, variant }: StoryProps) => (
<Component service={service} variant={variant} />
),
parameters: { chromatic: { disableSnapshot: true } },
};

// This story is for chromatic testing purposes only
export const Test = {
render: (_: StoryArgs, { variant }: StoryProps) => (
<Component service="kyrgyz" variant={variant} />
),
tags: ['!dev'],
};
Loading
Loading