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 13 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
31 changes: 16 additions & 15 deletions .storybook/withServicesDecorator/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import path from 'ramda/src/path';
import { Helmet } from 'react-helmet';
import TEXT_VARIANTS from './text-variants';
import arabic from '../../src/app/components/ThemeProvider/fontScripts/arabic';
Expand All @@ -16,10 +15,7 @@ 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 Down Expand Up @@ -47,19 +43,24 @@ export default (overrideProps?: { defaultService?: Services }) =>
story: (storyProps: any) => JSX.Element,
{
globals: {
service: { service: selectedService },
service: { service, variant },
isLite,
},
} = { globals: { service: { service: DEFAULT_SERVICE }, isLite: false } },
} = {
globals: {
service: { service: DEFAULT_SERVICE, variant: DEFAULT_VARIANT },
isLite: false,
},
},
) => {
const defaultServiceOverride = overrideProps?.defaultService;
const serviceToUse = defaultServiceOverride || selectedService;
const serviceToUse = defaultServiceOverride || service;

const variant = getVariant(serviceToUse as Services)(TEXT_VARIANTS);
let serviceLookup = serviceToUse;

const service = variant
? getService(serviceToUse as Services)(TEXT_VARIANTS)
: serviceToUse;
if (variant !== DEFAULT_VARIANT) {
serviceLookup = `${service}-${variant}`;
}

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

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const storyProps: any = {
Expand All @@ -80,8 +81,8 @@ export default (overrideProps?: { defaultService?: Services }) =>
locale,
dir,
service,
variant: variant || 'default',
selectedService: serviceToUse,
variant: variant || DEFAULT_VARIANT,
selectedService: service,
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
24 changes: 0 additions & 24 deletions src/app/components/Header/ScriptLink/index.stories.tsx

This file was deleted.

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
Loading