Skip to content

Commit b334e3a

Browse files
authored
Merge pull request #2012 from navikt/rewrite-types-press
Stories press-landing
2 parents 13995fa + 3582093 commit b334e3a

10 files changed

+117
-12
lines changed

src/components/_common/metatags/HeadWithMetatags.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const getCanonicalUrl = (content: ContentProps) => {
4040
return content.data.canonicalUrl;
4141
}
4242

43-
const path = getPublicPathname(content);
43+
const path = getPublicPathname({ _path: content._path });
4444

4545
return `${appOrigin}${path}`;
4646
};

src/components/_common/press-landing/PressNews.module.scss

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
}
1414

1515
.newsList {
16-
list-style-type: none;
1716
margin: 1rem 0 2rem 0;
1817
padding: 0;
1918
}

src/components/_common/press-landing/PressNews.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { PressNewsItem } from './PressNewsItem';
77
import styles from './PressNews.module.scss';
88

99
type PressNewsProps = {
10-
page: PressLandingPageProps;
10+
page: Pick<PressLandingPageProps, 'language' | 'data'>;
1111
};
1212

1313
export const PressNews = (props: PressNewsProps) => {

src/components/_common/press-landing/PressNewsItem.module.scss

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
.newsItem {
44
margin-bottom: 1.5rem;
5+
list-style-type: none;
56

67
a {
78
text-decoration-thickness: 0.05em;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
3+
import { ContentType } from 'types/content-props/_content-common';
4+
import { PressNewsItem } from './PressNewsItem';
5+
6+
const meta = {
7+
component: PressNewsItem,
8+
args: {
9+
newsItem: {
10+
_path: '',
11+
language: 'no',
12+
type: ContentType.MainArticle,
13+
displayName: '1 av 5 står utenfor arbeidslivet',
14+
data: {
15+
ingress:
16+
'685 000 personer mellom 20 og 66 år sto utenfor arbeid eller utdanning ved utgangen av 2023, viser nye tall fra NAV.',
17+
},
18+
createdTime: '2023-03-01T00:00:00Z',
19+
publish: { from: '2023-03-02T00:00:00Z', first: '2023-03-03T00:00:00Z' },
20+
},
21+
},
22+
} satisfies Meta<typeof PressNewsItem>;
23+
24+
export default meta;
25+
26+
type Story = StoryObj<typeof meta>;
27+
28+
export const Default: Story = {};
29+
30+
export const News = {
31+
args: {
32+
newsItem: {
33+
...meta.args.newsItem,
34+
data: {
35+
...meta.args.newsItem.data,
36+
contentType: 'news',
37+
},
38+
},
39+
},
40+
};
41+
42+
export const English = { args: { newsItem: { ...meta.args.newsItem, language: 'en' } } };
43+
44+
export const EnglishNews = {
45+
args: {
46+
newsItem: {
47+
...News.args.newsItem,
48+
language: 'en',
49+
data: {
50+
...meta.args.newsItem.data,
51+
contentType: 'news',
52+
},
53+
},
54+
},
55+
};
56+
57+
export const Nynorsk = { args: { newsItem: { ...meta.args.newsItem, language: 'nn' } } };
58+
59+
export const NynorskNews = {
60+
args: {
61+
newsItem: {
62+
...News.args.newsItem,
63+
language: 'nn',
64+
data: {
65+
...meta.args.newsItem.data,
66+
contentType: 'news',
67+
},
68+
},
69+
},
70+
};

src/components/_common/press-landing/PressNewsItem.tsx

+12-5
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,35 @@ import newsIcon from '/public/gfx/news-paper-icon-black.svg';
1414
import style from './PressNewsItem.module.scss';
1515

1616
type Props = {
17-
newsItem: ContentProps;
17+
newsItem: Pick<
18+
ContentProps,
19+
'language' | 'type' | 'data' | '_path' | 'displayName' | 'publish' | 'createdTime'
20+
>;
1821
};
1922

23+
function hasContentType(data: any): data is { contentType: string } {
24+
return data && typeof data.contentType === 'string';
25+
}
26+
2027
export const PressNewsItem = ({ newsItem }: Props) => {
2128
const { language } = newsItem;
2229
const getTranslations = translator('pressLanding', language);
2330

24-
const getTaglineElements = (newsItem: ContentProps) => {
31+
const getTaglineElements = ({ newsItem }: Props) => {
2532
if (newsItem.type === ContentType.MainArticle) {
26-
const isNews = newsItem.data.contentType === 'news';
33+
const isNews = hasContentType(newsItem.data) && newsItem.data.contentType === 'news';
2734
const icon = isNews ? newsIcon : pressIcon;
2835
const tagName = getTranslations(isNews ? 'news' : 'press');
2936
return { icon, tagName };
3037
}
3138
return { icon: null, tagName: null };
3239
};
3340

34-
const { icon, tagName } = getTaglineElements(newsItem);
41+
const { icon, tagName } = getTaglineElements({ newsItem });
3542

3643
return (
3744
<li key={newsItem._path} className={style.newsItem}>
38-
<LenkeBase href={getPublicPathname(newsItem)}>
45+
<LenkeBase href={getPublicPathname({ _path: newsItem._path })}>
3946
<Heading level={'3'} size={'medium'}>
4047
{newsItem.displayName}
4148
</Heading>

src/components/_common/press-landing/PressShortcuts.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getPublicPathname } from 'utils/urls';
66
import styles from './PressShortcuts.module.scss';
77

88
type PressShortcutsProps = {
9-
page: PressLandingPageProps;
9+
page: Pick<PressLandingPageProps, 'language' | 'data'>;
1010
};
1111

1212
export const PressShortcuts = (props: PressShortcutsProps) => {
@@ -30,7 +30,7 @@ export const PressShortcuts = (props: PressShortcutsProps) => {
3030
return (
3131
<li key={shortcut._path}>
3232
<LinkPanel
33-
href={getPublicPathname(shortcut)}
33+
href={getPublicPathname({ _path: shortcut._path })}
3434
className={styles.shortcutItem}
3535
>
3636
{shortcut.displayName}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
3+
import { PressTopSection } from './PressTopSection';
4+
5+
const meta = {
6+
component: PressTopSection,
7+
} satisfies Meta<typeof PressTopSection>;
8+
9+
export default meta;
10+
11+
type Story = StoryObj<typeof meta>;
12+
13+
export const Default: Story = {
14+
args: {
15+
page: {
16+
displayName: 'PressTopSection',
17+
data: {
18+
title: 'Presse',
19+
pressCall: {
20+
processedHtml:
21+
'<h2>Pressevakt</h2>\n\n<p><strong>E-post</strong>: <a href="mailto:[email protected]">[email protected]</a><br />\n<strong>Telefon</strong>: <a href="tel:40003144">40 00 31 44</a> (SMS besvares ikke) <br />\n<a href="https://www.nav.no/samarbeidspartner/pressevakt#pressevakt-direktoratet">Åpningstider pressevakt m.m.</a> </p>\n\n<p><a href="https://www.nav.no/samarbeidspartner/pressevakt#pressevakt-fylke">Pressevakter i fylkene</a></p>\n',
22+
macros: [],
23+
},
24+
},
25+
},
26+
},
27+
};

src/components/_common/press-landing/PressTopSection.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ParsedHtml } from 'components/_common/parsed-html/ParsedHtml';
55
import styles from './PressTopSection.module.scss';
66

77
type PressTopSectionProps = {
8-
page: PressLandingPageProps;
8+
page: Pick<PressLandingPageProps, 'displayName' | 'data'>;
99
};
1010

1111
export const PressTopSection = (props: PressTopSectionProps) => {

src/utils/urls.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ export function getMediaUrl(
114114
);
115115
}
116116

117-
export const getPublicPathname = (content: ContentProps) => stripXpPathPrefix(content._path);
117+
export const getPublicPathname = ({ _path }: Pick<ContentProps, '_path'>) =>
118+
stripXpPathPrefix(_path);
118119

119120
export const isUUID = (id: string) =>
120121
id && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(id);

0 commit comments

Comments
 (0)