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

Commit 47b1408

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

File tree

5 files changed

+84
-69
lines changed

5 files changed

+84
-69
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import EntityListMapper from '../../EntityListMapper';
4+
import deprecate from "util-deprecate";
5+
6+
function Paragraphs({ mapper, paragraphs, page, Wrapper, paragraphProps }) {
7+
return <EntityListMapper
8+
entities={paragraphs}
9+
mapper={mapper}
10+
entityProps={{page, ...paragraphProps}}
11+
{...(Wrapper ? {entityWrapper: Wrapper} : {})}
12+
/>;
13+
}
14+
15+
Paragraphs.propTypes = {
16+
mapper: PropTypes.oneOfType([
17+
PropTypes.shape(),
18+
PropTypes.func,
19+
]).isRequired,
20+
paragraphs: PropTypes.arrayOf(PropTypes.shape()),
21+
page: PropTypes.shape(),
22+
Wrapper: PropTypes.oneOfType([
23+
PropTypes.string,
24+
PropTypes.func,
25+
]),
26+
paragraphProps: PropTypes.shape(),
27+
};
28+
29+
Paragraphs.defaultProps = {
30+
Wrapper: undefined,
31+
paragraphProps: {},
32+
page: undefined,
33+
};
34+
35+
export default deprecate(Paragraphs, 'The Paragraphs component is deprecated, use the EntityListMapper component instead');
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react';
2+
import renderer from 'react-test-renderer';
3+
import Paragraphs from './Paragraphs';
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('Paragraphs', async () => {
19+
20+
test('with required props', async() => {
21+
const component = await waitForHnData(
22+
<Paragraphs
23+
mapper={mapper}
24+
paragraphs={[{target_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+
<Paragraphs
34+
mapper={mapper}
35+
paragraphProps={{
36+
testProp: 'testPropValue'
37+
}}
38+
paragraphs={[{target_uuid: uuid}]}
39+
Wrapper={'section'}
40+
page={{'pageTest': true}}
41+
/>
42+
);
43+
44+
expect(renderer.create(component).toJSON()).toMatchSnapshot();
45+
});
46+
});

src/__snapshots__/index.test.js.snap renamed to src/components/deprecated/__snapshots__/Paragraphs.test.js.snap

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

3-
exports[`Deprecated components Paragraphs with all props 1`] = `
3+
exports[`Paragraphs with all props 1`] = `
44
<section>
55
<div
66
bundle="unique_type__unique_bundle"
@@ -36,7 +36,7 @@ exports[`Deprecated components Paragraphs with all props 1`] = `
3636
</section>
3737
`;
3838

39-
exports[`Deprecated components Paragraphs with required props 1`] = `
39+
exports[`Paragraphs with required props 1`] = `
4040
<div
4141
bundle="unique_type__unique_bundle"
4242
className="MyCustomMapperComponent"

src/index.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,9 @@ import site from './site';
44
import EntityMapper from './EntityMapper';
55
import EntityListMapper from './EntityListMapper';
66
import Paragraph from './components/deprecated/Paragraph';
7+
import Paragraphs from './components/deprecated/Paragraphs';
78
import waitForHnData from './DrupalPage/waitForHnData';
89

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

src/index.test.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)