@times-components/ts-components 1.46.0 → 1.46.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/dist/components/recommended-articles/RecommendedArticles.d.ts +0 -1
- package/dist/components/recommended-articles/RecommendedArticles.js +10 -5
- package/dist/components/recommended-articles/RecommendedArticles.stories.js +4 -4
- package/dist/components/recommended-articles/RecommendedFetch.d.ts +5 -1
- package/dist/components/recommended-articles/RecommendedFetch.js +12 -4
- package/dist/components/recommended-articles/__tests__/RecommendedArticles.test.js +4 -4
- package/dist/components/recommended-articles/__tests__/RecommendedFetch.test.js +6 -1
- package/dist/components/recommended-articles/formatters.d.ts +1 -1
- package/dist/components/recommended-articles/formatters.js +16 -18
- package/package.json +3 -3
- package/rnw.js +1 -1
- package/src/components/recommended-articles/RecommendedArticles.stories.tsx +3 -3
- package/src/components/recommended-articles/RecommendedArticles.tsx +11 -8
- package/src/components/recommended-articles/RecommendedFetch.tsx +16 -4
- package/src/components/recommended-articles/__tests__/RecommendedArticles.test.tsx +3 -3
- package/src/components/recommended-articles/__tests__/RecommendedFetch.test.tsx +7 -0
- package/src/components/recommended-articles/__tests__/__snapshots__/RecommendedArticles.test.tsx.snap +2 -2
- package/src/components/recommended-articles/formatters.ts +15 -17
|
@@ -33,16 +33,16 @@ storiesOf('Typescript Component/Recommended Articles', module)
|
|
|
33
33
|
))
|
|
34
34
|
.add('Recommended Articles - 1 Article', () => (
|
|
35
35
|
<FetchProvider previewData={getArticles(previewData, 1)}>
|
|
36
|
-
<RecommendedArticles heading="Today's news"
|
|
36
|
+
<RecommendedArticles heading="Today's news" />
|
|
37
37
|
</FetchProvider>
|
|
38
38
|
))
|
|
39
39
|
.add('Recommended Articles - 2 Article', () => (
|
|
40
40
|
<FetchProvider previewData={getArticles(previewData, 2)}>
|
|
41
|
-
<RecommendedArticles heading="Today's business"
|
|
41
|
+
<RecommendedArticles heading="Today's business" />
|
|
42
42
|
</FetchProvider>
|
|
43
43
|
))
|
|
44
44
|
.add('Recommended Articles - 3 Article', () => (
|
|
45
45
|
<FetchProvider previewData={previewData}>
|
|
46
|
-
<RecommendedArticles heading="Today's sport"
|
|
46
|
+
<RecommendedArticles heading="Today's sport" />
|
|
47
47
|
</FetchProvider>
|
|
48
48
|
));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import get from 'lodash.get';
|
|
2
3
|
|
|
3
4
|
import RelatedArticles from '@times-components/related-articles';
|
|
4
5
|
|
|
@@ -8,17 +9,22 @@ import { getRelatedArticlesSlice } from './formatters';
|
|
|
8
9
|
|
|
9
10
|
export const RecommendedArticles: React.FC<{
|
|
10
11
|
heading: string;
|
|
11
|
-
|
|
12
|
-
}> = ({ heading, isVisible }) => {
|
|
12
|
+
}> = ({ heading }) => {
|
|
13
13
|
const { loading, error, data } = useFetch<any>();
|
|
14
14
|
|
|
15
|
-
if (loading || error
|
|
15
|
+
if (loading || error) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const articles = get(data, 'recommendations.articles');
|
|
20
|
+
|
|
21
|
+
if (!articles || !articles.length) {
|
|
16
22
|
return null;
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
const { fireAnalyticsEvent } = useTrackingContext();
|
|
20
26
|
|
|
21
|
-
const slice = getRelatedArticlesSlice(
|
|
27
|
+
const slice = getRelatedArticlesSlice(articles);
|
|
22
28
|
|
|
23
29
|
const onClickHandler = (__: MouseEvent, article: { url: string }) => {
|
|
24
30
|
const found = slice.items.find(
|
|
@@ -34,10 +40,7 @@ export const RecommendedArticles: React.FC<{
|
|
|
34
40
|
};
|
|
35
41
|
|
|
36
42
|
return (
|
|
37
|
-
<div
|
|
38
|
-
id="recommended-articles"
|
|
39
|
-
style={{ display: isVisible ? 'block' : 'none' }}
|
|
40
|
-
>
|
|
43
|
+
<div id="recommended-articles" style={{ display: 'none' }}>
|
|
41
44
|
<RelatedArticles
|
|
42
45
|
heading={heading}
|
|
43
46
|
slice={slice}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
nuk: any;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
1
7
|
import React, { useEffect, useState } from 'react';
|
|
2
8
|
|
|
3
9
|
import { FetchProvider } from '../../helpers/fetch/FetchProvider';
|
|
@@ -8,12 +14,18 @@ export const RecommendedFetch: React.FC<{
|
|
|
8
14
|
articleId: string;
|
|
9
15
|
articleHeadline: string;
|
|
10
16
|
articleSection: string;
|
|
11
|
-
|
|
12
|
-
}> = ({ articleId, articleHeadline, articleSection, isVisible }) => {
|
|
17
|
+
}> = ({ articleId, articleHeadline, articleSection }) => {
|
|
13
18
|
const [isClientSide, setIsClientSide] = useState<boolean>(false);
|
|
14
19
|
|
|
15
20
|
useEffect(() => {
|
|
16
|
-
|
|
21
|
+
try {
|
|
22
|
+
if (window.nuk.getCookieValue('acs_tnl')) {
|
|
23
|
+
setIsClientSide(true);
|
|
24
|
+
}
|
|
25
|
+
} catch (e) {
|
|
26
|
+
// tslint:disable-next-line:no-console
|
|
27
|
+
console.log(e);
|
|
28
|
+
}
|
|
17
29
|
}, []);
|
|
18
30
|
|
|
19
31
|
const heading = `Today's ${articleSection}`;
|
|
@@ -37,7 +49,7 @@ export const RecommendedFetch: React.FC<{
|
|
|
37
49
|
}
|
|
38
50
|
}}
|
|
39
51
|
>
|
|
40
|
-
<RecommendedArticles heading={heading}
|
|
52
|
+
<RecommendedArticles heading={heading} />
|
|
41
53
|
</TrackingContextProvider>
|
|
42
54
|
</FetchProvider>
|
|
43
55
|
) : null;
|
|
@@ -82,7 +82,7 @@ describe('<RecommendedArticles>', () => {
|
|
|
82
82
|
});
|
|
83
83
|
|
|
84
84
|
const { asFragment, getByText } = render(
|
|
85
|
-
<RecommendedArticles heading={heading}
|
|
85
|
+
<RecommendedArticles heading={heading} />
|
|
86
86
|
);
|
|
87
87
|
|
|
88
88
|
expect(getByText(heading));
|
|
@@ -109,7 +109,7 @@ describe('<RecommendedArticles>', () => {
|
|
|
109
109
|
(useFetch as jest.Mock).mockReturnValue({ data: previewData });
|
|
110
110
|
|
|
111
111
|
const { asFragment, getByText } = render(
|
|
112
|
-
<RecommendedArticles heading={heading}
|
|
112
|
+
<RecommendedArticles heading={heading} />
|
|
113
113
|
);
|
|
114
114
|
|
|
115
115
|
expect(getByText(heading));
|
|
@@ -129,7 +129,7 @@ describe('<RecommendedArticles>', () => {
|
|
|
129
129
|
context={initialContext}
|
|
130
130
|
analyticsStream={analyticsStream}
|
|
131
131
|
>
|
|
132
|
-
<RecommendedArticles heading={heading}
|
|
132
|
+
<RecommendedArticles heading={heading} />
|
|
133
133
|
</TrackingContextProvider>
|
|
134
134
|
);
|
|
135
135
|
|
|
@@ -18,6 +18,13 @@ jest.mock('../../../helpers/fetch/FetchProvider', () => ({
|
|
|
18
18
|
|
|
19
19
|
describe('<RecommendedFetch>', () => {
|
|
20
20
|
it('should render correctly', () => {
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
delete window.location;
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
window.location = { search: '?recommendedArticles=1' };
|
|
25
|
+
|
|
26
|
+
window.nuk = { getCookieValue: () => true };
|
|
27
|
+
|
|
21
28
|
const { asFragment, getByText } = render(
|
|
22
29
|
<RecommendedFetch
|
|
23
30
|
articleId="1234"
|
|
@@ -4,7 +4,7 @@ exports[`<RecommendedArticles> should render RelatedArticles correctly with 1 ar
|
|
|
4
4
|
<DocumentFragment>
|
|
5
5
|
<div
|
|
6
6
|
id="recommended-articles"
|
|
7
|
-
style="display:
|
|
7
|
+
style="display: none;"
|
|
8
8
|
>
|
|
9
9
|
<div>
|
|
10
10
|
RelatedArticles
|
|
@@ -45,7 +45,7 @@ exports[`<RecommendedArticles> should render RelatedArticles correctly with 3 ar
|
|
|
45
45
|
<DocumentFragment>
|
|
46
46
|
<div
|
|
47
47
|
id="recommended-articles"
|
|
48
|
-
style="display:
|
|
48
|
+
style="display: none;"
|
|
49
49
|
>
|
|
50
50
|
<div>
|
|
51
51
|
RelatedArticles
|
|
@@ -78,23 +78,21 @@ const getImage = (media?: Media) => {
|
|
|
78
78
|
// MAIN
|
|
79
79
|
|
|
80
80
|
export const getRelatedArticlesSlice = (
|
|
81
|
-
|
|
81
|
+
articles: any
|
|
82
82
|
): RelatedArticleSliceType => ({
|
|
83
83
|
sliceName: 'StandardSlice',
|
|
84
|
-
items:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
.slice(0, 3)
|
|
99
|
-
: []
|
|
84
|
+
items: articles
|
|
85
|
+
.map((article: Article) => ({
|
|
86
|
+
article: {
|
|
87
|
+
slug: article.slug,
|
|
88
|
+
shortIdentifier: article.url.slice(-9),
|
|
89
|
+
label: article.label,
|
|
90
|
+
headline: article.headline,
|
|
91
|
+
publishedTime: article.publishedDateTime,
|
|
92
|
+
bylines: getBylines(article.bylines),
|
|
93
|
+
summary125: getSummary(article.summary),
|
|
94
|
+
leadAsset: getImage(article.media)
|
|
95
|
+
}
|
|
96
|
+
}))
|
|
97
|
+
.slice(0, 3)
|
|
100
98
|
});
|