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

Allow Storybook to render the script link #11983

Draft
wants to merge 1 commit into
base: latest
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .storybook/withServicesDecorator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
) => {
const defaultServiceOverride = overrideProps?.defaultService;
const serviceToUse = defaultServiceOverride || selectedService;

console.log('HELLO', serviceToUse, '2', selectedService);

Check warning on line 57 in .storybook/withServicesDecorator/index.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement
const variant = getVariant(serviceToUse as Services)(TEXT_VARIANTS);

console.log(variant);

Check warning on line 59 in .storybook/withServicesDecorator/index.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement
const service = variant
? getService(serviceToUse as Services)(TEXT_VARIANTS)
: serviceToUse;
Expand Down
4 changes: 4 additions & 0 deletions .storybook/withServicesDecorator/text-variants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import serbian from '#app/lib/config/services/serbian';

Check failure on line 1 in .storybook/withServicesDecorator/text-variants.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'serbian' is declared but its value is never read.

Check failure on line 1 in .storybook/withServicesDecorator/text-variants.ts

View workflow job for this annotation

GitHub Actions / cypress-run (18.x)

'serbian' is declared but its value is never read.

Check warning on line 1 in .storybook/withServicesDecorator/text-variants.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'serbian' is defined but never used

Check failure on line 1 in .storybook/withServicesDecorator/text-variants.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'serbian' is declared but its value is never read.

Check failure on line 1 in .storybook/withServicesDecorator/text-variants.ts

View workflow job for this annotation

GitHub Actions / cypress-run (18.x)

'serbian' is declared but its value is never read.

Check failure on line 1 in .storybook/withServicesDecorator/text-variants.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'serbian' is declared but its value is never read.
import { Services, Variants } from '#app/models/types/global';

type TextVariant = {
Expand Down Expand Up @@ -286,6 +287,9 @@
timezone: 'GMT',
articlePath: '/russian/articles/ck7pz7re3zgo',
},
serbian: {

Check failure on line 290 in .storybook/withServicesDecorator/text-variants.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Type '{ variant: "cyr"; }' is missing the following properties from type 'TextVariant': text, longText, script, locale, and 2 more.

Check failure on line 290 in .storybook/withServicesDecorator/text-variants.ts

View workflow job for this annotation

GitHub Actions / cypress-run (18.x)

Type '{ variant: "cyr"; }' is missing the following properties from type 'TextVariant': text, longText, script, locale, and 2 more.

Check failure on line 290 in .storybook/withServicesDecorator/text-variants.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Type '{ variant: "cyr"; }' is missing the following properties from type 'TextVariant': text, longText, script, locale, and 2 more.

Check failure on line 290 in .storybook/withServicesDecorator/text-variants.ts

View workflow job for this annotation

GitHub Actions / cypress-run (18.x)

Type '{ variant: "cyr"; }' is missing the following properties from type 'TextVariant': text, longText, script, locale, and 2 more.

Check failure on line 290 in .storybook/withServicesDecorator/text-variants.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Type '{ variant: "cyr"; }' is missing the following properties from type 'TextVariant': text, longText, script, locale, and 2 more.
variant: 'cyr',
},
serbianCyr: {
service: 'serbian',
variant: 'cyr',
Expand Down
14 changes: 11 additions & 3 deletions src/app/components/Header/ScriptLink/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { RequestContext } from '../../../contexts/RequestContext';
import styles from './index.styles';

interface UseRouteMatcher {

Check failure on line 13 in src/app/components/Header/ScriptLink/index.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'UseRouteMatcher' is declared but never used.

Check failure on line 13 in src/app/components/Header/ScriptLink/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (18.x)

'UseRouteMatcher' is declared but never used.

Check warning on line 13 in src/app/components/Header/ScriptLink/index.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'UseRouteMatcher' is defined but never used

Check failure on line 13 in src/app/components/Header/ScriptLink/index.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'UseRouteMatcher' is declared but never used.

Check failure on line 13 in src/app/components/Header/ScriptLink/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (18.x)

'UseRouteMatcher' is declared but never used.

Check failure on line 13 in src/app/components/Header/ScriptLink/index.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'UseRouteMatcher' is declared but never used.
path: string;
params: Record<string, string>;
}
Expand Down Expand Up @@ -59,21 +59,29 @@
const { service, scriptLink } = useContext(ServiceContext);
const { isNextJs } = useContext(RequestContext);
const { enabled: scriptLinkEnabled } = useToggle('scriptLink');

const isStoryBook = process.env.STORYBOOK;
let path;
let params;
// TODO: Next.JS doesn't support `react-router-dom` hooks, so we need to
// revisit this to support both Express and Next.JS in the future.
if (!scriptLinkEnabled || isNextJs) return null;
// eslint-disable-next-line react-hooks/rules-of-hooks
const { path, params }: UseRouteMatcher = useRouteMatch();
if (!isStoryBook) {
// eslint-disable-next-line react-hooks/rules-of-hooks
const match = useRouteMatch();
path = match.path;
params = match.params;
}

const { text, variant } = scriptLink || {};
console.log('hello?123', isStoryBook);

Check warning on line 77 in src/app/components/Header/ScriptLink/index.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement
if (!variant) return null;

return (
<a
css={styles.link}
href={getVariantHref({
path,
params,

Check failure on line 84 in src/app/components/Header/ScriptLink/index.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Type '{} | undefined' is not assignable to type 'Record<string, string>'.

Check failure on line 84 in src/app/components/Header/ScriptLink/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (18.x)

Type '{} | undefined' is not assignable to type 'Record<string, string>'.

Check failure on line 84 in src/app/components/Header/ScriptLink/index.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Type '{} | undefined' is not assignable to type 'Record<string, string>'.

Check failure on line 84 in src/app/components/Header/ScriptLink/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (18.x)

Type '{} | undefined' is not assignable to type 'Record<string, string>'.

Check failure on line 84 in src/app/components/Header/ScriptLink/index.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Type '{} | undefined' is not assignable to type 'Record<string, string>'.
service,
variant,
scriptSwitchId,
Expand Down
2 changes: 1 addition & 1 deletion src/app/hooks/useToggle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const useToggle = toggleName => {
const featureToggle = useContext(ToggleContext).toggleState[toggleName];
const { enabled = null, value } = featureToggle || {};

console.log('maybe??', featureToggle, enabled);

Check warning on line 7 in src/app/hooks/useToggle/index.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement
if (featureToggle) {
return {
...{ enabled, value },
Expand Down
1 change: 0 additions & 1 deletion src/app/legacy/containers/Brand/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const BrandContainer = ({
const svgRatio = brandSVG && brandSVG.ratio;
const minWidth = svgRatio * svgMinHeight;
const maxWidth = svgRatio * svgMaxHeight;

return (
<StyledBrand
product={product}
Expand Down
6 changes: 3 additions & 3 deletions src/app/legacy/containers/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

const Header = ({ brandRef, borderBottom, skipLink, scriptLink, linkId }) => {
const [showConsentBanner, setShowConsentBanner] = useState(true);

console.log('HELLO23', scriptLink);

Check warning on line 14 in src/app/legacy/containers/Header/index.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement
const handleBannerBlur = event => {
const isRejectButton =
event.target?.getAttribute('data-terms-banner') === 'reject' ||
Expand Down Expand Up @@ -49,7 +49,7 @@
const { service, script, translations, dir, scriptLink, lang, serviceLang } =
useContext(ServiceContext);
const { skipLinkText } = translations;

console.log(renderScriptSwitch);

Check warning on line 52 in src/app/legacy/containers/Header/index.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement
const isOperaMini = useOperaMiniDetection();

const brandRef = useRef(null);
Expand Down Expand Up @@ -78,7 +78,7 @@
shouldRenderScriptSwitch = true;
}
}

console.log('render?', shouldRenderScriptSwitch);

Check warning on line 81 in src/app/legacy/containers/Header/index.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement
if (isApp) return null;

return (
Expand Down
24 changes: 23 additions & 1 deletion src/app/legacy/containers/Header/index.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
import React from 'react';
import HeaderContainer from '.';
import { ServiceContext } from '#app/contexts/ServiceContext';
import { ToggleContextProvider } from '#contexts/ToggleContext';

const Component = () => <HeaderContainer />;
const Component = () => {
return (
<ToggleContextProvider
toggles={{
scriptLink: { enabled: true },
}}
>
<ServiceContext.Provider
value={{
scriptLink: {
text: 'Ћир',
variant: 'cyr',
},
translations: { skipLinkText: 'text' },
}}
>
<HeaderContainer />
</ServiceContext.Provider>
</ToggleContextProvider>
);
};

export default {
title: 'Containers/Header',
Expand Down
4 changes: 2 additions & 2 deletions src/app/legacy/psammead/psammead-brand/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
linkId = null,
...rest
} = props;

console.log('final?', scriptLink);

Check warning on line 178 in src/app/legacy/psammead/psammead-brand/src/index.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement
return (
<Banner
svgHeight={svgHeight}
Expand All @@ -200,7 +200,7 @@
<StyledBrand {...props} />
)}
{skipLink}
{scriptLink && <div>{scriptLink}</div>}
{scriptLink && <div> {scriptLink}</div>}
</SvgWrapper>
</Banner>
);
Expand Down
Loading