Skip to content
This repository was archived by the owner on Mar 27, 2018. It is now read-only.

Commit ac465d3

Browse files
committed
fix(paragraph): map props in Paragraph component to remove PropType warnings
1 parent ec9bca5 commit ac465d3

File tree

8 files changed

+146
-108
lines changed

8 files changed

+146
-108
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"get-nested": "^4.0.0",
1414
"prop-types": "^15.5.10",
1515
"react-async-bootstrapper": "^1.1.2",
16-
"react-is-deprecated": "^0.1.2"
16+
"react-is-deprecated": "^0.1.2",
17+
"util-deprecate": "^1.0.2"
1718
},
1819
"peerDependencies": {
1920
"hn": "^0.6.1",

src/__snapshots__/index.test.js.snap

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Deprecated components Paragraph with all props 1`] = `
4-
<div
5-
bundle="unique_type__unique_bundle"
6-
className="MyCustomMapperComponent"
7-
entity={
8-
Object {
9-
"__hn": Object {
10-
"entity": Object {
11-
"bundle": "unique_bundle",
12-
"type": "unique_type",
13-
},
14-
},
15-
}
16-
}
17-
index={15}
18-
paragraph={
19-
Object {
20-
"__hn": Object {
21-
"entity": Object {
22-
"bundle": "unique_bundle",
23-
"type": "unique_type",
24-
},
25-
},
26-
}
27-
}
28-
testProp="testPropValue"
29-
/>
30-
`;
31-
32-
exports[`Deprecated components Paragraph with required props 1`] = `
33-
<div
34-
bundle="unique_type__unique_bundle"
35-
className="MyCustomMapperComponent"
36-
entity={
37-
Object {
38-
"__hn": Object {
39-
"entity": Object {
40-
"bundle": "unique_bundle",
41-
"type": "unique_type",
42-
},
43-
},
44-
}
45-
}
46-
index={0}
47-
paragraph={
48-
Object {
49-
"__hn": Object {
50-
"entity": Object {
51-
"bundle": "unique_bundle",
52-
"type": "unique_type",
53-
},
54-
},
55-
}
56-
}
57-
/>
58-
`;
59-
603
exports[`Deprecated components Paragraphs with all props 1`] = `
614
<section>
625
<div
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
import EntityMapper from "../../EntityMapper";
3+
import PropTypes from 'prop-types';
4+
import deprecate from 'util-deprecate';
5+
6+
function Paragraph ({ mapper, uuid, page, index, paragraphProps }) {
7+
return <EntityMapper
8+
mapper={mapper}
9+
uuid={uuid}
10+
entityProps={{index, page, ...paragraphProps}}
11+
/>
12+
}
13+
14+
Paragraph.propTypes = {
15+
mapper: PropTypes.oneOfType([
16+
PropTypes.shape(),
17+
PropTypes.func,
18+
]).isRequired,
19+
uuid: PropTypes.string.isRequired,
20+
page: PropTypes.shape({}),
21+
index: PropTypes.number,
22+
paragraphProps: PropTypes.shape(),
23+
};
24+
25+
Paragraph.defaultProps = {
26+
paragraphProps: {},
27+
index: 0,
28+
page: undefined,
29+
};
30+
31+
export default deprecate(Paragraph, 'The Paragraph component is deprecated, use the EntityMapper component instead');
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import Paragraph from './Paragraph';
2+
import React from 'react';
3+
import renderer from 'react-test-renderer';
4+
import site from '../../site';
5+
import waitForHnData from '../../DrupalPage/waitForHnData';
6+
import { mapper, uuid } from '../../utils/tests';
7+
8+
jest.mock('../../site', () => {
9+
return require('../../utils/tests').mockSite();
10+
});
11+
12+
jest.mock('util-deprecate', () => jest.fn((func) => func));
13+
14+
beforeEach(() => {
15+
site.getData.mockRestore();
16+
});
17+
18+
describe('Paragraph', async () => {
19+
20+
test('with required props', async () => {
21+
const component = await waitForHnData(
22+
<Paragraph
23+
mapper={mapper}
24+
uuid={uuid}
25+
/>
26+
);
27+
28+
expect(renderer.create(component).toJSON()).toMatchSnapshot();
29+
});
30+
31+
test('with all props', async () => {
32+
const component = await waitForHnData(
33+
<Paragraph
34+
mapper={mapper}
35+
paragraphProps={{
36+
testProp: 'testPropValue'
37+
}}
38+
uuid={uuid}
39+
page={{'pageTest': true}}
40+
index={15}
41+
/>
42+
);
43+
44+
expect(renderer.create(component).toJSON()).toMatchSnapshot();
45+
});
46+
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Paragraph with all props 1`] = `
4+
<div
5+
bundle="unique_type__unique_bundle"
6+
className="MyCustomMapperComponent"
7+
entity={
8+
Object {
9+
"__hn": Object {
10+
"entity": Object {
11+
"bundle": "unique_bundle",
12+
"type": "unique_type",
13+
},
14+
},
15+
}
16+
}
17+
index={15}
18+
page={
19+
Object {
20+
"pageTest": true,
21+
}
22+
}
23+
paragraph={
24+
Object {
25+
"__hn": Object {
26+
"entity": Object {
27+
"bundle": "unique_bundle",
28+
"type": "unique_type",
29+
},
30+
},
31+
}
32+
}
33+
testProp="testPropValue"
34+
/>
35+
`;
36+
37+
exports[`Paragraph with required props 1`] = `
38+
<div
39+
bundle="unique_type__unique_bundle"
40+
className="MyCustomMapperComponent"
41+
entity={
42+
Object {
43+
"__hn": Object {
44+
"entity": Object {
45+
"bundle": "unique_bundle",
46+
"type": "unique_type",
47+
},
48+
},
49+
}
50+
}
51+
index={0}
52+
page={undefined}
53+
paragraph={
54+
Object {
55+
"__hn": Object {
56+
"entity": Object {
57+
"bundle": "unique_bundle",
58+
"type": "unique_type",
59+
},
60+
},
61+
}
62+
}
63+
/>
64+
`;

src/index.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@ import DrupalPage from './DrupalPage';
33
import site from './site';
44
import EntityMapper from './EntityMapper';
55
import EntityListMapper from './EntityListMapper';
6+
import Paragraph from './components/deprecated/Paragraph';
67
import waitForHnData from './DrupalPage/waitForHnData';
78

8-
let warningParagraphDeprecation = false;
9-
const Paragraph = (p) => {
10-
if(!warningParagraphDeprecation) {
11-
console.warn('Warning: The component "Paragraph" is deprecated, use "EntityMapper" instead.');
12-
warningParagraphDeprecation = true;
13-
}
14-
return <EntityMapper {...p} />;
15-
};
16-
179
let warningParagraphsDeprecation = false;
1810
const Paragraphs = (p) => {
1911
if(!warningParagraphsDeprecation) {

src/index.test.js

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Paragraphs, Paragraph } from './index';
1+
import { Paragraphs } from './index';
22
import React from 'react';
33
import renderer from 'react-test-renderer';
44
import site from './site';
@@ -8,7 +8,6 @@ import { mapper, uuid } from './utils/tests';
88
jest.mock('./site', () => {
99
return require('./utils/tests').mockSite();
1010
});
11-
1211
console.warn = jest.fn();
1312

1413
beforeEach(() => {
@@ -18,44 +17,6 @@ beforeEach(() => {
1817

1918
describe('Deprecated components', async () => {
2019

21-
describe('Paragraph', async () => {
22-
23-
test('with required props', async () => {
24-
const component = await waitForHnData(
25-
<Paragraph
26-
mapper={mapper}
27-
uuid={uuid}
28-
/>
29-
);
30-
31-
expect(renderer.create(component).toJSON()).toMatchSnapshot();
32-
33-
expect(console.warn).toHaveBeenCalledTimes(1);
34-
expect(console.warn).toBeCalledWith('Warning: The component "Paragraph" is deprecated, use "EntityMapper" instead.');
35-
});
36-
37-
test('with all props', async () => {
38-
const component = await waitForHnData(
39-
<Paragraph
40-
mapper={mapper}
41-
paragraphProps={{
42-
testProp: 'testPropValue'
43-
}}
44-
uuid={uuid}
45-
page={{'pageTest': true}}
46-
index={15}
47-
/>
48-
);
49-
50-
expect(renderer.create(component).toJSON()).toMatchSnapshot();
51-
52-
expect(console.warn).toHaveBeenCalledTimes(3);
53-
expect(console.warn).toBeCalledWith('Warning: The component "Paragraph" is deprecated, use "EntityMapper" instead.');
54-
expect(console.warn).toBeCalledWith('Warning: The prop "paragraphProps" is replaced by "entityProps".');
55-
expect(console.warn).toBeCalledWith('Warning: The prop "page" is deprecated. Please use "entityProps={{ page }}" instead.');
56-
});
57-
});
58-
5920
describe('Paragraphs', async () => {
6021

6122
test('with required props', async() => {

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4616,7 +4616,7 @@ user-home@^1.1.1:
46164616
version "1.1.1"
46174617
resolved "https://registry.yarnpkg.com/user-home/-/user-home-1.1.1.tgz#2b5be23a32b63a7c9deb8d0f28d485724a3df190"
46184618

4619-
util-deprecate@~1.0.1:
4619+
util-deprecate@^1.0.2, util-deprecate@~1.0.1:
46204620
version "1.0.2"
46214621
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
46224622

0 commit comments

Comments
 (0)